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

即时配送新增订单,状态变更

林琦海 4 лет назад
Родитель
Сommit
a7f0fcf5be

+ 8 - 1
app-ghs/controllers/ExpressController.php

@@ -7,6 +7,7 @@
 namespace ghs\controllers;
 
 
+use biz\shop\classes\ShopExpressClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\services\CustomService;
 use bizGhs\express\services\MiniExpressService;
@@ -43,7 +44,12 @@ class ExpressController extends BaseController
         $cargoInfo = ProductService::groupCargo($ghsItemInfo);
 
         $shop_order_id = time();
-        $shop_no = ""; //与快递签约时的门店ID(应该是固定的)
+        $expressData = MiniExpressService::getExpressInfo($expressId);
+        if(empty($expressData)){
+            util::fail("暂不支持");
+        }
+
+        $shop_no = ShopExpressClass::getShopNo($this->sjId,$this->shopId,strtolower( $expressData['deliveryId'])); //与快递签约时的门店ID
 
         $openid = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
         if (empty($openId)) {
@@ -106,6 +112,7 @@ class ExpressController extends BaseController
         $expressId = $post['expressId'] ?? 0;// 快递ID
         $orderSn = $post['orderSn'] ?? '';
 
+
     }
 
 

+ 21 - 0
biz-ghs/express/classes/DeliveryOrderClass.php

@@ -0,0 +1,21 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2022/7/24 21:54
+ */
+
+namespace bizGhs\express\classes;
+
+use bizHd\base\classes\BaseClass;
+class DeliveryOrderClass extends BaseClass
+{
+    public static $baseFile = '\bizGhs\express\models\DeliveryOrder';
+
+    //新增订单
+    public static function addOrder($data)
+    {
+        return self::add($data);
+    }
+
+
+}

+ 16 - 0
biz-ghs/express/models/DeliveryOrder.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2022/7/24 21:53
+ */
+
+namespace bizGhs\express\models;
+
+use bizHd\base\models\Base;
+class DeliveryOrder extends Base
+{
+    public static function tableName()
+    {
+        return 'xhDeliveryOrder';
+    }
+}

+ 85 - 0
biz-ghs/express/services/DeliveryOrderServices.php

@@ -0,0 +1,85 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2022/7/24 22:03
+ */
+
+namespace bizGhs\express\services;
+
+use bizGhs\express\classes\DeliveryOrderClass;
+use bizHd\base\services\BaseService;
+use common\components\util;
+use Yii;
+class DeliveryOrderServices extends BaseService
+{
+    public static $baseFile = '\bizGhs\express\classes\DeliveryOrderClass';
+
+    //新增即时配送订单
+    public static function addOrder($sjId,$shopId,$expressId, $shopNo, $orderSn, $openId, $sender, $receiver, $cargo, $orderInfo, $shop)
+    {
+        $res  = MiniExpressService::addOrder($expressId,$shopNo,$orderSn,$openId,$sender,$receiver,$cargo,$orderInfo,$shop);
+
+        $expressData = MiniExpressService::getExpressInfo($expressId);
+        $data = $res;
+        $data['sjId'] = $sjId;
+        $data['shopId'] = $shopId;
+        $data['orderSn'] = $orderSn;
+        $data['deliveryId'] = $expressData['deliveryId'];
+        $data['deliveryName'] = $expressData['deliveryName'];
+        $data['waybillId'] = $res['waybill_id'];
+        $data['orderStatus'] = $res['order_status'];
+        $data['finishCode'] = $res['finish_code'];
+        $data['pickupCode'] = $res['pickup_code'];
+        $data['dispatchDuration'] = $res['dispatch_duration'];
+        $order = DeliveryOrderClass::addOrder($data);
+        return $order;
+    }
+
+    //订单状态变更
+    public static function updateOrder($shopId,$waybillId,$orderSn,array  $data)
+    {
+        $orderStatus = $data['order_status'];
+        $actionMsg = $data['action_msg']??'';
+        $riderName = $data['rider_name']??'';
+        $ridePhone = $data['ride_phone']??'';
+        $expectedDeliveryTime = $data['expected_delivery_time']??false;
+        $isPhoneEncrypted = $data['expected_delivery_time']??false;
+        // 日志记录
+        Yii::info("订单状态变更 : waybillId". $waybillId . " data= " . json_encode($data));
+        if(!$orderStatus){
+            util::fail("订单状态错误");
+        }
+        $orderStatusMap = array_keys(MiniExpressService::$orderStatusMap);
+        if(!in_array($orderStatus,$orderStatusMap)){
+            util::fail("订单状态异常");
+        }
+        $upData = [];
+        $upData['orderStatus'] = $orderStatus;
+        if($actionMsg){
+            $upData['actionMsg'] = $actionMsg;
+        }
+        if($riderName){
+            $upData['riderName'] = $riderName;
+        }
+        if($ridePhone){
+            $upData['ridePhone'] = $ridePhone;
+        }
+        if($expectedDeliveryTime!==false){
+            $upData['expectedDeliveryTime'] = $expectedDeliveryTime;
+        }
+        if($isPhoneEncrypted!==false){
+            $upData['isPhoneEncrypted'] = $isPhoneEncrypted;
+        }
+        $where = [];
+        $where['shopId'] = $shopId;
+        $where['orderSn'] = $orderSn;
+        $where['waybillId'] = $waybillId;
+
+        $check = DeliveryOrderClass::getByCondition($where);
+        if(!$check){
+            util::fail("订单不存在");
+        }
+        $res = DeliveryOrderClass::getById($check['id'],$upData);
+        return $res;
+    }
+}

+ 15 - 0
common/components/miniUtil.php

@@ -1773,6 +1773,21 @@ class miniUtil
     /*
      * 商家可调用本接口向配送公司请求下配送单,配送公司会返回这一单的配送单号、配送费、预计骑手接单时间等信息。
 如遇下单错误,请先确认一下编码方式,python建议 json.dumps(b, ensure_ascii=False),php建议 json_encode($arr, JSON_UNESCAPED_UNICODE) 可预约时间:达达:72小时内,闪送2小时以后,48小时以内
+    {
+  "resultcode": 0,
+  "resultmsg": "ok",
+  "fee": 10, 实际运费(单位:元),运费减去优惠券费用
+  "deliverfee": 10, 运费(单位:元)
+  "couponfee": 0, 优惠券费用(单位:元)
+  "tips": 0, 小费(单位:元)
+  "insurancfee": 0, 保价费(单位:元)
+  "distance": 1000, 配送距离(整数单位:米)
+  "waybill_id": "123456789",  配送单号
+  "order_status": 101, 配送状态。
+  "finish_code": 1024, 收货码
+  "pickup_code": 2048,  取货码
+  "dispatch_duration": 300  预计骑手接单时间,单位秒,比如5分钟,就填300, 无法预计填0
+}
      */
     public static function addOrder($data, $merchant, $ptStyle = 0)
     {