Ver Fonte

快递信息同步

ANG YU há 4 anos atrás
pai
commit
74801c24db

+ 17 - 18
app/Http/Controllers/TestController.php

@@ -342,27 +342,26 @@ sql;
 
     public function init_在途异常()
     {
-//        $logistic_numbers = OrderPackage::query()
-//            ->select('logistic_number')
-//            ->where('exception_status', 5)
-//            ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
-//            ->pluck('logistic_number');
-//
-        /** @var OrderPackageReceivedSyncService $service */
-        $service = app('OrderPackageReceivedSyncService');
-//        $service->syncLogisticRoute(false, $logistic_numbers);
-
-
         $logistic_numbers = 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', ['顺丰', '中通', '韵达', '圆通', '京东']);
-                });
-            })
+            ->select('logistic_number')
             ->where('exception_status', 5)
             ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
             ->pluck('logistic_number');
-        $service->syncLogisticRouteByAliJiSu($logistic_numbers);
+        /** @var OrderPackageReceivedSyncService $service */
+        $service = app('OrderPackageReceivedSyncService');
+        $service->syncLogisticRoute(false, $logistic_numbers);
+
+
+//        $logistic_numbers = 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', ['顺丰', '中通', '韵达', '圆通', '京东']);
+//                });
+//            })
+//            ->where('exception_status', 5)
+//            ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
+//            ->pluck('logistic_number');
+//        $service->syncLogisticRouteByAliJiSu($logistic_numbers);
     }
 }

+ 0 - 171
app/Services/OrderPackageReceivedSyncService.php

@@ -247,175 +247,4 @@ class OrderPackageReceivedSyncService
         }
         return $data;
     }
-
-
-    /**
-     * @param array $data
-     * @param $lastRouteDate
-     * @return array
-     */
-    public function setExceptionType(array $data, $lastRouteDate): array
-    {
-        //设置默认异常为否
-
-        $data['exception_type'] = '无';
-        $data['exception'] = '否';
-        $logistic_number = $data['logistic_number'];
-        /** @var OrderPackage $orderPackage */
-        $orderPackage = OrderPackage::query()->with('order')->where('logistic_number', $logistic_number)->first();
-        $delivered_duration = now()->diffInHours(Carbon::parse($orderPackage['sent_at']));
-        $last_routed_duration = now()->diffInHours(Carbon::parse($lastRouteDate));
-        $VALID_HOURS = 4;
-        $SHORT_RESPONSE_HOURS = (function ($province) {
-            switch ($province) {
-                case '浙江省':
-                case '江苏省':
-                case '上海':
-                case '安徽省':
-                    return 24;
-                case '北京':
-                case '天津':
-                case '江西省':
-                case '湖北省':
-                case '湖南省':
-                case '广东省':
-                case '福建省':
-                case '山东省':
-                case '河北省':
-                case '河南省':
-                case '山西省':
-                case '四川省':
-                case '陕西省':
-                case '重庆':
-                case '广西壮族自治区':
-                case '贵州省':
-                case '云南省':
-                case '海南省':
-                case '吉林省':
-                case '黑龙江省':
-                case '辽宁省':
-                    return 72;
-                case '青海省':
-                case '宁夏回族自治区':
-                case '甘肃省':
-                case '内蒙古自治区':
-                case '新疆维吾尔自治区':
-                case '西藏自治区':
-                    return 120;
-                default:
-                    return 24;
-            }
-        })($orderPackage->order->province);
-        $LONG_RESPONSE_HOURS = (function ($province) {
-            switch ($province) {
-                case '浙江省':
-                case '江苏省':
-                case '上海':
-                case '安徽省':
-                    return 72;
-                case '北京':
-                case '天津':
-                case '江西省':
-                case '湖北省':
-                case '湖南省':
-                case '广东省':
-                case '福建省':
-                case '山东省':
-                case '河北省':
-                case '河南省':
-                case '山西省':
-                case '四川省':
-                case '陕西省':
-                case '重庆':
-                case '广西壮族自治区':
-                case '贵州省':
-                case '云南省':
-                case '海南省':
-                case '吉林省':
-                case '黑龙江省':
-                case '辽宁省':
-                    return 120;
-                case '青海省':
-                case '宁夏回族自治区':
-                case '甘肃省':
-                case '内蒙古自治区':
-                case '新疆维吾尔自治区':
-                case '西藏自治区':
-                    return 168;
-                default:
-                    return 72;
-            }
-        })($orderPackage->order->province);
-        $SENDING_RESPONSE_HOURS = 48;
-        $HAVEN_SECOND_GOT_HOURS = 24;
-        $IS_ROUTED = 1;               //0000 0001 有路由信息
-        $IS_IN_VALID_TIME = 2;        //0000 0010 大于4小时
-        $IS_WEIGHED = 4;              //0000 0100 称重过
-        $IS_RECEIVED = 8;          //0000 1000 已经收货
-        $IS_SENDING = 16;             //0001 0000 正在派送
-        $IS_SHORT_NO_RESPONSE = 32;     //0010 0000 中转异常
-        $IS_LONG_NO_RESPONSE = 64;     //0010 0000 疑似丢件
-        $IS_SENDING_NO_RESPONSE = 128;     //0010 0000 派送异常
-        $IS_SECOND_ROUTE_HAVE = 256;     //0100 0000 揽件异常
-        $conclusion = (function () use (
-            $data, $delivered_duration, $last_routed_duration,
-            $VALID_HOURS, $IS_ROUTED, $IS_IN_VALID_TIME, $IS_WEIGHED, $IS_RECEIVED, $IS_SENDING, $IS_SHORT_NO_RESPONSE, $IS_LONG_NO_RESPONSE, $IS_SENDING_NO_RESPONSE,
-            $SHORT_RESPONSE_HOURS, $LONG_RESPONSE_HOURS, $SENDING_RESPONSE_HOURS, $HAVEN_SECOND_GOT_HOURS, $IS_SECOND_ROUTE_HAVE,
-            $orderPackage
-        ) {
-            $conclusion = 0;
-            $conclusion |= !empty($data['transfer_status']) ? $IS_ROUTED : 0;
-            $conclusion |= ($delivered_duration > $VALID_HOURS) ? $IS_IN_VALID_TIME : 0;
-            $conclusion |= ($orderPackage->weighed_at) ? $IS_WEIGHED : 0;
-            $conclusion |= ($data['status'] == '已签收') ? $IS_RECEIVED : 0;
-            $conclusion |= ($data['status'] == '派送中') ? $IS_SENDING : 0;//
-            $conclusion |= ($last_routed_duration > $SHORT_RESPONSE_HOURS && $last_routed_duration < $LONG_RESPONSE_HOURS) ? $IS_SHORT_NO_RESPONSE : 0;
-            $conclusion |= ($last_routed_duration > $LONG_RESPONSE_HOURS) ? $IS_LONG_NO_RESPONSE : 0;
-            $conclusion |= ($last_routed_duration > $SENDING_RESPONSE_HOURS && $data['status'] == '派送中') ? $IS_SENDING_NO_RESPONSE : 0;
-            $conclusion |= ($delivered_duration > $HAVEN_SECOND_GOT_HOURS && $data['routes_length'] < 3) ? $IS_SECOND_ROUTE_HAVE : 0;//和出库时间比较 超过指定时间,路由信息小于三条
-            return $conclusion;
-        })();
-        switch ($conclusion) {
-            case $IS_IN_VALID_TIME:
-                $data['exception_type'] = '疑似库内丢件';
-                break;
-            case $IS_IN_VALID_TIME | $IS_WEIGHED:
-                $data['exception_type'] = '揽件异常';
-                break;
-            case $IS_ROUTED | $IS_IN_VALID_TIME | $IS_SHORT_NO_RESPONSE:
-            case $IS_ROUTED | $IS_IN_VALID_TIME | $IS_SHORT_NO_RESPONSE | $IS_WEIGHED:
-                $data['exception_type'] = '中转异常';
-                break;
-            case $IS_ROUTED | $IS_IN_VALID_TIME | $IS_LONG_NO_RESPONSE:
-            case $IS_ROUTED | $IS_IN_VALID_TIME | $IS_LONG_NO_RESPONSE | $IS_WEIGHED:
-                $data['exception_type'] = '疑似丢件';
-                break;
-            default:
-                break;
-        }
-        if ($conclusion
-            == ($conclusion | $IS_ROUTED | $IS_IN_VALID_TIME | $IS_SENDING | $IS_SENDING_NO_RESPONSE)) {
-            $data['exception_type'] = '派件异常';
-        }
-        if ($conclusion
-            == ($conclusion | $IS_SECOND_ROUTE_HAVE)) {
-            $data['exception_type'] = '揽件异常';
-            $data['exception'] = '是';
-
-        }
-        switch ($conclusion) {
-            case $IS_IN_VALID_TIME:
-            case $IS_IN_VALID_TIME | $IS_WEIGHED:
-            case $IS_ROUTED | $IS_SHORT_NO_RESPONSE:
-            case $IS_LONG_NO_RESPONSE:
-                $data['exception'] = '是';
-                break;
-            default:
-                break;
-        }
-        return [
-            'exception_type' => array_key_exists('exception_type', $data) ? $data['exception_type'] : null,
-            'exception' => array_key_exists('exception', $data) ? $data['exception'] : null,
-        ];
-    }
 }

+ 3 - 5
app/Traits/LogisticSyncTrait.php

@@ -74,10 +74,9 @@ trait LogisticSyncTrait
                     }
                     return ($a['accept_time'] > $b['accept_time']) ? -1 : 1;
                 });
-
                 $last_transfer = $transfer_status[0]['accept_time'];
-                $last_remark = empty(!$transfer_status[0]['remark'])?:$transfer_status[0]['accept_address'];
-                if (count($transfer_status) <= 3) {//三条以内的不管地区 时间限制为24h
+                $last_remark = empty(!$transfer_status[0]['remark'])?$transfer_status[0]['remark']:$transfer_status[0]['accept_address'];
+                if (count($transfer_status) < 3) {//三条以内的不管地区 时间限制为24h
                     if (Carbon::parse($last_transfer)->diffInHours(now()) > 24) {
                         $data['exception_status'] = '在途异常';
                     }
@@ -126,8 +125,7 @@ trait LogisticSyncTrait
                         $data['exception_status'] = '在途异常';
                     }
                 }
-
-                if ($data['exception_status']??''==='在途异常'&& $data['status']== '派送中') {
+                if (($data['exception_status']??''==='在途异常')&& ($data['status']=== '派送中')) {
                     $data['exception_status'] = '派送异常';
                 }
                 if (Str::contains($last_remark,['代收','快递柜','驿站','自提柜','丰巢','快递小屋','合作点','快递超市','签收'])) {