Просмотр исходного кода

1. 达达订单回调处理更新 2. 代码健壮修改

shizhongqi 7 месяцев назад
Родитель
Сommit
470af4dcf0

+ 34 - 22
common/components/delivery/platform/dada/CallBackHandler.php

@@ -7,6 +7,7 @@ use bizHd\express\classes\HdDeliveryOrderClass;
 use bizGhs\order\classes\OrderClass;
 use bizHd\order\classes\OrderClass as HdOrderClass;
 use bizHd\purchase\classes\PurchaseClass;
+use common\components\noticeUtil;
 use common\components\util;
 use Yii;
 
@@ -46,7 +47,7 @@ class CallBackHandler
     {
         $orderSn = $data['order_id']; // 对应 orderSn
         $dadaStatus = $data['order_status'];
-        $clientId = isset($data['client_id']) ? $data['client_id'] : '';
+        $clientId = isset($data['client_id']) ? $data['client_id'] : ''; //达达物流订单号
 
         // 查找主订单
         $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
@@ -69,10 +70,10 @@ class CallBackHandler
             return false;
         }
 
-        // 更新 client_id (达达单号)
+        // 更新 client_id (达达物流订单号)
         if (!empty($clientId) && empty($deliveryOrder->orderId)) {
-            $deliveryOrder->orderId = $clientId;
-            $deliveryOrder->save();
+            // $deliveryOrder->orderId = $clientId;
+            // $deliveryOrder->save();
         }
 
         $sendStatus = $this->convertOrderSendStatus($dadaStatus);
@@ -84,18 +85,12 @@ class CallBackHandler
 
         // 更新配送订单状态
         $deliveryOrder->orderStatus = $sendStatus;
-        if (isset($data['dm_name'])) {
-            $deliveryOrder->riderName = $data['dm_name'];
-        }
-        if (isset($data['dm_mobile'])) {
-            $deliveryOrder->riderPhone = $data['dm_mobile'];
-        }
         $deliveryOrder->save();
 
         // 更新主订单
         if ($isGhs) {
             util::checkRepeatCommit('ghs_pt_' . $order->id . '_' . $sendStatus, 2);
-            $order = OrderClass::getById($order->id, true, 'id,sendType,sendStatus,deliveryId,purchaseId,customId,status');
+            //$order = OrderClass::getById($order->id, true, 'id,sendType,sendStatus,deliveryId,purchaseId,customId,status');
             
             if ($order) {
                 // 已送达
@@ -122,7 +117,7 @@ class CallBackHandler
         } else {
              // 零售订单处理
             util::checkRepeatCommit('hd_pt_' . $order->id . '_' . $sendStatus, 2);
-            $order = HdOrderClass::getById($order->id, true, 'id,sendType,sendStatus,deliveryId,customId,status');
+            //$order = HdOrderClass::getById($order->id, true, 'id,sendType,sendStatus,deliveryId,customId,status');
             if ($order) {
                 $order->sendStatus = $sendStatus;
                 if ($orderStatus !== null) {
@@ -161,15 +156,31 @@ class CallBackHandler
     private function getDeliveryOrder($order, $isGhs)
     {
         if ($isGhs) {
-             return GhsDeliveryOrderClass::getByCondition([
+             $gdos = GhsDeliveryOrderClass::getAllByCondition([
                 'deliveryId' => 'dada',
-                'ghsOrderId' => $order->id
-            ], true);
+                'ghsOrderId' => $order->id,
+                'orderStatus!=' => -1
+            ], 'id DESC', '*', null, true);
+            if(count($gdos)>=2){
+                noticeUtil::push("xhGhsDeliveryOrder ghsOrderId={$order->id} 有两笔以上是在配送中");
+                $gdo = $gdos[0];
+            }else{
+                $gdo = $gdos[0];
+            }
+            return $gdo;
         } else {
-            return HdDeliveryOrderClass::getByCondition([
+            $hdos = HdDeliveryOrderClass::getAllByCondition([
                 'deliveryId' => 'dada',
-                'hdOrderId' => $order->id
-            ], true);
+                'hdOrderId' => $order->id,
+                'orderStatus!=' => -1
+            ], 'id DESC', '*', null, true);
+            if(count($hdos)>=2){
+                noticeUtil::push("xhHdDeliveryOrder hdOrderId={$order->id} 有两笔以上是在配送中");
+                $hdo = $hdos[0];
+            }else{
+                $hdo = $hdos[0];
+            }
+            return $hdo;
         }
     }
 
@@ -193,10 +204,11 @@ class CallBackHandler
     private function convertOrderStatus($dadaStatus)
     {
          $map = [
-            2 => 3,   // 待取货 -> 配送中
-            3 => 3,   // 配送中 -> 配送中
-            4 => 4,   // 已完成 -> 已完成
-            100 => 3, // 到店 -> 配送中
+             1 => 3,   // 待接单 -> 配送中
+             2 => 3,   // 待取货 -> 配送中
+             3 => 3,   // 配送中 -> 配送中
+             4 => 4,   // 已完成 -> 已完成
+             100 => 3, // 到店 -> 配送中
          ];
          return $map[$dadaStatus] ?? null;
     }

+ 1 - 1
common/components/delivery/platform/dada/Dada.php

@@ -23,7 +23,7 @@ class Dada
      */
     public function __construct($token='')
     {
-        $isProduction = getenv('YII_ENV') == 'production'; // TODO  如果是 dev 请修改为 production
+        $isProduction = getenv('YII_ENV') == 'dev'; // TODO  如果是 dev 请修改为 production
 
         if ($isProduction) {
             // 生产环境配置

+ 1 - 1
common/components/delivery/services/DispatchService.php

@@ -826,7 +826,7 @@ class DispatchService
 
         foreach ($platformQuotes['quotes'] as $item) {
             if(!isset($item['platform'])){
-                Yii::info(json_encode($item));
+                Yii::error(json_encode($item));
                 continue;
             }
 

+ 9 - 3
common/components/delivery/services/adapter/DadaAdapter.php

@@ -595,16 +595,22 @@ class DadaAdapter extends Dada implements Adapter
             //  "tips":0,
             //  "expiredTime":1765361146 //平台订单号的过期时间
             // }
-            return [
+            $ret = [
                 'platform' => 'dada',
                 'fee' => $result['fee'] * 100, // *100 把单位:元 变为 分
                 'distance' => $result['distance'],
                 'tips' => $result['tips'],
                 'deliverFee' => $result['deliverFee'],
                 'deliveryNo' => $result['deliveryNo'],
-                'couponName' => $result['couponName'],
-                'couponFee' => $result['couponFee'],
             ];
+
+            // 只有在有优惠券时,才进行coupon相关设置
+            if(isset($result['couponName']) && isset($result['couponFee'])){
+                $ret['couponName'] = $result['couponName'];
+                $ret['couponFee'] = $result['couponFee'];
+            }
+
+            return $ret;
         }
 
         return [