shish 5 سال پیش
والد
کامیت
9c4b34dc4e

+ 47 - 78
app/ghs/controllers/OrderSendController.php

@@ -2,87 +2,56 @@
 
 namespace ghs\controllers;
 
-use biz\order\services\OrderSendService;
-use biz\order\services\OrderService;
+use bizGhs\order\services\OrderSendService;
+use bizGhs\order\services\OrderService;
 use Yii;
 use common\components\util;
 
 class OrderSendController extends BaseController
 {
-	
-	//发货 shish 2019.12.16
-	public function actionDetail()
-	{
-		$id = Yii::$app->request->get('id', 0);
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		$list = OrderSendService::sendList($order);
-		util::success($list);
-	}
-	
-	//制单 免填单 填单 shish 2019.12.16
-	public function actionPrintOrder()
-	{
-		$post = Yii::$app->request->post();
-		$id = isset($post['id']) ? $post['id'] : 0;
-		$option = isset($post['option']) ? $post['option'] : 0;
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		OrderSendService::printOrder(['id' => $id, 'option' => $option]);
-	}
-	
-	//发货 shish 2019.12.17
-	public function actionDeliver()
-	{
-		$post = Yii::$app->request->post();
-		$id = isset($post['id']) ? $post['id'] : 0;
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		$post['merchantId'] = $this->merchantId;
-		OrderSendService::deliver($post);
-	}
-	
-	//送达 shish 2019.12.17
-	public function actionReach()
-	{
-		$post = Yii::$app->request->post();
-		$id = isset($post['id']) ? $post['id'] : 0;
-		$option = isset($post['option']) ? $post['option'] : 0;
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->merchantId);
-		OrderSendService::reach($order, ['option' => $option]);
-	}
-	
-	//向快递公司发起配送需求
-	public function actionExpress()
-	{
-	
-	}
-	
-	//取消快递
-	public function actionCancelExpress()
-	{
-		$sendSide = 1;
-		$sendTime = '10:21';
-	}
-	
-	//添加小费
-	public function actionAddTip()
-	{
-	
-	}
-	
-	//结果回调通知
-	public function actionExpressCallback()
-	{
-	
-	}
-	
-	//快递服务提供方
-	public function actionExpressProvide()
-	{
-		$data = ['id' => 1, 'name' => '达达'];
-		util::success($data);
-	}
-	
+
+    //发货 shish 2019.12.16
+    public function actionDetail()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $order = OrderService::getById($id);
+        OrderService::valid($order, $this->merchantId);
+        //发货列表
+        $list = OrderSendService::sendList($order);
+        util::success($list);
+    }
+
+    //制单 免填单 填单 shish 2019.12.16
+    public function actionPrintOrder()
+    {
+        $post = Yii::$app->request->post();
+        $id = isset($post['id']) ? $post['id'] : 0;
+        $option = isset($post['option']) ? $post['option'] : 0;
+        $order = OrderService::getById($id);
+        OrderService::valid($order, $this->merchantId);
+        OrderSendService::printOrder(['id' => $id, 'option' => $option]);
+    }
+
+    //发货 shish 2019.12.17
+    public function actionDeliver()
+    {
+        $post = Yii::$app->request->post();
+        $id = isset($post['id']) ? $post['id'] : 0;
+        $order = OrderService::getById($id);
+        OrderService::valid($order, $this->merchantId);
+        $post['merchantId'] = $this->merchantId;
+        OrderSendService::deliver($post);
+    }
+
+    //送达 shish 2019.12.17
+    public function actionReach()
+    {
+        $post = Yii::$app->request->post();
+        $id = isset($post['id']) ? $post['id'] : 0;
+        $option = isset($post['option']) ? $post['option'] : 0;
+        $order = OrderService::getById($id);
+        OrderService::valid($order, $this->merchantId);
+        OrderSendService::reach($order, ['option' => $option]);
+    }
+
 }

+ 12 - 0
biz-ghs/order/classes/OrderClass.php

@@ -153,4 +153,16 @@ class OrderClass extends BaseClass
         return current($respond);
     }
 
+    //订单到期未付款未确认的订单置成取消状态 shish 2021.1.23
+    public static function setExpire($order)
+    {
+        $now = time();
+        if (isset($order['deadline']) && $now > $order['deadline']) {
+            if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
+                $id = $order['id'];
+                self::updateById($id, ['status' => self::ORDER_STATUS_CANCEL]);
+            }
+        }
+    }
+
 }

+ 5 - 4
biz-ghs/order/classes/OrderSendClass.php

@@ -22,6 +22,7 @@ class OrderSendClass extends BaseClass
     {
         //下单完成
         $orderId = $data['orderId'];
+        $orderSn = $data['orderSn'];
         $payTime = $data['payTime'];
         $actionId = self::$actionId;
         $placeOrderId = $actionId['placeOrder'];
@@ -32,8 +33,8 @@ class OrderSendClass extends BaseClass
         OrderClass::updateById($orderId, ['currentFlow' => 1]);
 
         //制单未开始
-        $printOrderId = $actionId['printOrder'];
-        $data = ['actionId' => $printOrderId, 'orderId' => $orderId, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $printOrderId];
+        $deliverId = $actionId['deliver'];
+        $data = ['actionId' => $deliverId, 'orderSn' => $orderSn, 'finishTime' => 0, 'inTurn' => $deliverId];
         self::add($data);
     }
 
@@ -86,9 +87,9 @@ class OrderSendClass extends BaseClass
         $merchantId = $order['merchantId'];
         $merchant = MerchantClass::getById($merchantId);
         //完成通知客户
-        InformUserClass::sendComplete($user, $order, $merchant);
+        //InformUserClass::sendComplete($user, $order, $merchant);
         //完成通知管理员
-        InformAdminClass::sendComplete($order);
+        //InformAdminClass::sendComplete($order);
     }
 
 

+ 164 - 0
biz-ghs/order/services/OrderSendService.php

@@ -3,6 +3,7 @@
 namespace bizGhs\order\services;
 
 use bizGhs\base\services\BaseService;
+use bizGhs\order\classes\OrderSendClass;
 use Yii;
 
 class OrderSendService extends BaseService
@@ -10,4 +11,167 @@ class OrderSendService extends BaseService
 
     public static $baseFile = '\bizGhs\order\classes\OrderSendClass';
 
+
+    //制单 shish 2019.12.17
+    public static function printOrder($data)
+    {
+        $id = $data['id'];
+        $option = $data['option'];
+        $actionIdList = OrderSendClass::$actionId;
+        $printOrderId = $actionIdList['printOrder'];
+        $currentId = OrderSendClass::toDoActionId($id);
+        if ($printOrderId != $currentId) {
+            util::fail('当前流程无法操作');
+        }
+        //1有配送单 2 填单制单
+        if (in_array($option, [1, 2]) == false) {
+            util::fail('操作无效');
+        }
+        $time = time();
+        OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $printOrderId], ['option' => $option, 'finishTime' => $time]);
+        $hasDeliver = 0;
+        if ($option == 1) {
+            //有纸质配送单
+            $hasDeliver = 1;
+        }
+        if ($option == 2) {
+            //填单制单
+            $hasDeliver = 2;
+        }
+        OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_UN_SEND, 'currentFlow' => 2, 'printStatus' => 1, 'hasDeliver' => $hasDeliver]);
+
+        //进入发货流程
+        $deliverId = $actionIdList['deliver'];
+        $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId];
+        OrderSendClass::add($data);
+        $actionList = OrderSendClass::$action;
+        $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
+        util::success(['nextAction' => $data]);
+    }
+
+    //发货 shish 2019.12.17
+    public static function deliver($data)
+    {
+        $id = $data['id'];
+        $option = $data['option'];
+        $actionIdList = OrderSendClass::$actionId;
+        $deliverId = $actionIdList['deliver'];
+        $currentId = OrderSendClass::toDoActionId($id);
+        if ($deliverId != $currentId) {
+            util::fail('当前流程无法操作');
+        }
+        $time = time();
+
+        $sendType = isset($data['sendType']) ? $data['sendType'] : OrderClass::SEND_TYPE_UNKNOWN;
+
+        $sendInfo = [];
+        if ($sendType == OrderClass::SEND_TYPE_OTHER) {
+
+            util::fail('即将开通...');
+
+            $side = $data['sendSide'];
+            $sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
+            if ($sendTime < ($time + 20 * 60)) {
+                util::fail('请选择20分钟之后的时间');
+            }
+            $sendInfo = [
+                'sideId' => $side,
+                'sendTime' => $sendTime,
+                'addTime' => $time,
+                'sendTip' => 0,
+                'merchantId' => $data['merchantId'],
+                'orderId' => $id,
+                'cost' => 6,
+                'tip' => 0,
+                'distance' => 7,
+                'sendTime' => $sendTime,
+                'side' => $side,
+            ];
+            OrderExpressClass::add($sendInfo);
+        }
+
+        OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $deliverId], ['option' => $option, 'finishTime' => $time]);
+        OrderClass::updateById($id, ['status' => OrderClass::ORDER_STATUS_SENDING, 'currentFlow' => 3, 'sendType' => $sendType]);
+
+        //待发货订单-1,配送中订单+1
+        $merchantId = $data['merchantId'];
+        $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $asset->unSendOrder -= 1;
+        $asset->sendingOrder += 1;
+        $asset->save();
+
+        //进入送达流程
+        $reachId = $actionIdList['reach'];
+        $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId];
+        OrderSendClass::add($data);
+        $actionList = OrderSendClass::$action;
+        $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';
+        util::success(['nextAction' => $data, 'sendInfo' => $sendInfo]);
+    }
+
+    //送达 shish 2019.12.17
+    public static function reach($order, $data)
+    {
+        $id = $order['id'];
+        $actionIdList = OrderSendClass::$actionId;
+        $reachId = $actionIdList['reach'];
+        $currentId = OrderSendClass::toDoActionId($id);
+        if ($reachId != $currentId) {
+            util::fail('当前流程无法操作');
+        }
+        OrderSendClass::reach($order);
+        OrderClass::complete($order, OrderClass::ORDER_TOTAL_FLOW);
+        //配送中订单-1,完成订单+1
+        $merchantId = $order['merchantId'];
+        $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $asset->sendingOrder -= 1;
+        $asset->finishOrder += 1;
+        $asset->save();
+        util::complete();
+    }
+
+    //发货详情 shish 2019.12.15
+    public static function sendList($order)
+    {
+        $orderId = $order['id'];
+        $orderSn = $order['orderSn'];
+        $list = OrderSendClass::getAllByCondition(['orderSn' => $orderSn], 'inTurn DESC', '*');
+        if (empty($list)) {
+            return [];
+        }
+        $nameList = OrderSendClass::$action;
+        $idList = OrderSendClass::$actionId;
+        foreach ($list as $key => $val) {
+            $actionId = $val['actionId'];
+            $list[$key]['actionName'] = isset($nameList[$actionId]['name']) ? $nameList[$actionId]['name'] : '';
+            $list[$key]['actionSign'] = isset($nameList[$actionId]['sign']) ? $nameList[$actionId]['sign'] : '';
+            if ($actionId == $idList['printOrder']) {
+                $list[$key]['receive'] = [];
+                if (!empty($order['receiveUserName'])) {
+                    $list[$key]['receive'] = [
+                        'receiveUserName' => $order['receiveUserName'],
+                        'receiveMobile' => $order['receiveMobile'],
+                        'receiveAddress' => $order['receiveAddress'],
+                        'receiveFloor' => $order['receiveFloor'],
+                        'receiveFullAddress' => $order['receiveFullAddress'],
+                    ];
+                }
+            }
+            if ($actionId == $idList['deliver']) {
+                $list[$key]['sendInfo'] = $order['sendType'] == OrderClass::SEND_TYPE_OTHER ? OrderExpressClass::getExpress($orderId) : [];
+            }
+            if ($actionId == $idList['reach']) {
+                $list[$key]['classify'] = [];
+                if ($order['classify'] == 1) {
+                    $category = CategoryClass::getById($order['categoryId']);
+                    $categoryName = isset($category['categoryName']) ? $category['categoryName'] : '';
+                    $usage = UsageClass::getById($order['usageId']);
+                    $usageName = isset($usage['usageName']) ? $usage['usageName'] : '';
+                    $list[$key]['classify'] = ['category' => $categoryName, 'usage' => $usageName];
+                }
+            }
+        }
+        return $list;
+    }
+
 }