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

Merge branch 'zhongqi-delivery' into dev

shizhongqi 8 месяцев назад
Родитель
Сommit
1efc0dfe20

+ 2 - 86
app-ghs/controllers/DeliveryController.php

@@ -263,92 +263,8 @@ class DeliveryController extends BaseController
             util::fail($platformQuotes['error']);
         }
 
-        $deliveryList = [];
-        foreach ($platformQuotes['quotes'] as $item) {
-            switch ($item['platform']) {
-                case 'shunfeng':
-                    $deliveryList[] = [
-                        'name' => '顺丰',
-                        'en_name' => 'shunfeng',
-                        'price' => $item['real_pay_money'],
-                        'distance' => $item['distance'],
-                        'type' => '',
-                        'isAble' => true
-                    ];
-                    break;
-                case 'shansong':
-                    $deliveryList[] = [
-                        'name' => '闪送',
-                        'en_name' => 'shansong',
-                        'price' => $item['total_amount'],
-                        'distance' => $item['total_distance'],
-                        'type' => '',
-                        'issOrderNo' => $item['order_number'],
-                        'isAble' => true
-                    ];
-                    break;
-                case 'fengniao':
-                    // 循环遍历 goods_infos 数组,提取有效项的信息
-                    $validGoods = [];
-                    if (!empty($item['goods_infos']) && is_array($item['goods_infos'])) {
-                        foreach ($item['goods_infos'] as $good) {
-                            if (!empty($good['is_valid']) && $good['is_valid'] == 1) {
-                                $validGoods[] = [
-                                    'actual_delivery_amount_cent' => $good['actual_delivery_amount_cent'] ?? 0,
-                                    'service_goods_id' => $good['service_goods_id'] ?? ''
-                                ];
-
-                                $deliveryList[] = [
-                                    'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
-                                    'en_name' => 'fengniao',
-                                    'price' => $good['actual_delivery_amount_cent'],
-                                    'distance' => $item['distance'],
-                                    'valid_goods' => $validGoods,
-                                    'type' => $good['slogan'],
-                                    'isAble' => true
-                                ];
-                            } else {
-                                $deliveryList[] = [
-                                    'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
-                                    'en_name' => 'fengniao',
-                                    'price' => 0,
-                                    'distance' => $item['distance'],
-                                    'valid_goods' => $good,
-                                    'type' => $good['disable_reason'],
-                                    'isAble' => false
-                                ];
-                            }
-                        }
-                    }
-                    break;
-                case 'huolala':
-                    foreach($item['price_info_list'] as $arr) {
-                        $priceInfo = $arr['calculate_price_info'];
-                        $vehicleType = $arr['vehicle_type'];
-                        $deliveryList[] = [
-                            'name' => '货拉拉' . ' (' . $vehicleType['_meta']['vehicle_type'] . ')',
-                            'en_name' => 'huolala',
-                            'price' => $priceInfo['price_conditions'][0]['price_info']['total_price'],
-                            'distance' => $priceInfo['distance_info']['distance_total'],
-                            'type' => $vehicleType['_meta']['vehicle_type'],
-                            'isAble' => true,
-                            // ---------------------------------------------
-                            'order_vehicle_id' => $vehicleType['order_vehicle_id'],
-                            'city_id' => $item['city_id'],
-                            'city_info_revision' => $vehicleType['city_info_revision'],
-                            // // 下单需要透传的数据
-                            'vehicle_std' => $vehicleType['vehicle_std'],
-                            'spec_req' => $vehicleType['spec_req'],
-                            'price_calculate_id' => $priceInfo['price_calculate_id'],
-                            'price_item_encryption' => $priceInfo['price_conditions'][0]['price_item_encryption'],
-                            'vehicle_attr' => $priceInfo['vehicle_info']['vehicle_attr'],
-                            'commodity_info' => $priceInfo['price_conditions'][0]['commodity_item'],
-                        ];
-                    }
-                    break;
-            }
-        }
-
+        // 格式化各平台报价为前端展示格式
+        $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
         // 按 price 从低到高排序
         ArrayHelper::multisort($deliveryList, 'price', SORT_ASC);
 

+ 4 - 87
app-hd/controllers/DeliveryController.php

@@ -53,8 +53,8 @@ class DeliveryController extends BaseController
             'city' => $custom['city'],
             'weight' => $weight,
             'remark' => $post['remark'] ?? '',
-            'prePrice' => 10,
-            'actPrice' => 10,
+            'prePrice' => 10, // TODO 要从前端获取
+            'actPrice' => 10, // TODO
         ];
         $ghsShop = ShopClass::getById($ghsShopId);
         $ds = new DispatchService($ghs->mainId);
@@ -64,91 +64,8 @@ class DeliveryController extends BaseController
         }
 
         $deliveryList = [];
-        foreach ($platformQuotes['quotes'] as $item) {
-            switch ($item['platform']) {
-                case 'shunfeng':
-                    $deliveryList[] = [
-                        'name' => '顺丰',
-                        'en_name' => 'shunfeng',
-                        'price' => $item['real_pay_money'],
-                        'distance' => $item['distance'],
-                        'type' => '',
-                        'isAble' => true
-                    ];
-                    break;
-                case 'shansong':
-                    $deliveryList[] = [
-                        'name' => '闪送',
-                        'en_name' => 'shansong',
-                        'price' => $item['total_amount'],
-                        'distance' => $item['total_distance'],
-                        'type' => '',
-                        'issOrderNo' => $item['order_number'],
-                        'isAble' => true
-                    ];
-                    break;
-                case 'fengniao':
-                    // 循环遍历 goods_infos 数组,提取有效项的信息
-                    $validGoods = [];
-                    if (!empty($item['goods_infos']) && is_array($item['goods_infos'])) {
-                        foreach ($item['goods_infos'] as $good) {
-                            if (!empty($good['is_valid']) && $good['is_valid'] == 1) {
-                                $validGoods[] = [
-                                    'actual_delivery_amount_cent' => $good['actual_delivery_amount_cent'] ?? 0,
-                                    'service_goods_id' => $good['service_goods_id'] ?? ''
-                                ];
-
-                                $deliveryList[] = [
-                                    'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
-                                    'en_name' => 'fengniao',
-                                    'price' => $good['actual_delivery_amount_cent'],
-                                    'distance' => $item['distance'],
-                                    'valid_goods' => $validGoods,
-                                    'type' => $good['slogan'],
-                                    'isAble' => true
-                                ];
-                            } else {
-                                $deliveryList[] = [
-                                    'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
-                                    'en_name' => 'fengniao',
-                                    'price' => 0,
-                                    'distance' => $item['distance'],
-                                    'valid_goods' => $good,
-                                    'type' => $good['disable_reason'],
-                                    'isAble' => false
-                                ];
-                            }
-                        }
-                    }
-                    break;
-                case 'huolala':
-                    foreach($item['price_info_list'] as $arr) {
-                        $priceInfo = $arr['calculate_price_info'];
-                        $vehicleType = $arr['vehicle_type'];
-                        $deliveryList[] = [
-                            'name' => '货拉拉' . ' (' . $vehicleType['_meta']['vehicle_type'] . ')',
-                            'en_name' => 'huolala',
-                            'price' => $priceInfo['price_conditions'][0]['price_info']['total_price'],
-                            'distance' => $priceInfo['distance_info']['distance_total'],
-                            'type' => $vehicleType['_meta']['vehicle_type'],
-                            'isAble' => true,
-                            // ---------------------------------------------
-                            'order_vehicle_id' => $vehicleType['order_vehicle_id'],
-                            'city_id' => $item['city_id'],
-                            'city_info_revision' => $vehicleType['city_info_revision'],
-                            // // 下单需要透传的数据
-                            'vehicle_std' => $vehicleType['vehicle_std'],
-                            'spec_req' => $vehicleType['spec_req'],
-                            'price_calculate_id' => $priceInfo['price_calculate_id'],
-                            'price_item_encryption' => $priceInfo['price_conditions'][0]['price_item_encryption'],
-                            'vehicle_attr' => $priceInfo['vehicle_info']['vehicle_attr'],
-                            'commodity_info' => $priceInfo['price_conditions'][0]['commodity_item'],
-                        ];
-                    }
-                    break;
-            }
-        }
-
+        // 格式化各平台报价为前端展示格式
+        $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
         // 按 price 从低到高排序
         ArrayHelper::multisort($deliveryList, 'price', SORT_ASC);
 

+ 49 - 3
app-hd/controllers/PurchaseController.php

@@ -14,6 +14,7 @@ use bizHd\purchase\services\PurchaseService;
 use bizGhs\product\classes\ProductClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dateUtil;
+use common\components\delivery\services\DispatchService;
 use common\components\dict;
 use common\components\imgUtil;
 use common\components\noticeUtil;
@@ -571,12 +572,57 @@ class PurchaseController extends BaseController
                         $currentWeight = bcmul($thisWeight, $bigNum, 2);
                         $weight = bcadd($currentWeight, $weight, 2);
                     }
-                    $result = PurchaseClass::getDistanceFee($this->shop, $ghsShopInfo, $weight, $custom);
-                    $sendCost = $result['fee'] ?? 0;
-                    $sendDistance = $result['distance'] ?? 0;
+                    // TODO 使用平台估价接口获取费用与距离
+                    //$result = PurchaseClass::getDistanceFee($this->shop, $ghsShopInfo, $weight, $custom);
+                    //$sendCost = $result['fee'] ?? 0;
+                    //$sendDistance = $result['distance'] ?? 0;
+
+                    $platform = $post['deliveryPlatform'];
+                    $ghsShopId = $ghsInfo['shopId'];
+                    // 生成随机订单号
+                    $prefix = 'XSD_CS-' . $this->mainId . '-';
+                    $orderSn = $prefix . round(microtime(true) * 1000);
+
+                    //构建出 Order 数据
+                    $order = [
+                        'orderSn' => $orderSn,
+                        'customName' => $custom->name,
+                        'customMobile' => $custom->mobile,
+                        'fullAddress' => $custom->fullAddress,
+                        'floor' => $custom->floor,
+                        'dist' => $custom->dist,
+                        'lat' => $custom->lat,
+                        'long' => $custom->long,
+                        'address' => $custom->address, //'toAddress' => $order['address'],
+                        'city' => $custom->city,
+                        'weight' => $weight,
+                        'remark' => $post['remark'] ?? '',
+                        'prePrice' => 100 * ($post['itemTotalAmount'] ?? 0), // 花材总价
+                        'actPrice' => 100 * ($post['itemTotalAmount'] ?? 0),
+                    ];
+                    $ghsShop = ShopClass::getById($ghsShopId);
+                    $orderTime = date('Y-m-d H:i:s');
+                    $ds = new DispatchService($ghsInfo['mainId'], $platform);
+                    $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
+                    if(isset($platformQuotes['error'])){
+                        Yii::error($platformQuotes['error']);
+                        noticeUtil::push($platform . "-跑腿平台估价接口获取费用与距离失败:mainId=" . $this->mainId);
+                    } else {
+                        $deliveryList = [];
+                        // 格式化各平台报价为前端展示格式
+                        $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
+                        $result = $deliveryList[0];
+                        $sendCost = ($result['price'] ?? 0)/100;
+                        $sendDistance = $result['distance'] ?? 0;
+
+                        //Yii::error('获取跑腿估价失败-' .  json_encode($platformQuotes));
+                        //util::fail('获取跑腿估价失败');
+
+                    }
                 }
                 $post['sendCost'] = $sendCost;
                 $post['sendDistance'] = $sendDistance;
+
                 //出车、发快递、发物流可以算包装费
                 $packCost = 0;
                 if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {

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

@@ -333,8 +333,8 @@ class DispatchService
             'position_source' => 3,
             'goods_count' => count($goodsItemList),
             'goods_weight' => (float)$order['weight'],
-            'goods_total_amount_cent' => (int)($order['prePrice'] * 100),
-            'goods_actual_amount_cent' => (int)($order['actPrice'] * 100),
+            'goods_total_amount_cent' => (int)($order['actPrice'] * 100),
+            'goods_actual_amount_cent' => (int)($order['prePrice'] * 100),
             'goods_item_list' => $goodsItemList,
             'order_type' => 1,
             'chain_store_id' => $platformShopId, // 蜂鸟平台 shopId
@@ -617,4 +617,106 @@ class DispatchService
                 break;
         }
     }
+
+    /**
+     * 格式化各平台报价为前端展示格式
+     * 
+     * @param array $platformQuotes 各平台报价结果(来自 getAllPlatformPrice)
+     * @return array 格式化后的配送列表
+     */
+    public function formatPlatformQuotesForDisplay($platformQuotes)
+    {
+        $deliveryList = [];
+
+        if (empty($platformQuotes['quotes'])) {
+            return $deliveryList;
+        }
+
+        foreach ($platformQuotes['quotes'] as $item) {
+            switch ($item['platform']) {
+                case 'shunfeng':
+                    $deliveryList[] = [
+                        'name' => '顺丰',
+                        'en_name' => 'shunfeng',
+                        'price' => $item['real_pay_money'],
+                        'distance' => $item['distance'],
+                        'type' => '',
+                        'isAble' => true
+                    ];
+                    break;
+                case 'shansong':
+                    $deliveryList[] = [
+                        'name' => '闪送',
+                        'en_name' => 'shansong',
+                        'price' => $item['total_amount'],
+                        'distance' => $item['total_distance'],
+                        'type' => '',
+                        'issOrderNo' => $item['order_number'],
+                        'isAble' => true
+                    ];
+                    break;
+                case 'fengniao':
+                    // 循环遍历 goods_infos 数组,提取有效项的信息
+                    $validGoods = [];
+                    if (!empty($item['goods_infos']) && is_array($item['goods_infos'])) {
+                        foreach ($item['goods_infos'] as $good) {
+                            if (!empty($good['is_valid']) && $good['is_valid'] == 1) {
+                                $validGoods[] = [
+                                    'actual_delivery_amount_cent' => $good['actual_delivery_amount_cent'] ?? 0,
+                                    'service_goods_id' => $good['service_goods_id'] ?? ''
+                                ];
+
+                                $deliveryList[] = [
+                                    'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
+                                    'en_name' => 'fengniao',
+                                    'price' => $good['actual_delivery_amount_cent'],
+                                    'distance' => $item['distance'],
+                                    'valid_goods' => $validGoods,
+                                    'type' => $good['slogan'],
+                                    'isAble' => true
+                                ];
+                            } else {
+                                $deliveryList[] = [
+                                    'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
+                                    'en_name' => 'fengniao',
+                                    'price' => 0,
+                                    'distance' => $item['distance'],
+                                    'valid_goods' => $good,
+                                    'type' => $good['disable_reason'],
+                                    'isAble' => false
+                                ];
+                            }
+                        }
+                    }
+                    break;
+                case 'huolala':
+                    foreach($item['price_info_list'] as $arr) {
+                        $priceInfo = $arr['calculate_price_info'];
+                        $vehicleType = $arr['vehicle_type'];
+                        $deliveryList[] = [
+                            'name' => '货拉拉' . ' (' . $vehicleType['_meta']['vehicle_type'] . ')',
+                            'en_name' => 'huolala',
+                            'price' => $priceInfo['price_conditions'][0]['price_info']['total_price'],
+                            'distance' => $priceInfo['distance_info']['distance_total'],
+                            'type' => $vehicleType['_meta']['vehicle_type'],
+                            'isAble' => true,
+                            // ---------------------------------------------
+                            'order_vehicle_id' => $vehicleType['order_vehicle_id'],
+                            'city_id' => $item['city_id'],
+                            'city_info_revision' => $vehicleType['city_info_revision'],
+                            // 下单需要透传的数据
+                            'vehicle_std' => $vehicleType['vehicle_std'],
+                            'spec_req' => $vehicleType['spec_req'],
+                            'price_calculate_id' => $priceInfo['price_calculate_id'],
+                            'price_item_encryption' => $priceInfo['price_conditions'][0]['price_item_encryption'],
+                            'vehicle_attr' => $priceInfo['vehicle_info']['vehicle_attr'],
+                            'commodity_info' => $priceInfo['price_conditions'][0]['commodity_item'],
+                        ];
+                    }
+                    break;
+            }
+        }
+
+        return $deliveryList;
+    }
 }