DeliveryService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Services;
  3. use App\OracleDocOrderDeliveryInfo;
  4. use App\OracleDOCOrderHeader;
  5. use Illuminate\Support\Carbon;
  6. use Illuminate\Support\Facades\Cache;
  7. class DeliveryService
  8. {
  9. public function getDelivery($printStr): array
  10. {
  11. list($batchCodes, $orderCodes, $logisticNumbers) = $this->conversionPrintData($printStr);
  12. if ($batchCodes){
  13. $orderHeaders = OracleDOCOrderHeader::query()->selectRaw('orderno')->whereIn('WaveNo',$batchCodes)->get()->toArray();
  14. $orderCodes = array_unique(array_merge($orderCodes,array_column($orderHeaders,'orderno')));
  15. }
  16. if ($orderCodes) {
  17. $deliveryInfo = OracleDocOrderDeliveryInfo::query()->selectRaw('trackingNo')->whereIn('orderno',$orderCodes)->get()->toArray();
  18. $logisticNumbers = array_unique(array_merge($logisticNumbers,array_column($deliveryInfo,'trackingno')));
  19. }
  20. $OracleDocOrderDeliveryInfos = OracleDocOrderDeliveryInfo::query()->with('docOrderHeader')->whereIn('trackingNo',$logisticNumbers)->get();
  21. $tbParams = app(TBDeliveryService::class)->getDeliveryInfo($OracleDocOrderDeliveryInfos);
  22. $pddParams = app(PDDDeliveryService::class)->getDeliveryInfo($OracleDocOrderDeliveryInfos);
  23. $sfParams = app(SFDeliveryService::class)->getDeliveryInfo($OracleDocOrderDeliveryInfos);
  24. $jdParams = app(JDDeliveryService::class)->getDeliveryInfo($logisticNumbers);
  25. $sfQhdParams = app(SFQHDDeliveryService::class)->getDeliveryInfo($logisticNumbers);
  26. return array_merge($tbParams,$pddParams,$sfParams,$jdParams,$sfQhdParams);
  27. }
  28. public function conversionPrintData($printStr): array
  29. {
  30. preg_match_all('/[\w]+/', $printStr, $nos);
  31. foreach ($nos[0] as $no) {
  32. if (strstr($no, 'SO')) $orderCodes[] = $no;
  33. elseif (strstr($no, 'W')) $batchesCodes[] = $no;
  34. else $logisticNumbers[] = $no;
  35. }
  36. return [$batchesCodes ?? [], $orderCodes ?? [], $logisticNumbers ?? []];
  37. }
  38. /**
  39. * 快递面单填充自定义区域内容 或 自制面单
  40. * @param $items
  41. * @return array
  42. */
  43. public function customProcessing(array $items)
  44. {
  45. foreach ($items as $key =>$item) {
  46. if ($item['is_process'] == false) continue;
  47. $items[$key] = app(TBDeliveryService::class)->processing($item);
  48. }
  49. return $items;
  50. }
  51. /**
  52. * 根据缓存删除十分钟前的文件
  53. */
  54. public function destroyFile(){
  55. if (Cache::has('print-template-file-list')){
  56. $arr = Cache::get('print-template-file-list');
  57. $now = Carbon::now();
  58. foreach ($arr as $key=>$item) {
  59. $time = (new Carbon($item['time']))->addMilliseconds(10);
  60. if ($now->lt($time)){
  61. if(file_exists($item['path'])){
  62. unlink($item['path']);
  63. }
  64. unset($arr[$key]);
  65. }
  66. }
  67. Cache::put('print-template-file-list',$arr);
  68. }
  69. }
  70. }