Переглянути джерело

1. 花店快捷开单时,获取各跑腿平台报价
2. 批发快捷开单时,获取各跑腿平台报价
3. 创建订单成功后(订单要是已付款的),添加生产者创建跑腿订单指令,发送给跑腿订单消息者
4. 其它修改等

shizhongqi 7 місяців тому
батько
коміт
141983ecfb

+ 53 - 0
app-ghs/controllers/DeliveryController.php

@@ -242,6 +242,59 @@ class DeliveryController extends BaseController
         util::success($ret, "success");
     }
 
+    // 批发快捷开单时 -- 获取各跑腿平台报价
+    public function actionQuickOrderDeliveryQuotes()
+    {
+        $post = Yii::$app->request->post();
+        $orderTime = date('Y-m-d H:i:s');
+
+        // --------- $customId ----------
+        $customId = $post['customId'];
+        $custom = \bizGhs\custom\classes\CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('获取custom数据失败');
+        }
+
+        // 生成随机订单号,不要跟原来的混起来,跑腿-销售单-
+        $prefix = 'PT-XSD-' . $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' => $post['weight'] ?? 1,
+            //'remark' => $post['remark'] ?? '',
+            'prePrice' => floatval($post['totalPrice'] ?? 0),
+            'actPrice' => floatval($post['totalPrice'] ?? 0),
+        ];
+
+        $shop = ShopClass::getById($this->shopId);
+
+        $ds = new DispatchService($this->mainId);
+        $ds->validateOrder($order); //对 $order 进行验证
+        $platformQuotes = $ds->getAllPlatformPrice($order, $shop, $orderTime);
+        if (isset($platformQuotes['error'])) {
+            util::fail($platformQuotes['error']);
+        }
+
+        // 格式化各平台报价为前端展示格式
+        $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
+        // 按 price 从低到高排序
+        yii\helpers\ArrayHelper::multisort($deliveryList, 'price', SORT_ASC);
+
+        $ret['deliveryList'] = $deliveryList;
+        util::success($ret, "success");
+    }
+
     // 创建订单(真实下单)
     public function actionCreateOrder()
     {

+ 13 - 1
app-ghs/controllers/OrderController.php

@@ -6,6 +6,7 @@ use biz\common\classes\GhsNotifyClass;
 use biz\common\classes\HdNotifyClass;
 use biz\shop\classes\ShopExtClass;
 use bizGhs\custom\classes\CustomDebtChangeClass;
+use bizGhs\express\classes\GhsDeliveryOrderClass;
 use bizGhs\express\services\DadaExpressServices;
 use bizGhs\ghs\classes\GhsClass;
 use bizGhs\order\classes\OrderItemClass;
@@ -1355,7 +1356,6 @@ class OrderController extends BaseController
                                     $order->save();
                                 }
                             }
-
                         }
                     }
                 }
@@ -1365,6 +1365,18 @@ class OrderController extends BaseController
                         ShopExtClass::ghsPleasePayReport($order);
                     }
                 }
+
+                //跑腿订单生产者创建订单
+                // TODO
+                if($sendType == dict::getDict('sendType', 'thirdSend') && $post['callErrand'] == 1){ // $post 中有 pickupTime,则说明是要立即发跑腿 或者  callErrand == 1
+                    $payWay = $post['payWay'];
+                    if($hasPay != dict::getDict('hasPay', 'unPay')){
+                        $data = [
+                            'orderId' => $saleId,
+                        ];
+                        GhsDeliveryOrderClass::askCreateOrder($data);
+                    }
+                }
             }
             util::success($return);
         } catch (\Exception $e) {

+ 54 - 2
app-hd/controllers/DeliveryController.php

@@ -5,7 +5,6 @@ namespace hd\controllers;
 use biz\common\classes\HdNotifyClass;
 use Yii;
 use biz\ghs\classes\GhsClass;
-use bizGhs\custom\classes\CustomClass;
 use bizGhs\express\classes\DeliveryAuthTokenClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\express\classes\HdDeliveryOrderClass;
@@ -97,6 +96,59 @@ class DeliveryController extends BaseController
         util::success($ret, "success");
     }
 
+    // 花店快捷开单时 -- 获取各跑腿平台报价
+    public function actionQuickOrderDeliveryQuotes()
+    {
+        $post = Yii::$app->request->post();
+        $orderTime = date('Y-m-d H:i:s');
+        
+        // --------- $customId ----------
+        $customId = $post['customId'];
+        $custom = \bizHd\custom\classes\CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('获取custom数据失败');
+        }
+
+        // 生成随机订单号,不要跟原来的混起来,跑腿-销售单-
+        $prefix = 'PT-XSD-' . $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' => $post['weight'] ?? 1,
+            //'remark' => $post['remark'] ?? '',
+            'prePrice' => floatval($post['totalPrice'] ?? 0),
+            'actPrice' => floatval($post['totalPrice'] ?? 0),
+        ];
+
+        $shop = ShopClass::getById($this->shopId);
+
+        $ds = new DispatchService($this->mainId);
+        $ds->validateOrder($order); //对 $order 进行验证
+        $platformQuotes = $ds->getAllPlatformPrice($order, $shop, $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");
+    }
+
     // 花店向批发买花时 -- 获取各跑腿平台报价
     public function actionAllDeliveryQuotes()
     {
@@ -112,7 +164,7 @@ class DeliveryController extends BaseController
 
         // --------- $customId
         $customId = $ghs->customId ?? 0;
-        $custom = CustomClass::getById($customId, true); // 批发的 custom
+        $custom = \bizGhs\custom\classes\CustomClass::getById($customId, true); // 批发的 custom
         if (empty($custom)) {
             util::fail('获取custom数据失败');
         }

+ 11 - 3
app-hd/controllers/MerchantController.php

@@ -4,15 +4,13 @@ namespace hd\controllers;
 
 use biz\shop\classes\ShopAdminClass;
 use biz\sj\classes\MerchantClass;
-use bizHd\auth\services\AuthService;
 use biz\sj\services\MerchantExtendService;
 use biz\sj\services\MerchantService;
 use bizHd\saas\services\SetAuthService;
+use bizHd\shop\classes\ShopClass;
 use Yii;
 use common\components\util;
-
 use bizHd\merchant\services\ShopService;
-use yii\web\Controller;
 
 class MerchantController extends BaseController
 {
@@ -38,6 +36,16 @@ class MerchantController extends BaseController
         }
         $ext = isset($this->sjExtend) && !empty($this->sjExtend) ? $this->sjExtend->attributes : [];
         $merchant = MerchantService::getInfo($merchant, $ext);
+
+        //跑腿配送是否开启及获取配送规则
+        $shop = ShopClass::getById($this->shopId, true);
+        $intraCityRet = \biz\shop\classes\ShopClass::hasIntraCity($shop);
+        $merchant['openIntraCity'] = $intraCityRet['openIntraCity'];
+        $merchant['hcFreeKm'] = $intraCityRet['hcFreeKm'];
+        $merchant['hcMap'] = $intraCityRet['hcMap'];
+        $merchant['hsFreeKm'] = $intraCityRet['hsFreeKm'];
+        $merchant['hsAddFee'] = $intraCityRet['hsAddFee'];
+
         util::success($merchant);
     }
 

+ 13 - 1
app-hd/controllers/OrderController.php

@@ -14,6 +14,7 @@ use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\OrderForwardClass;
 use bizHd\order\classes\OrderItemClass;
 use bizHd\order\classes\OrderSendClass;
+use bizHd\express\classes\HdDeliveryOrderClass;
 use bizHd\order\services\OrderService;
 use bizHd\product\classes\ProductClass;
 use bizHd\saas\services\RegionService;
@@ -840,13 +841,24 @@ class OrderController extends BaseController
                 ShopExtClass::newWorkRemind($shopExt, $order);
             }
 
+            //跑腿订单生产者创建订单 // TODO
+            $sendType = $post['sendType'] ?? 0;
+            if($sendType == dict::getDict('sendType', 'thirdSend') && $post['callErrand'] == 1){ // $post 中有 pickupTime,则说明是要立即发跑腿
+                $payWay = $post['payWay'];
+                if($hasPay != dict::getDict('hasPay', 'unPay')){
+                    $data = [
+                        'orderId' => $order->id,
+                    ];
+                    HdDeliveryOrderClass::askCreateOrder($data);
+                }
+            }
+
             util::success($return);
         } catch (\Exception $e) {
             $transaction->rollBack();
             Yii::error("失败原因:" . $e->getMessage());
             util::fail('下单失败');
         }
-
     }
 
     //下单要用到的相关信息 ssh 2019.12.6

+ 27 - 1
biz-ghs/express/classes/GhsDeliveryOrderClass.php

@@ -2,11 +2,37 @@
 namespace bizGhs\express\classes;
 
 use bizGhs\base\classes\BaseClass;
+use common\components\noticeUtil;
+use Yii;
 
 class GhsDeliveryOrderClass extends BaseClass
 {
     //public static $baseFile = '\bizGhs\express\models\GhsDelivery';
     public static $baseFile = GhsDeliveryOrderAR::class;
+
+    //生产者创建下单指令逻辑
+    public static function askCreateOrder($data)
+    {
+        try {
+            $orderId = $data['orderId'] ?? 0;
+            $producer = Yii::$app->rabbitmq->getProducer('ptProducer');
+            $msg = serialize(['type' => 'ghs_pt_create_order', 'orderId' => $orderId]);
+            $producer->publish($msg, 'ptExchange', 'ptRoute', ['delivery_mode' => 2, 'content_type' => 'application/octet-stream']);
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "批发,跑腿下单,生产消息端报错 {$orderId} {$msg}";
+            noticeUtil::push($remind);
+        }
+    }
+
+    //消费者消费下单指令逻辑
+    public static function beginCreateOrder($data)
+    {
+        //批发,进行下单流程处理
+        //$dataStr = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+        noticeUtil::push('已消费跑腿订单 -- ' . $data);
+        return true;
+    }
 }
 
 // 在同文件末尾追加一个内联的 AR 类
@@ -21,4 +47,4 @@ class GhsDeliveryOrderAR extends \bizGhs\base\models\Base
 // 可选:为了兼容历史直接引用 models 的代码(如果存在),做一个别名映射
 if (!class_exists('\bizGhs\express\models\GhsDeliveryOrder')) {
     class_alias(\bizGhs\express\classes\GhsDeliveryOrderAR::class, '\bizGhs\express\models\GhsDeliveryOrder');
-}
+}

+ 0 - 1
biz-hd/express/classes/ExpressClass.php

@@ -6,7 +6,6 @@ use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\expressUtil;
 use common\components\noticeUtil;
-use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
 

+ 25 - 0
biz-hd/express/classes/HdDeliveryOrderClass.php

@@ -2,10 +2,35 @@
 namespace bizHd\express\classes;
 
 use bizHd\base\classes\BaseClass;
+use common\components\noticeUtil;
+use Yii;
 
 class HdDeliveryOrderClass extends BaseClass
 {
     public static $baseFile = HdDeliveryOrderAR::class;
+
+    //生产者创建下单指令逻辑
+    public static function askCreateOrder($data)
+    {
+        try {
+            $orderId = $data['orderId'] ?? 0;
+            $producer = Yii::$app->rabbitmq->getProducer('ptProducer');
+            $msg = serialize(['type' => 'hd_pt_create_order', 'orderId' => $orderId]);
+            $producer->publish($msg, 'ptExchange', 'ptRoute', ['delivery_mode' => 2, 'content_type' => 'application/octet-stream']);
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "零售花店,跑腿下单,生产消息端报错 {$orderId} {$msg}";
+            noticeUtil::push($remind, '15280215347');
+        }
+    }
+
+    //消费者消费下单指令逻辑
+    public static function beginCreateOrder($data)
+    {
+        //花店,进行下单流程处理
+        noticeUtil::push('已消费hd', '15280215347');
+        return true;
+    }
 }
 
 // 在同文件末尾追加一个内联的 AR 类

+ 5 - 2
common/components/delivery/platform/shunfeng/Shunfeng.php

@@ -30,9 +30,12 @@ class Shunfeng
             $this->devId = 1594082399;
             $this->appSecret = '9025c4f5ad93e8e08e947f02d0cde652';
         } else {
+//            $this->baseUrl = 'https://openic.sf-express.com/open/api/external/';
+//            $this->devId = 1741530942;
+//            $this->appSecret = '07b3f83d19a4a9f89322976c936faf92';
             $this->baseUrl = 'https://openic.sf-express.com/open/api/external/';
-            $this->devId = 1741530942;
-            $this->appSecret = '07b3f83d19a4a9f89322976c936faf92';
+            $this->devId = 1594082399;
+            $this->appSecret = '9025c4f5ad93e8e08e947f02d0cde652';
         }
         $this->shopId = $shopId;
 

+ 15 - 8
common/components/delivery/services/DispatchService.php

@@ -106,25 +106,32 @@ class DispatchService
 
     public function validateOrder($order)
     {
+        $errors = [];
         if(empty($order['address'])){
-            throw new \Exception('客户地址缺失');
+            $errors[] = '客户地址缺失';
         }
     
         if(empty($order['long']) || empty($order['lat'])){
-            throw new \Exception('客户地址信息缺失');
+            $errors[] = '客户经纬度缺失';
         }
 
         if(empty($order['customName'])){
-            throw new \Exception('客户姓名缺失');
+            $errors[] = '客户姓名缺失';
         }
 
         if(empty($order['city'])){
-            throw new \Exception('客户城市信息缺失');
+            $errors[] = '客户城市信息缺失';
         }
 
         if(empty($order['customMobile']) && empty($order['receiveMobile']) && empty($order['bookMobile'])){
-            throw new \Exception('客户联系电话缺失');
+            $errors[] = '客户联系电话缺失';
         }
+
+        if(!empty($errors)){
+            util::fail(implode(', ', $errors));
+        }
+
+        return true;
     }
 
     /**
@@ -541,7 +548,7 @@ class DispatchService
             'deliveryType' => 1,
 
             //补充额外的订单数据
-            'sendNum' => $order['sendNum'],
+            'sendNum' => $order['sendNum'] ?? '',
         ];
 
         $timestamp = strtotime($pickupTime);
@@ -1049,14 +1056,14 @@ class DispatchService
 
                     foreach($item['estimateList'] as $arr) {
                         $serType = $arr['serviceType'] ?? null;
-                        $type = empty($serType) ? '' : $serviceType[$serType];
+                        $type = empty($serType) ? '' : $serviceType[$serType]; //服务类型
 
                         $deliveryList[] = [
                             'name' => '滴滴' . ' (' . $this->adapters['didi']->carType($arr['carType'])  . $type . ')',
                             'en_name' => 'didi',
                             'price' => $arr['fee'],
                             'distance' => $arr['distance'],
-                            'type' => $type, //服务商或车型名称
+                            'type' => $type,
                             'isAble' => true,
                             // ---------------------------------------------
                             'estimateId' => $arr['estimateId'],

+ 1 - 1
common/components/delivery/services/adapter/ShansongAdapter.php

@@ -215,7 +215,7 @@ class ShansongAdapter extends Shansong implements Adapter
             ];
         }
 
-        Yii::error('shansong 报价失败:'.json_encode($resp));
+        Yii::error('shansong 报价失败:'.json_encode($resp, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
         return [
             'platform' => 'shansong',
             'status' => $resp['status'],

+ 0 - 40
common/components/dict.php

@@ -487,46 +487,6 @@ class dict
             'app' => ['id' => 3, 'name' => 'app'],
         ],
 
-        //达达取消原因
-        'dadaCancelReason' => [
-            [
-                'id' => 1,
-                'reason' => '没有配送员接单',
-            ],
-            [
-                'id' => 2,
-                'reason' => '配送员没来取货',
-            ],
-            [
-                'id' => 3,
-                'reason' => '配送员态度太差',
-            ],
-            [
-                'id' => 4,
-                'reason' => '顾客取消订单',
-            ],
-            [
-                'id' => 5,
-                'reason' => '订单填写错误',
-            ],
-            [
-                'id' => 34,
-                'reason' => '配送员让我取消此单',
-            ],
-            [
-                'id' => 35,
-                'reason' => '配送员不愿上门取货',
-            ],
-            [
-                'id' => 36,
-                'reason' => '我不需要配送了',
-            ],
-            [
-                'id' => 37,
-                'reason' => '配送员以各种理由表示无法完成订单',
-            ],
-        ],
-
         //来源
         'fromType' => [
             'shop' => 1,//门店

+ 6 - 5
common/components/rabbitmq/ptConsumer.php

@@ -2,13 +2,11 @@
 /**
  * 跑腿发单消费者
  */
-
 namespace common\components\rabbitmq;
 
 use common\components\noticeUtil;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
-use Yii;
 
 class ptConsumer implements ConsumerInterface
 {
@@ -31,17 +29,20 @@ class ptConsumer implements ConsumerInterface
                 noticeUtil::push("跑腿发单的消费者报错:Invalid notify message format: {$msg->body}", '15280215347');
                 return ConsumerInterface::MSG_REJECT;
             }
-            print_r($data);
+            //print_r($data);
+
             // 根据操作类型分发处理
             $type = $data['type'] ?? null;
             switch ($type) {
                 case 'hd_pt_create_order':
                     //花店跑腿开始下单
-                    $result = \bizHd\express\classes\ExpressClass::beginCreateOrder($data);
+                    //$result = \bizHd\express\classes\ExpressClass::beginCreateOrder($data);
+                    $result = \bizHd\express\classes\HdDeliveryOrderClass::beginCreateOrder($data);
                     break;
                 case 'ghs_pt_create_order':
                     //供货商跑腿开始下单
-                    $result = \bizGhs\express\classes\ExpressClass::beginCreateOrder($data);
+                    //$result = \bizGhs\express\classes\ExpressClass::beginCreateOrder($data);
+                    $result = \bizGhs\express\classes\GhsDeliveryOrderClass::beginCreateOrder($data);
                     break;
                 default:
                     noticeUtil::push("跑腿发单的消费者报错,不存在的类型: {$type}");