فهرست منبع

Merge branch 'zhongqi-delivery'

shizhongqi 8 ماه پیش
والد
کامیت
ccb88d26c8

+ 0 - 8
app-ghs/controllers/ShopExtController.php

@@ -75,12 +75,6 @@ class ShopExtController extends BaseController
                 $ghsArr['hcMap'] = json_encode($map);
             }
         }
-        if(isset($post['pfHsFreeKm'])){
-            $ghsArr['hsFreeKm'] = $post['pfHsFreeKm'];
-        }
-        if(isset($post['pfHsAddFee'])){
-            $ghsArr['hsAddFee'] = $post['pfHsAddFee'];
-        }
         if(isset($post['pfHcFreeKm'])){
             $ghsArr['hcFreeKm'] = $post['pfHcFreeKm'];
         }
@@ -161,8 +155,6 @@ class ShopExtController extends BaseController
         //批发 shopExt
         $arr['pfHcMap'] = $ext['hcMap'];
         $arr['pfHcFreeKm'] = $ext['hcFreeKm'];
-        $arr['pfHsFreeKm'] = $ext['hsFreeKm'];
-        $arr['pfHsAddFee'] = $ext['hsAddFee'];
 
         $arr['losingItemName'] = $losingItemName;
         $arr['zjGatheringItemName'] = $zjGatheringItemName;

+ 2 - 3
common/components/delivery/platform/didi/Didi.php

@@ -16,9 +16,8 @@ class Didi
             $cfg = [
                 'base_url' => 'https://freight.xiaojukeji.com',
                 'app_key' => '6724e08ff1ac4afdbf1c000cfe722449',
-                // TODO: 请填入正式环境的 appId 和 secret
-                'app_id' => '', 
-                'secret' => '',
+                'app_id' => 'MDdovjIS',
+                'secret' => 'b61603625ebcf69a6364fdc30ae47944630c738c',
             ];
         } else {
             $cfg = [

+ 11 - 11
common/components/delivery/services/AuthService.php

@@ -72,22 +72,22 @@ Class AuthService{
 
     public function didiAuth($mainId, $shopId)
     {
-        // $shop = ShopClass::getById($shopId, false, 'id,lat,long');
-        // if(!$shop){
-        //     util::fail('门店不存在');
-        // }
-        // $lat = $shop['lat'];
-        // $lng = $shop['long'];
-        // if(empty($lat) || empty($lng)){
-        //     util::fail('门店经纬度不存在');
-        // }
+        $shop = ShopClass::getById($shopId, false, 'id,lat,long');
+        if(!$shop){
+            util::fail('门店不存在');
+        }
+        $lat = $shop['lat'];
+        $lng = $shop['long'];
+        if(empty($lat) || empty($lng)){
+            util::fail('门店经纬度不存在');
+        }
+
         $didiAuth = new \common\components\delivery\platform\didi\Auth();
-        $ret = $didiAuth->getAuthUrl($mainId, 110100, '', '');
+        $ret = $didiAuth->getAuthUrl($mainId, '', $lat, $lng);
         if(isset($ret['raw']) && $ret['raw']['code'] == 200){
             util::success(['url'=>$ret['raw']['data']['authUrl']]);
         }else{
             util::fail('获取授权地址失败');
         }
-
     }
 }

+ 4 - 2
common/components/delivery/services/DispatchService.php

@@ -187,7 +187,8 @@ class DispatchService
         // 查找批发配送订单
         $deliveryOrder = GhsDeliveryOrderClass::getByCondition([
             'deliveryId' => $deliveryId,
-            'ghsOrderId' => $orderId
+            'ghsOrderId' => $orderId,
+            'orderStatus' => ['not in', [-1, -2]],
         ], false, null, $fields);
 
         if ($deliveryOrder) {
@@ -197,7 +198,8 @@ class DispatchService
         // 查找零售配送订单
         $deliveryOrder =  HdDeliveryOrderClass::getByCondition([
             'deliveryId' => $deliveryId,
-            'hdOrderId' => $orderId
+            'hdOrderId' => $orderId,
+            'orderStatus' => ['not in', [-1, -2]],
         ], false, null, $fields);
 
         if ($deliveryOrder) {

+ 29 - 12
common/components/delivery/services/adapter/DidiAdapter.php

@@ -97,9 +97,9 @@ class DidiAdapter extends Didi implements Adapter
         $useTime = null;
         if ($orderTime) {
             $ts = strtotime($orderTime);
-            if ($ts > time() + 1800) { // 30分钟后算预约? 滴滴快送暂不支持预约单,这里保留逻辑备用
-                // $modeType = 2; 
-                // $useTime = $ts * 1000;
+            if ($ts > (time() + 300)) { // 5分钟后算预约? 滴滴快送暂不支持预约单,这里保留逻辑备用
+                $modeType = 2;// 变更为2-预约单
+                $useTime = $ts * 1000;
                 // 注意:文档说“快送暂不支持预约单都按照实时单处理”,所以这里可能无需处理,或者传了也没用
             }
         }
@@ -187,6 +187,13 @@ class DidiAdapter extends Didi implements Adapter
      */
     public function formatOrderData($order, $orderType, $shop, $params)
     {
+        // 默认实时单,拉货生效,快送暂不支持预约单都按照实时单处理
+        $timeDiff = strtotime($params['pickupTime']) - time();
+        $modeType = 1;
+        if ($timeDiff > 300) {
+            $modeType = 2;
+        }
+
         $sender = [
             'fromSenderName' => $shop['merchantName'],
             'fromMobile' => $shop['mobile'],
@@ -203,17 +210,23 @@ class DidiAdapter extends Didi implements Adapter
             'toAddressDetail' => $order['floor'],
             'toLatitude' => (float)$order['lat'],
             'toLongitude' => (float)$order['long'],
-            'weight' => $order['weight'] ?? 1,
-            'goodType' => $order['goodType'] ?? '8',
+            'weight' => round(['weight'] ?? 1) * 1000,
+            'goodType' => 4, // const GOODS_TYPE_MAP
         ];
 
         $apiData = [
-            'issOrderNo' => $order['orderSn'],
+            'outOrderNo' => $order['orderSn'],
             'estimate_id' => $params['estimateId'] ?? null,
             'sender' => $sender,
-            'receiverList' => [$receiver],
+            'receiver' => $receiver,
             'remark' => $params['remark'] ?? $order['remark'] ?? '',
+            'orderSequence' => $order['sendNum'] // 取件流水号,方便寻找订单对应的花材
         ];
+        if($modeType == 2){
+            $apiData['modeType'] = 2;
+            $apiData['useTime'] = strtotime($params['pickupTime']) * 1000;
+        }
+
         return $apiData;
     }
 
@@ -236,8 +249,6 @@ class DidiAdapter extends Didi implements Adapter
         }
 
         $sender = $order['sender'];
-        $receiver = $order['receiverList'][0];
-        
         $fromAddress = [
             'name' => $sender['fromSenderName'],
             'phone' => $sender['fromMobile'],
@@ -249,6 +260,7 @@ class DidiAdapter extends Didi implements Adapter
             'virtualPhoneType' => 0,
         ];
 
+        $receiver = $order['receiver'];
         $toAddress = [
             'name' => $receiver['toReceiverName'],
             'phone' => $receiver['toMobile'],
@@ -270,16 +282,21 @@ class DidiAdapter extends Didi implements Adapter
         $timeStamp = time();
         $businessParams = [
             'estimateIdList' => [$estimateId], // 预估ID
-            'outOrderNo' => self::generateUniOroder($order['issOrderNo'], $timeStamp), // 接入方订单号
+            'outOrderNo' => self::generateUniOroder($order['outOrderNo'], $timeStamp), // 接入方订单号
             'fromAddress' => $fromAddress,
             'toAddress' => $toAddress,
             'goodsType' => $goodsType,
             'weight' => $weightGram,
             'needPickupCode' => false,
-            'needReceiveCode' => true,
-            'thirdUid' => $sender['fromMobile'],
+            'needReceiveCode' => false,
+            'thirdUid' => $this->appId, // TODO ??? 入方用户唯一标识。保持在渠道方唯一,会用于安全风控,【聚合模式】必须传
             'remark' => $order['remark'] ?? '',
+            'orderSequence' => $order['orderSequence'] ?? '',
         ];
+        if(isset($order['modeType']) && $order['modeType'] == 2){
+            $businessParams['modeType'] = 2;
+            $businessParams['useTime'] = $order['useTime'];
+        }
 
         $payload = $this->buildRequestPayload($businessParams);
         $url = $this->getApiUrl('freight.open.platform.channel.standard.createOrder');