DeliveryService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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') || strstr($no,'so')) $orderCodes[] = $no;
  33. elseif (strstr($no, 'W') || 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): array
  44. {
  45. foreach ($items as $key =>$item) {
  46. if ($item['is_process'] == false) continue;
  47. switch ($item('component_type')){
  48. case 'TB':
  49. $items[$key] = app(TBDeliveryService::class)->processing($item);
  50. break;
  51. case 'PDD':
  52. $items[$key] = app(PDDDeliveryService::class)->processing($item);
  53. break;
  54. default:
  55. break;
  56. }
  57. }
  58. return $items;
  59. }
  60. /**
  61. * 根据缓存删除十分钟前的文件
  62. */
  63. public function destroyFileOfCache()
  64. {
  65. if (Cache::has('print-template-file-list')) {
  66. $arr = Cache::get('print-template-file-list');
  67. $now = Carbon::now();
  68. foreach ($arr as $key => $item) {
  69. $time = (new Carbon($item['time']))->addMilliseconds(10);
  70. if ($now->lt($time)) {
  71. if (file_exists($item['path'])) {
  72. unlink($item['path']);
  73. }
  74. unset($arr[$key]);
  75. }
  76. }
  77. Cache::put('print-template-file-list', $arr);
  78. }
  79. }
  80. }