| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Services;
- use App\OracleDocOrderDeliveryInfo;
- use App\OracleDOCOrderHeader;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\Cache;
- class DeliveryService
- {
- public function getDelivery($printStr): array
- {
- list($batchCodes, $orderCodes, $logisticNumbers) = $this->conversionPrintData($printStr);
- if ($batchCodes){
- $orderHeaders = OracleDOCOrderHeader::query()->selectRaw('orderno')->whereIn('WaveNo',$batchCodes)->get()->toArray();
- $orderCodes = array_unique(array_merge($orderCodes,array_column($orderHeaders,'orderno')));
- }
- if ($orderCodes) {
- $deliveryInfo = OracleDocOrderDeliveryInfo::query()->selectRaw('trackingNo')->whereIn('orderno',$orderCodes)->get()->toArray();
- $logisticNumbers = array_unique(array_merge($logisticNumbers,array_column($deliveryInfo,'trackingno')));
- }
- $OracleDocOrderDeliveryInfos = OracleDocOrderDeliveryInfo::query()->with('docOrderHeader')->whereIn('trackingNo',$logisticNumbers)->get();
- $tbParams = app(TBDeliveryService::class)->getDeliveryInfo($OracleDocOrderDeliveryInfos);
- $pddParams = app(PDDDeliveryService::class)->getDeliveryInfo($OracleDocOrderDeliveryInfos);
- $sfParams = app(SFDeliveryService::class)->getDeliveryInfo($OracleDocOrderDeliveryInfos);
- $jdParams = app(JDDeliveryService::class)->getDeliveryInfo($logisticNumbers);
- $sfQhdParams = app(SFQHDDeliveryService::class)->getDeliveryInfo($logisticNumbers);
- return array_merge($tbParams,$pddParams,$sfParams,$jdParams,$sfQhdParams);
- }
- public function conversionPrintData($printStr): array
- {
- preg_match_all('/[\w]+/', $printStr, $nos);
- foreach ($nos[0] as $no) {
- if (strstr($no, 'SO') || strstr($no,'so')) $orderCodes[] = $no;
- elseif (strstr($no, 'W') || strstr($no, 'w') ) $batchesCodes[] = $no;
- else $logisticNumbers[] = $no;
- }
- return [$batchesCodes ?? [], $orderCodes ?? [], $logisticNumbers ?? []];
- }
- /**
- * 快递面单填充自定义区域内容 或 自制面单
- * @param $items
- * @return array
- */
- public function customProcessing(array $items): array
- {
- foreach ($items as $key =>$item) {
- if ($item['is_process'] == false) continue;
- switch ($item('component_type')){
- case 'TB':
- $items[$key] = app(TBDeliveryService::class)->processing($item);
- break;
- case 'PDD':
- $items[$key] = app(PDDDeliveryService::class)->processing($item);
- break;
- default:
- break;
- }
- }
- return $items;
- }
- /**
- * 根据缓存删除十分钟前的文件
- */
- public function destroyFileOfCache()
- {
- if (Cache::has('print-template-file-list')) {
- $arr = Cache::get('print-template-file-list');
- $now = Carbon::now();
- foreach ($arr as $key => $item) {
- $time = (new Carbon($item['time']))->addMilliseconds(10);
- if ($now->lt($time)) {
- if (file_exists($item['path'])) {
- unlink($item['path']);
- }
- unset($arr[$key]);
- }
- }
- Cache::put('print-template-file-list', $arr);
- }
- }
- }
|