Explorar el Código

开启阿里公用同步快递任务

hu hao hace 4 años
padre
commit
1226699700

+ 0 - 1
app/Console/Commands/SyncOrderPackageLogisticRouteTask.php

@@ -46,7 +46,6 @@ class SyncOrderPackageLogisticRouteTask extends Command
         LogService::log(SyncOrderPackageLogisticRouteTask::class, "同步快递信息定时任务启动", '');
         ini_set('memory_limit', '2226M');
         $this->service = app('OrderPackageReceivedSyncService');
-//        $this->service->syncLogisticRouteYTO();
         $this->service->syncLogisticRoute();
         $this->service->syncLogisticRouteByAliJiSu();
     }

+ 39 - 39
app/Services/OrderPackageReceivedSyncService.php

@@ -85,45 +85,45 @@ class OrderPackageReceivedSyncService
         });
     }
 
-//    public function syncLogisticRouteByAliJiSu()
-//    {
-//        ini_set('max_execution_time', 2 * 60 * 60);
-//        $query = OrderPackage::query()
-//            ->select(['logistic_number', 'order_id','id'])
-//            ->whereIn('order_id',function ($query){
-//                $query->from('orders')->selectRaw('id')->whereIn('logistic_id',function ($builder){
-//                    $builder->from('logistics')->selectRaw('id')->where('type','!=','物流')->whereNotIn('belong_company',['顺丰','中通','韵达','圆通','京东']);
-//                });
-//            });
-//        $query = $query->where('sent_at', '>=', now()->subDays(config('api_logistic.querying_days')))
-//            ->whereNull('received_at');
-//
-//        $query->chunkById(200, function ($orderPackages) {
-//            LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法-阿里公用接口", json_encode($orderPackages));
-//            foreach ($orderPackages as $orderPackage){
-//                if ($orderPackage && $orderPackage->logistic_number)LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
-//            }
-//        });
-//        $this->syncLogisticRouteJD();
-//    }
-//    public function syncLogisticRouteJD(){
-//        ini_set('max_execution_time', 60);
-//        $query = OrderPackage::query()
-//            ->select(['logistic_number', 'order_id','id'])
-//            ->whereIn('order_id',function ($query){
-//                $query->from('orders')->selectRaw('id')->whereIn('logistic_id',function ($builder){
-//                    $builder->from('logistics')->selectRaw('id')->where('type','!=','物流')->where('belong_company','京东');
-//                });
-//            });
-//        $query = $query->where('created_at', '>=', now()->subDays(config('api_logistic.querying_days')))
-//            ->whereNull('received_at')->where('logistic_number','like','JD%');
-//        $query->chunkById(200, function ($orderPackages) {
-//            LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法-JD", json_encode($orderPackages));
-//            foreach ($orderPackages as $orderPackage){
-//                if ($orderPackage && $orderPackage->logistic_number)LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
-//            }
-//        });
-//    }
+    public function syncLogisticRouteByAliJiSu()
+    {
+        ini_set('max_execution_time', 2 * 60 * 60);
+        $query = OrderPackage::query()
+            ->select(['logistic_number', 'order_id','id'])
+            ->whereIn('order_id',function ($query){
+                $query->from('orders')->selectRaw('id')->whereIn('logistic_id',function ($builder){
+                    $builder->from('logistics')->selectRaw('id')->where('type','!=','物流')->whereNotIn('belong_company',['顺丰','中通','韵达','圆通','京东']);
+                });
+            });
+        $query = $query->where('sent_at', '>=', now()->subDays(config('api_logistic.querying_days')))
+            ->whereNull('received_at');
+
+        $query->chunkById(200, function ($orderPackages) {
+            LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法-阿里公用接口", json_encode($orderPackages));
+            foreach ($orderPackages as $orderPackage){
+                if ($orderPackage && $orderPackage->logistic_number)LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
+            }
+        });
+        $this->syncLogisticRouteJD();
+    }
+    public function syncLogisticRouteJD(){
+        ini_set('max_execution_time', 60);
+        $query = OrderPackage::query()
+            ->select(['logistic_number', 'order_id','id'])
+            ->whereIn('order_id',function ($query){
+                $query->from('orders')->selectRaw('id')->whereIn('logistic_id',function ($builder){
+                    $builder->from('logistics')->selectRaw('id')->where('type','!=','物流')->where('belong_company','京东');
+                });
+            });
+        $query = $query->where('created_at', '>=', now()->subDays(config('api_logistic.querying_days')))
+            ->whereNull('received_at')->where('logistic_number','like','JD%');
+        $query->chunkById(200, function ($orderPackages) {
+            LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法-JD", json_encode($orderPackages));
+            foreach ($orderPackages as $orderPackage){
+                if ($orderPackage && $orderPackage->logistic_number)LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
+            }
+        });
+    }
     /**
      * 根据传递的承运商与快递单号更新快递信息
      * @param array $logisticNumbers 快递单号