| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace mall\controllers;
- use Yii;
- use bizMall\shop\classes\ShopClass;
- use common\components\delivery\services\DispatchService;
- use common\components\util;
- 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 ----------
- $ghsShopId = $this->shopId;
- if (empty($ghsShopId)) {
- util::fail('店铺不存在');
- }
- $user = $this->user;
- if (empty($user)) {
- util::fail('用户不存在');
- }
- $mainId = $this->mainId;
- if (empty($mainId)) {
- util::fail('商户不存在');
- }
- $buyType = $post['buyType'] ?? 'huaCai'; //订单类型
- $order = $this->generateOrderData($buyType, $user, $post);
- $ghsShop = ShopClass::getById($ghsShopId);
- if (empty($ghsShop)) {
- util::fail('店铺信息不存在');
- }
-
- $ds = new DispatchService($mainId);
- $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
- if(isset($platformQuotes['error'])){
- util::fail($platformQuotes['error']);
- }
- // 格式化各平台报价为前端展示格式
- $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
- // 按 price 从低到高排序
- ArrayHelper::multisort($deliveryList, 'price', SORT_ASC);
- $ret['deliveryList'] = $deliveryList;
- util::success($ret, "success");
- }
- private function generateOrderData($buyType, $user, $post)
- {
- // 生成随机订单号,不要跟原来的混起来,跑腿-销售单-
- $prefix = 'PT-XSD-' . $this->mainId . '-';
- $orderSn = $prefix . round(microtime(true) * 1000);
- //构建出 Order 数据
- if($buyType == 'huaCai'){//订单类型是:花材
- $order = [
- 'orderSn' => $orderSn,
- 'customName' => $user['name'],
- 'customMobile' => $user['mobile'],
- 'fullAddress' => $user['fullAddress'],
- 'floor' => $user['floor'],
- 'dist' => $user['dist'],
- 'lat' => $user['lat'],
- 'long' => $user['long'],
- 'address' => $user['address'], //'toAddress' => $order['address'],
- 'city' => $user['city'],
- 'weight' => $post['weight'] ?? 1,
- 'remark' => $post['remark'] ?? '',
- 'prePrice' => floatval($post['totalPrice'] ?? 0),
- 'actPrice' => floatval($post['totalPrice'] ?? 0),
- ];
- }elseif($buyType == 'huaShu'){//订单类型是:花束
- $order = [
- 'orderSn' => $orderSn,
- 'customName' => $post['receiveUserName'],
- 'customMobile' => $post['receiveMobile'],
- 'fullAddress' => $post['address'],
- 'floor' => $post['floor'] ?? '',
- 'dist' => $post['dist'] ?? '',
- 'lat' => $post['region']['latitude'],
- 'long' => $post['region']['longitude'],
- 'address' => $post['address'], //'toAddress' => $order['address'],
- 'city' => $post['city'],
- 'weight' => $post['weight'] ?? 1,
- 'remark' => $post['remark'] ?? '',
- 'prePrice' => floatval($post['totalPrice'] ?? 0),
- 'actPrice' => floatval($post['totalPrice'] ?? 0),
- ];
- }else{
- util::fail('不存在此订单类型');
- }
- return $order;
- }
- }
|