| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use bizGhs\custom\classes\CustomClass;
- use Yii;
- use biz\shop\classes\ShopClass;
- use common\components\delivery\services\DispatchService;
- use common\components\util;
- use ghs\controllers\BaseController;
- use yii\helpers\ArrayHelper;
- class DeliveryController extends BaseController
- {
- // 获取多个平台报价
- public function actionAllDeliveryQuotes()
- {
- $post = Yii::$app->request->post();
- $orderTime = date('Y-m-d H:i:s');
- // --------- $ghsShopId ----------
- $ghsId = $post['ghsId'] ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('获取批发商失败');
- }
- $ghsShopId = $ghs->shopId;
- // --------- $customId
- $customId = $ghs->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('获取custom数据失败');
- }
- $weight = $post['weight'] ?? 1;
- // 生成随机订单号
- //$snData = ['shopId' => $ghsShopId, 'mainId' => $ghs->mainId, 'ghsId' => $ghsId, 'customId' => $customId];
- //$orderSn = orderSn::getGhsOrderSn($snData);
- $prefix = 'XSD_CS-';
- $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' => 10,
- 'actPrice' => 10,
- ];
- $ghsShop = ShopClass::getById($ghsShopId);
- $ds = new DispatchService($ghs->mainId);
- $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
- if(isset($platformQuotes['error'])){
- 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;
- }
- }
- // 按 price 从低到高排序
- ArrayHelper::multisort($deliveryList, 'price', SORT_ASC);
- $ret['deliveryList'] = $deliveryList;
- util::success($ret, "success");
- }
- }
|