| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?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, // TODO 要从前端获取
- 'actPrice' => 10, // TODO
- ];
- $ghsShop = ShopClass::getById($ghsShopId);
- $ds = new DispatchService($ghs->mainId);
- $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
- if(isset($platformQuotes['error'])){
- util::fail($platformQuotes['error']);
- }
- $deliveryList = [];
- // 格式化各平台报价为前端展示格式
- $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
- // 按 price 从低到高排序
- ArrayHelper::multisort($deliveryList, 'price', SORT_ASC);
- $ret['deliveryList'] = $deliveryList;
- util::success($ret, "success");
- }
- }
|