瀏覽代碼

发快递

shish 5 年之前
父節點
當前提交
76bbf5e10c

+ 19 - 15
app/ghs/controllers/OrderController.php

@@ -6,14 +6,11 @@ use biz\sj\services\MerchantExtendService;
 use bizHd\wx\classes\WxOpenClass;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
-use bizGhs\custom\services\CustomService;
 use bizGhs\merchant\classes\ShopClass;
 use bizGhs\merchant\services\ShopService;
 use bizGhs\order\classes\OrderClass;
-use bizGhs\order\services\OrderItemService;
 use bizGhs\order\services\OrderService;
 use bizHd\saas\services\RegionService;
-use bizHd\user\services\UserService;
 use bizGhs\product\classes\ProductClass;
 use common\components\configDict;
 use common\components\dateUtil;
@@ -89,7 +86,7 @@ class OrderController extends BaseController
         $post['fromType'] = 1;//商城
         $post['prePrice'] = 0.01;
         $post['actPrice'] = 0.01;
-        $post['sendSide'] = $post['sendSide'] ?? 0;
+        $post['expressId'] = $post['expressId'] ?? 0;
 
         $productJson = $post['product'] ?? '';
         if (empty($productJson)) {
@@ -291,14 +288,21 @@ class OrderController extends BaseController
     //发快递和第三方配送 shish 2021.1.24
     public function actionThirdSend()
     {
-        $respond = [
-            'sendSide' => '达达',
-            'distance' => 5.5,
-            'sendCost' => 20,
-            'status' => 1,
-            'tip' => 5,
-        ];
-        util::success($respond);
+        $get = Yii::$app->request->get();
+        $id = isset($get['id']) ? $get['id'] : 0;
+        $info = OrderClass::getOrderInfo($id);
+        OrderClass::valid($info, $this->shopId);
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $respond = OrderClass::thirdSend($info, $get);
+            $transaction->commit();
+            util::success($respond);
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("发快递操作报错:" . $exception->getMessage());
+            util::fail('操作失败');
+        }
     }
 
     //确认送达 shish 2021.1.24
@@ -461,8 +465,8 @@ class OrderController extends BaseController
 
             $typeList = configDict::getConfig('capitalType');
             $capitalType = $typeList['xhGhsOrder']['id'];
-            $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
-            $passbackParams = urlencode($passbackParams);
+            $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
+            $passBackParams = urlencode($passBackParams);
 
             $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
             $payRequestBuilder->setBody($body);
@@ -471,7 +475,7 @@ class OrderController extends BaseController
             $payRequestBuilder->setTotalAmount($total_amount);
             $payRequestBuilder->setTimeExpress($timeout_express);
             //在异步通知时将该参数原样返回
-            $payRequestBuilder->setPassbackParams($passbackParams);
+            $payRequestBuilder->setPassbackParams($passBackParams);
             //同步通知
             $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
             //异步通知

+ 57 - 1
biz-ghs/order/classes/OrderClass.php

@@ -2,6 +2,7 @@
 
 namespace bizGhs\order\classes;
 
+use biz\express\classes\ExpressClass;
 use bizGhs\product\classes\ProductClass;
 use biz\sj\classes\MerchantAssetClass;
 use bizGhs\admin\classes\AdminClass;
@@ -316,10 +317,65 @@ class OrderClass extends BaseClass
         if ($order['status'] != OrderClass::ORDER_STATUS_SENDING) {
             util::fail('订单没有在配送状态');
         }
+        $id = $order['id'];
         self::updateById($id, ['status' => self::ORDER_STATUS_COMPLETE, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
         OrderSendClass::reach($order);
     }
 
+    //快递送 shish 2021.3.16
+    public static function thirdSend($order, $expressInfo)
+    {
+        if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
+            util::fail('订单未付款');
+        }
+        if ($order['status'] != self::ORDER_STATUS_UN_SEND) {
+            util::fail('不是待配送状态');
+        }
+        $id = $order['id'];
+
+        self::updateById($id, ['status' => self::ORDER_STATUS_SENDING, 'sendType' => self::SEND_TYPE_MYSELF,]);
+
+        $express = OrderExpressClass::getByCondition(['orderId' => $id]);
+        if (!empty($express)) {
+            util::fail('已经发过了');
+        }
+        $orderSn = $order['orderSn'];
+        $expressId = $expressInfo['expressId'] ?? 0;
+        $getInfo = ExpressClass::getExpressInfo($expressId);
+        $expressName = $getInfo['deliveryName'] ?? '';
+        $sjId = $order['merchantId'] ?? 0;
+        $hour = $expressInfo['sendTime'] ?? '12:00';
+        $sendCost = 12;
+        $distance = 5;
+        $status = 1;
+        $sendTime = strtotime(date("Y-m-d ") . $hour);
+        $expData = [
+            'orderId' => $id,
+            'orderSn' => $orderSn,
+            'sjId' => $sjId,
+            'expressId' => $expressId,
+            'sendTime' => $sendTime,
+            'cost' => $sendCost,
+            'distance' => $distance,
+            'status' => $status,
+            'expressName' => $expressName,
+        ];
+        OrderExpressClass::addExpress($expData);
+
+        OrderSendClass::thirdSend($order);
+
+        $respond = [
+            'expressName' => $expressName,
+            'expressId' => $expressId,
+            'distance' => $distance,
+            'sendCost' => $sendCost,
+            'status' => $status,
+            'tip' => 0,
+        ];
+        return $respond;
+
+    }
+
     //本店送 shish 2021.1.24
     public static function selfSend($info)
     {
@@ -327,7 +383,7 @@ class OrderClass extends BaseClass
             util::fail('订单未付款');
         }
         if ($info['status'] != self::ORDER_STATUS_UN_SEND) {
-            util::fail('不是待配送订单');
+            util::fail('不是待配送状态');
         }
         $id = $info['id'];
         self::updateById($id, ['status' => self::ORDER_STATUS_SENDING, 'sendType' => self::SEND_TYPE_MYSELF,]);

+ 35 - 29
biz-ghs/order/classes/OrderExpressClass.php

@@ -8,34 +8,40 @@ use bizGhs\base\classes\BaseClass;
 class OrderExpressClass extends BaseClass
 {
 
-	public static $baseFile = '\bizGhs\order\models\OrderExpress';
-
-	//获取配送进展
-	public static function getProgress($showExpress, $order)
-	{
-		if ($showExpress == false) {
-			return [];
-		}
-		if ($order['sendType'] != OrderClass::SEND_TYPE_THIRD) {
-			return [];
-		}
-		return [
-			'progressName' => '骑手已接单,取货中',
-		];
-	}
-
-	//取当前订单的配送信息
-	public static function getExpress($orderId)
-	{
-		$info = self::getByCondition(['orderId' => $orderId]);
-		if (empty($info)) {
-			return [];
-		}
-		$sideId = $info['sideId'];
-		$sideData = self::$side;
-		$sideName = isset($sideData[$sideId]) ? $sideData[$sideId] : '';
-		$info['sideName'] = $sideName;
-		return $info;
-	}
+    public static $baseFile = '\bizGhs\order\models\OrderExpress';
+
+    //获取配送进展
+    public static function getProgress($showExpress, $order)
+    {
+        if ($showExpress == false) {
+            return [];
+        }
+        if ($order['sendType'] != OrderClass::SEND_TYPE_THIRD) {
+            return [];
+        }
+        return [
+            'progressName' => '骑手已接单,取货中',
+        ];
+    }
+
+    //取当前订单的配送信息
+    public static function getExpress($orderId)
+    {
+        $info = self::getByCondition(['orderId' => $orderId]);
+        if (empty($info)) {
+            return [];
+        }
+        $sideId = $info['sideId'];
+        $sideData = self::$side;
+        $sideName = isset($sideData[$sideId]) ? $sideData[$sideId] : '';
+        $info['sideName'] = $sideName;
+        return $info;
+    }
+
+    //新增快递 shish 2021.3.16
+    public static function addExpress($expData)
+    {
+        return self::add($expData);
+    }
 
 }

+ 121 - 105
biz-ghs/order/classes/OrderSendClass.php

@@ -7,109 +7,125 @@ use common\components\util;
 
 class OrderSendClass extends BaseClass
 {
-	
-	public static $baseFile = '\bizGhs\order\models\OrderSend';
-	
-	//流程键名与ID关系
-	const ACTION_RELATION = ['placeOrder' => 10, 'deliver' => 30, 'reach' => 40];
-	const ACTION_LIST = [
-		10 => ['name' => '下单', 'sign' => 'placeOrder'],
-		30 => ['name' => '发货', 'sign' => 'deliver'],
-		40 => ['name' => '送达', 'sign' => 'reach']
-	];
-	
-	//自己送和本店送 shish 2021.3.4
-	public static function selfSend($order)
-	{
-		$orderSn = $order['orderSn'];
-		$action_data = self::ACTION_RELATION;
-		$currentId = $relation['deliver'] ?? 0;
-		if (empty($currentId)) {
-			util::fail('没有找到流程ID');
-		}
-		$send = self::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId], true);
-		if (empty($send)) {
-			util::fail('配送信息错误');
-		}
-		//0没有选择 1本店送 2发快递
-		$send->option = 1;
-		$send->save();
-	}
-	
-	//下单操作完成 shish 2019.12.13
-	public static function placeOrder($data)
-	{
-		//下单完成
-		$orderSn = $data['orderSn'];
-		$payTime = $data['payTime'];
-		$relation = self::ACTION_RELATION;
-		$actionList = self::ACTION_LIST;
-		$currentId = $relation['placeOrder'] ?? 0;
-		if (empty($currentId)) {
-			util::fail('没有找到流程ID');
-		}
-		$currentName = $actionList[$currentId]['name'] ?? '';
-		$data = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $payTime, 'inTurn' => $currentId, 'status' => 1];
-		self::add($data);
-		
-		OrderClass::updateByCondition(['orderSn' => $orderSn], ['currentFlow' => 1]);
-		
-		//制单未开始
-		$nextId = $relation['deliver'] ?? 0;
-		if (empty($nextId)) {
-			util::fail('下单后没有找到下一步的流程ID');
-		}
-		$nextName = $actionList[$nextId]['name'] ?? '';
-		$data = ['actionId' => $nextId, 'actionName' => $nextName, 'orderSn' => $orderSn, 'inTurn' => $nextId, 'status' => 0];
-		self::add($data);
-	}
-	
-	//当前待执行的动作 shish 2019.12.16
-	public static function toDoActionId($orderSn)
-	{
-		$action = self::getByCondition(['orderSn' => $orderSn], false, 'inTurn DESC');
-		$actionId = 0;
-		if (empty($action['finishTime'])) {
-			$actionId = $action['actionId'];
-		}
-		return $actionId;
-	}
-	
-	//送达 shish 2020.6.1
-	public static function reach($order)
-	{
-		$orderSn = $order['orderSn'];
-		$time = date("Y-m-d H:i:s");
-		$relation = self::ACTION_RELATION;
-		$actionList = self::ACTION_LIST;
-		$currentId = $relation['reach'] ?? 0;
-		if (empty($currentId)) {
-			util::fail('没有找到流程ID');
-		}
-		$currentName = $actionList[$currentId]['name'] ?? '';
-		$has = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId]);
-		if ($has) {
-			util::fail('已经确认送达');
-		}
-
-		$preId = $relation['deliver'] ?? 0;
-		$preActionId = $relation['deliver'] ?? 0;
-		$preInfo = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $preActionId], true);
-		if (empty($preInfo)) {
-			util::fail('配送信息错误,没有找到前面个流程');
-		}
-		$preInfo->status = 1;
-		$preInfo->save();
-
-		$sendData = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $time, 'inTurn' => $currentId, 'status' => 1];
-		OrderSendClass::add($sendData);
-	}
-	
-	//免发货和自取流程处理 shish 2021.1.24
-	public static function withoutSend($info)
-	{
-		$orderSn = $info['orderSn'];
-		self::deleteByCondition(['orderSn' => $orderSn]);
-	}
-	
+
+    public static $baseFile = '\bizGhs\order\models\OrderSend';
+
+    //流程键名与ID关系
+    const ACTION_RELATION = ['placeOrder' => 10, 'deliver' => 30, 'reach' => 40];
+    const ACTION_LIST = [
+        10 => ['name' => '下单', 'sign' => 'placeOrder'],
+        30 => ['name' => '发货', 'sign' => 'deliver'],
+        40 => ['name' => '送达', 'sign' => 'reach']
+    ];
+
+    public static function thirdSend($order)
+    {
+        $orderSn = $order['orderSn'];
+        $relation = self::ACTION_RELATION;
+        $currentId = $relation['deliver'] ?? 0;
+        if (empty($currentId)) {
+            util::fail('没有找到流程');
+        }
+        $send = self::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId], true);
+        if (empty($send)) {
+            util::fail('配送信息错误');
+        }
+        //0没有选择 1本店送 2发快递
+        $send->option = 2;
+        $send->save(); 
+    }
+
+    //本店送 shish 2021.3.4
+    public static function selfSend($order)
+    {
+        $orderSn = $order['orderSn'];
+        $relation = self::ACTION_RELATION;
+        $currentId = $relation['deliver'] ?? 0;
+        if (empty($currentId)) {
+            util::fail('没有找到流程');
+        }
+        $send = self::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId], true);
+        if (empty($send)) {
+            util::fail('配送信息错误');
+        }
+        //0没有选择 1本店送 2发快递
+        $send->option = 1;
+        $send->save();
+    }
+
+    //下单操作完成 shish 2019.12.13
+    public static function placeOrder($data)
+    {
+        //下单完成
+        $orderSn = $data['orderSn'];
+        $payTime = $data['payTime'];
+        $relation = self::ACTION_RELATION;
+        $actionList = self::ACTION_LIST;
+        $currentId = $relation['placeOrder'] ?? 0;
+        if (empty($currentId)) {
+            util::fail('没有找到流程');
+        }
+        $currentName = $actionList[$currentId]['name'] ?? '';
+        $data = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $payTime, 'inTurn' => $currentId, 'status' => 1];
+        self::add($data);
+
+        OrderClass::updateByCondition(['orderSn' => $orderSn], ['currentFlow' => 1]);
+
+        //制单未开始
+        $nextId = $relation['deliver'] ?? 0;
+        if (empty($nextId)) {
+            util::fail('下单后没有找到下一步的流程ID');
+        }
+        $nextName = $actionList[$nextId]['name'] ?? '';
+        $data = ['actionId' => $nextId, 'actionName' => $nextName, 'orderSn' => $orderSn, 'inTurn' => $nextId, 'status' => 0];
+        self::add($data);
+    }
+
+    //当前待执行的动作 shish 2019.12.16
+    public static function toDoActionId($orderSn)
+    {
+        $action = self::getByCondition(['orderSn' => $orderSn], false, 'inTurn DESC');
+        $actionId = 0;
+        if (empty($action['finishTime'])) {
+            $actionId = $action['actionId'];
+        }
+        return $actionId;
+    }
+
+    //送达 shish 2020.6.1
+    public static function reach($order)
+    {
+        $orderSn = $order['orderSn'];
+        $time = date("Y-m-d H:i:s");
+        $relation = self::ACTION_RELATION;
+        $actionList = self::ACTION_LIST;
+        $currentId = $relation['reach'] ?? 0;
+        if (empty($currentId)) {
+            util::fail('没有找到流程');
+        }
+        $currentName = $actionList[$currentId]['name'] ?? '';
+        $has = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId]);
+        if ($has) {
+            util::fail('已经确认送达');
+        }
+
+        $preActionId = $relation['deliver'] ?? 0;
+        $preInfo = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $preActionId], true);
+        if (empty($preInfo)) {
+            util::fail('配送信息错误,没有找到前面个流程');
+        }
+        $preInfo->status = 1;
+        $preInfo->save();
+
+        $sendData = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $time, 'inTurn' => $currentId, 'status' => 1];
+        OrderSendClass::add($sendData);
+    }
+
+    //免发货和自取流程处理 shish 2021.1.24
+    public static function withoutSend($info)
+    {
+        $orderSn = $info['orderSn'];
+        self::deleteByCondition(['orderSn' => $orderSn]);
+    }
+
 }

+ 1 - 1
biz-ghs/order/services/OrderSendService.php

@@ -73,7 +73,7 @@ class OrderSendService extends BaseService
 			
 			util::fail('即将开通...');
 			
-			$side = $data['sendSide'];
+			$side = $data['expressId'];
 			$sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
 			if ($sendTime < ($time + 20 * 60)) {
 				util::fail('请选择20分钟之后的时间');

+ 1 - 1
biz-hd/order/services/OrderSendService.php

@@ -77,7 +77,7 @@ class OrderSendService extends BaseService
 			
 			util::fail('即将开通...');
 			
-			$side = $data['sendSide'];
+			$side = $data['expressId'];
 			$sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
 			if ($sendTime < ($time + 20 * 60)) {
 				util::fail('请选择20分钟之后的时间');

+ 3 - 2
biz/express/classes/ExpressClass.php

@@ -7,8 +7,8 @@ use common\components\util;
 
 class ExpressClass extends BaseClass
 {
-    public static $baseFile = '\biz\express\models\Express';
 
+    public static $baseFile = '\biz\express\models\Express';
 
     public static function getExpressAll($select='*',$where=[])
     {
@@ -33,4 +33,5 @@ class ExpressClass extends BaseClass
         }
         return $res;
     }
-}
+
+}

+ 9 - 1
sql.sql

@@ -1490,4 +1490,12 @@ CREATE TABLE `xhStatYjMonth` (
   PRIMARY KEY (`id`),
   UNIQUE KEY `yj` (`sjId`,`year`,`month`)
 ) COMMENT='员工每月开单业绩';
-ALTER TABLE xhShopAdmin ADD adminName VARCHAR(80) NOT NULL DEFAULT '' COMMENT '员工名称' AFTER `adminId`;
+ALTER TABLE xhShopAdmin ADD adminName VARCHAR(80) NOT NULL DEFAULT '' COMMENT '员工名称' AFTER `adminId`;
+ALTER TABLE xhGhsOrderExpress ADD `orderSn` CHAR(20) NOT NULL DEFAULT '' COMMENT '订单编号' AFTER orderId;
+ALTER TABLE xhOrderExpress ADD `orderSn` CHAR(20) NOT NULL DEFAULT '' COMMENT '订单编号' AFTER orderId;
+ALTER TABLE xhGhsOrderExpress MODIFY `status` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '1待接单 2已接单 3已完成 4已取消';
+ALTER TABLE xhOrderExpress MODIFY `status` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '1待接单 2已接单 3已完成 4已取消';
+ALTER TABLE `xhGhsOrder` CHANGE `sendSide` `expressId` SMALLINT NOT NULL DEFAULT 0 COMMENT '配送方id';
+ALTER TABLE `xhOrder` CHANGE `sendSide` `expressId` SMALLINT NOT NULL DEFAULT 0 COMMENT '配送方id';
+ALTER TABLE `xhGhsOrderExpress` ADD expressName VARCHAR(50) NOT NULL DEFAULT '' COMMENT '配送方名称' AFTER `expressId`;
+ALTER TABLE `xhOrderExpress` ADD expressName VARCHAR(50) NOT NULL DEFAULT '' COMMENT '配送方名称' AFTER `expressId`;