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

滴滴跑腿更新:1.识别车型 2.开通城市查询

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

+ 82 - 0
common/components/delivery/platform/didi/Didi.php

@@ -1,6 +1,8 @@
 <?php
 namespace common\components\delivery\platform\didi;
 
+use common\components\delivery\helpers\HttpClient;
+
 class Didi
 {
     protected $baseUrl;
@@ -36,6 +38,42 @@ class Didi
         $this->thirdUid = $thirdUid;
     }
 
+    /**
+     * 开通城市查询
+     * @param int|null $cityId 城市id(城市编码,经纬度二传一) 国标码
+     * @param float|null $longitude 经度 火星坐标系(高德)
+     * @param float|null $latitude 纬度 火星坐标系(高德)
+     * @return array
+     */
+    public function queryCityInfo($cityId = null, $longitude = null, $latitude = null)
+    {
+        // 暂时仅支持快送业务查询,bizType 固定为 12
+        $businessParams = [
+            'bizType' => 12,
+        ];
+
+        if (!empty($cityId)) {
+            $businessParams['cityId'] = (int)$cityId;
+        }
+
+        // 拉货有城市开城但部分区域不支持的情况,如不传经纬度则按照城市返回
+        if (!empty($longitude) && !empty($latitude)) {
+            $businessParams['longitude'] = (float)$longitude;
+            $businessParams['latitude'] = (float)$latitude;
+        }
+
+        $payload = $this->buildRequestPayload($businessParams);
+        $url = $this->getApiUrl('freight.open.platform.channel.standard.queryCityInfo');
+        $headers = ["Content-Type" => "application/x-www-form-urlencoded"];
+
+        $resp =HttpClient::post($url, $payload, $headers);
+        if($resp['code'] == 200 && isset($resp['result'])){
+            return $resp['result'];
+        }
+
+        return [];
+    }
+
     /**
      * 构建API请求参数
      *
@@ -132,4 +170,48 @@ class Didi
 
         return $left;
     }
+
+    /**
+     * 车型
+     * @param $number 车型编号
+     * @return string
+     */
+    public function carType($number)
+    {
+        $map = [
+            //拉货车型
+            1001 => '小面包',
+            1002 => '中面包',
+            1003 => '小型平板',
+            1004 => '中型平板',
+            1005 => '4.2米平板',
+            1006 => '依维柯',
+            1007 => '4.2米厢货',
+            1008 => '5.2米货车',
+            1009 => '6.8米货车',
+            1010 => '7.6米货车',
+            1011 => '13米货车',
+            1012 => '微面',
+            1013 => '小厢货',
+            1014 => '中厢货',
+            1015 => '小高栏',
+            1016 => '4.2米高栏',
+            1019 => '9.6米货车',
+            1020 => '三轮车',
+            1022 => '集装箱卡车',
+            1023 => '微平板',
+            1024 => '微厢货',
+            1025 => '微高栏',
+            1026 => '中高栏',
+            1028 => '17.5米',
+            1029 => '16米',
+            1030 => '15米',
+            1031 => '13.5米',
+            //快送车型 
+            1017 => '小轿车',
+            1018 => '两轮车',
+        ];
+
+        return isset($map[$number]) ? $map[$number] : $number;
+    }
 }

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

@@ -978,11 +978,11 @@ class DispatchService
 
                     foreach($item['estimateList'] as $arr) {
                         $deliveryList[] = [
-                            'name' => '滴滴' . ' (' . $arr['carType'] . ')',
+                            'name' => '滴滴' . ' (' . $this->adapters['didi']->carType($arr['carType']) . ')',
                             'en_name' => 'didi',
                             'price' => $arr['fee'],
                             'distance' => $arr['distance'],
-                            'type' => $arr['estimateId'],
+                            'type' => $arr['name'], //服务商或车型名称
                             'isAble' => true,
                             // ---------------------------------------------
                             'estimateId' => $arr['estimateId'],

+ 21 - 2
common/components/delivery/services/adapter/DidiAdapter.php

@@ -45,7 +45,7 @@ class DidiAdapter extends Didi implements Adapter
         }
 
         // 服务参数列表 (询价时可以传入多个,获取不同服务的价格)
-        // 假设这里主要请求快送(BizType=12)
+        // 默认请求快送(BizType=12)
         $serviceCategoryList = [
             [
                 'bizType' => 12,     // 业务类型 -- 快送
@@ -60,6 +60,22 @@ class DidiAdapter extends Didi implements Adapter
                 'serviceType' => 1,
             ]
         ];
+        // 如果是预约单,则使用以下 拉货(普通货运)
+        $laHuo_serviceCategoryList = [
+            [
+                'bizType' => 0,      // 业务类型 -- 普通货运
+                'carType' => 1020,   // 车型 -- 三轮车
+                'serviceLevel' => 0, // 服服务等级
+                //'serviceType' => 1,  // 服务类型(快送专用,拉货不需要传)
+            ],
+            [
+                'bizType' => 0,
+                'carType' => 1012,   // 微面
+                'serviceLevel' => 0,
+                //'serviceType' => 1,
+            ]
+        ];
+        //$ret = $this->queryCityInfo(null,  (float)$receiver['toLongitude'], (float)$receiver['toLatitude']);
 
         // 构造起点信息
         $fromAddress = [
@@ -101,6 +117,9 @@ class DidiAdapter extends Didi implements Adapter
                 $modeType = 2;// 变更为2-预约单
                 $useTime = $ts * 1000;
                 // 注意:文档说“快送暂不支持预约单都按照实时单处理”,所以这里可能无需处理,或者传了也没用
+
+                //从快送 变更 拉货
+                //$serviceCategoryList = $laHuo_serviceCategoryList;
             }
         }
 
@@ -210,7 +229,7 @@ class DidiAdapter extends Didi implements Adapter
             'toAddressDetail' => $order['floor'],
             'toLatitude' => (float)$order['lat'],
             'toLongitude' => (float)$order['long'],
-            'weight' => round(['weight'] ?? 1) * 1000,
+            'weight' => round(($order['weight'] ?? 1)) * 1000,
             'goodType' => 4, // const GOODS_TYPE_MAP
         ];