shish 5 лет назад
Родитель
Сommit
eeb9342b0d

+ 34 - 0
app/ghs/controllers/OrderItemController.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace ghs\controllers;
+
+use bizGhs\order\classes\OrderClass;
+use bizGhs\order\services\OrderItemService;
+use bizGhs\product\classes\ProductClass;
+use common\components\util;
+use Yii;
+
+class OrderItemController extends BaseController
+{
+
+    public $guestAccessAction = [];
+
+    //重选花材 shish 2021.3.2
+    public function actionReset()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'] ?? 0;
+        $product = $post['product'] ?? '[]';
+        $product = json_decode($product, true);
+        //检查花材是否都是同家门店的
+        ProductClass::valid($product, $this->shopId);
+
+        $info = OrderClass::getOrderInfo($id);
+        OrderClass::valid($info, $this->shopId);
+
+        //添加修改花材
+        OrderItemService::replace($info, $product);
+        util::complete();
+    }
+
+}

+ 316 - 298
biz-ghs/order/classes/OrderClass.php

@@ -15,302 +15,320 @@ use bizGhs\base\classes\BaseClass;
 
 class OrderClass extends BaseClass
 {
-	
-	public static $baseFile = '\bizGhs\order\models\Order';
-	
-	//已完成
-	const ORDER_STATUS_COMPLETE = 6;
-	//已取消
-	const ORDER_STATUS_CANCEL = 5;
-	//待通知
-	const ORDER_STATUS_UN_NOTICE = 4;
-	//配送中
-	const ORDER_STATUS_SENDING = 3;
-	//待配送
-	const ORDER_STATUS_UN_SEND = 2;
-	//待付款,待确认
-	const ORDER_STATUS_UN_PAY = 1;
-	
-	//未确认
-	const SEND_TYPE_UNKNOWN = 1;
-	//自取
-	const SEND_TYPE_NO = 2;
-	//自己送
-	const SEND_TYPE_MYSELF = 3;
-	//快递送,第三方配送
-	const SEND_TYPE_THIRD = 4;
-	
-	//待付款,待确认
-	const PAY_STATUS_UN_PAY = 1;
-	//已付款
-	const PAY_STATUS_HAS_PAY = 2;
-	
-	//待配送
-	const SEND_STATUS_UN_SEND = 1;
-	//配送中
-	const SEND_STATUS_SENDING = 2;
-	//配送完成
-	const SEND_STATUS_COMPLETE = 3;
-	
-	
-	//订单总流程数
-	const TOTAL_FLOW = 3;
-	
-	//添加订单 shish 2019.12.5
-	public static function addOrder($data)
-	{
-		$merchantId = $data['merchantId'] ?? 0;
-		$month = date("Ym");
-		$orderSn = orderSn::getGhsOrderSn();
-		$data['orderSn'] = $orderSn;
-		$data['payStatus'] = self::PAY_STATUS_UN_PAY;
-		
-		//花材列表
-		$product = $data['product'];
-		OrderItemClass::replace($orderSn, $product);
-		
-		//将花店每月的总订单数作为编号
-		$riseNum = StatOrderCountClass::addOrder($month, $merchantId);
-		$data['sendNum'] = $riseNum;
-		$data['num'] = 1;
-		$data['smallNum'] = 1;
-		$data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
-		//订单30分钟后过期
-		$data['deadline'] = date("Y-m-d H:i:s", (time() + 1800));
-		$data['sendCost'] = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
-		$return = self::add($data);
-		$orderId = $return['id'];
-		
-		//全部订单+1,待付款订单+1
-		$merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
-		$merchantAsset->unPayOrder += 1;
-		$merchantAsset->totalOrder += 1;
-		$merchantAsset->save();
-		
-		//增加下单流程
-		$payTime = date("Y-m-d H:i:s");
-		$sendData = ['orderId' => $orderId, 'orderSn' => $orderSn, 'payTime' => $payTime];
-		OrderSendClass::placeOrder($sendData);
-		
-		//扣库存 2021.2.23 linqh
-		foreach ($product as $key => $val) {
-			ProductClass::decreaseStock($val['productId'], $val['num'], $val['smallNum']);
-		}
-		return $return;
-	}
-	
-	//根据订单编号查询 shish 2021.19
-	public static function getByOrderSn($orderSn)
-	{
-		return self::getByCondition(['orderSn' => $orderSn]);
-	}
-	
-	//订单列表 shish 2021.1.19
-	public static function getOrderList($where)
-	{
-		$data = self::getList('*', $where, 'addTime DESC');
-		$data['list'] = self::groupOrder($data['list'], true);
-		$data['allNum'] = 0;
-		$data['unPayNum'] = 0;
-		$data['unSendNum'] = 0;
-		$data['sendingNum'] = 0;
-		$data['finishNum'] = 0;
-		return $data;
-	}
-	
-	//显示操作按钮
-	public static function getShowButton($showButton, $order)
-	{
-		if ($showButton == false) {
-			return [];
-		}
-		$item = ['type' => 'item', 'show' => 1, 'disable' => 0];
-		if ($order['sendStatus'] > 0) {
-			//只有待发货订单,花材按钮才能点击
-			$item['disable'] = 1;
-		}
-		$send = ['type' => 'send', 'show' => 1, 'disable' => 0];
-		if ($order['sendType'] == 1) {
-			//自取订单,发货按钮不可点
-			$send['disable'] = 1;
-		}
-		$selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
-		if ($order['sendType'] == 0) {
-			//只有未确认配送方式的订单才可点击自取
-			$selfGet['disable'] = 0;
-		}
-		return [$item, $send, $selfGet];
-	}
-	
-	//显示进度 shish 2021.3.1
-	public static function getShowProgress($showProgress, $order)
-	{
-		if ($showProgress == false) {
-			return [];
-		}
-		$create = ['name' => '创建', 'complete' => 1];
-		$unConfirm = ['name' => '待确认', 'complete' => 0];
-		if ($order['status'] > 0) {
-			$unConfirm['complete'] = 1;
-		}
-		$out = ['name' => '出库', 'complete' => 0];
-		if ($order['status'] > 1) {
-			$out['complete'] = 1;
-		}
-		return [$create, $unConfirm, $out];
-	}
-	
-	public static function getShowItem($showItem, $order)
-	{
-		if ($showItem == false) {
-			return ['list' => [], 'itemStat' => []];
-		}
-		$orderSn = $order['orderSn'];
-		$list = OrderItemClass::getOrderItem($orderSn);
-		$totalPrice = 0;
-		$totalBigNum = 0;
-		$totalSmallNum = 0;
-		$kind = 0;
-		$itemStat = [];
-		if (!empty($list)) {
-			foreach ($list as $key => $val) {
-				$list[$key]['property'] = $val['rank'] . '级';
-				$price = $val['price'];
-				$totalPrice = stringUtil::calcAdd($totalPrice, $price);
-				$kind++;
-				$currentBigNum = $val['bigNum'];
-				$currentSmallNum = $val['smallNum'];
-				$totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
-				$totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
-			}
-			$itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
-		}
-		return ['list' => $list, 'itemStat' => $itemStat];
-	}
-	
-	//整合订单员工和供货商等信息 shish 2021.1.19
-	public static function groupOrder($list, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false)
-	{
-		if (empty($list)) {
-			return $list;
-		}
-		
-		$customIds = array_unique(array_filter(array_column($list, 'customId')));
-		$customInfo = CustomClass::getCustomByIds($customIds);
-		
-		$adminIds = array_unique(array_filter(array_column($list, 'adminId')));
-		$adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
-		
-		foreach ($list as $key => $val) {
-			$adminId = $val['adminId'] ?? 0;
-			$list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
-			$customId = $val['customId'] ?? 0;
-			$list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
-			$list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
-			$list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
-			$list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
-			//显示列表页的操作按钮
-			$list[$key]['buttonList'] = self::getShowButton($showButton, $val);
-			//显示进度条
-			$list[$key]['progress'] = self::getShowProgress($showProgress, $val);
-			//显示产品
-			$showItem = self::getShowItem($showItem, $val);
-			$list[$key]['product'] = $showItem['list'];
-			$list[$key]['productStat'] = $showItem['itemStat'];
-			
-			//显示重选花材按钮
-			$showResetItem = 1;
-			//配送中和已完成的不显示重选花材按钮
-			if (in_array($val['sendStatus'], [self::SEND_STATUS_SENDING, self::SEND_STATUS_COMPLETE])) {
-				$showResetItem = 0;
-			}
-			$list[$key]['showResetItem'] = 1;
-			//获取配送进展
-			$list[$key]['expressProgress'] = OrderExpressClass::getProgress($showExpress, $val);
-		}
-		return $list;
-	}
-	
-	//订单的验证 shish 2021.3.2
-	public static function valid($info, $shopId)
-	{
-		if (empty($info)) {
-			util::fail('没有找到订单');
-		}
-		if (isset($info['shopId']) && $info['shopId'] == $shopId) {
-			return true;
-		}
-		util::fail('没有权限操作的订单');
-	}
-
-	//获取订单详情 shish 2021.1.21
-	public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false)
-	{
-		$info = self::getById($id);
-		if (empty($info)) {
-			util::fail('没有找到订单');
-		}
-		$respond = self::groupOrder([$info], $showButton, $showProgress, $showItem, $showExpress);
-		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]);
-			}
-		}
-	}
-	
-	//本店送 shish 2021.1.24
-	public static function selfSend($info)
-	{
-		if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_PAY) {
-			util::fail('订单不是待配送状态!');
-		}
-		if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_SEND) {
-			util::fail('订单不是待配送状态');
-		}
-		$id = $info['id'];
-		self::updateById($id, [
-			'status' => self::ORDER_STATUS_SENDING,
-			'sendType' => self::SEND_TYPE_MYSELF,
-		]);
-	}
-	
-	//自取和免发货流程的处理 shish 2021.1.24
-	public static function withoutSend($order)
-	{
-		$id = $order['id'];
-		if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
-			util::fail('订单已完成');
-		}
-		
-		//订单状态变更
-		self::updateById($id, ['sendType' => self::SEND_TYPE_NO, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
-		self::complete($order, self::TOTAL_FLOW);
-		
-		OrderSendClass::withoutSend($order);
-		
-		//待发货订单-1,完成订单+1
-		$merchantId = $order['merchantId'];
-		$asset = MerchantAssetClass::getByMerchantId($merchantId, true);
-		$asset->finishOrder += 1;
-		$asset->unSendOrder -= 1;
-		$asset->save();
-		
-		return self::TOTAL_FLOW;
-	}
-	
-	//订单完成 shish 2020.3.12
-	public static function complete($order, $currentFlow)
-	{
-		$id = $order['id'];
-		self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]);
-	}
-	
+
+    public static $baseFile = '\bizGhs\order\models\Order';
+
+    //已完成
+    const ORDER_STATUS_COMPLETE = 6;
+    //已取消
+    const ORDER_STATUS_CANCEL = 5;
+    //待通知
+    const ORDER_STATUS_UN_NOTICE = 4;
+    //配送中
+    const ORDER_STATUS_SENDING = 3;
+    //待配送
+    const ORDER_STATUS_UN_SEND = 2;
+    //待付款,待确认
+    const ORDER_STATUS_UN_PAY = 1;
+
+    //未确认
+    const SEND_TYPE_UNKNOWN = 1;
+    //自取
+    const SEND_TYPE_NO = 2;
+    //自己送
+    const SEND_TYPE_MYSELF = 3;
+    //快递送,第三方配送
+    const SEND_TYPE_THIRD = 4;
+
+    //待付款,待确认
+    const PAY_STATUS_UN_PAY = 1;
+    //已付款
+    const PAY_STATUS_HAS_PAY = 2;
+
+    //待配送
+    const SEND_STATUS_UN_SEND = 1;
+    //配送中
+    const SEND_STATUS_SENDING = 2;
+    //配送完成
+    const SEND_STATUS_COMPLETE = 3;
+
+
+    //订单总流程数
+    const TOTAL_FLOW = 3;
+
+    //添加订单 shish 2019.12.5
+    public static function addOrder($data)
+    {
+        $merchantId = $data['merchantId'] ?? 0;
+        $month = date("Ym");
+        $orderSn = orderSn::getGhsOrderSn();
+        $data['orderSn'] = $orderSn;
+        $data['payStatus'] = self::PAY_STATUS_UN_PAY;
+
+        //花材列表
+        $product = $data['product'];
+        OrderItemClass::replace($orderSn, $product);
+
+        //将花店每月的总订单数作为编号
+        $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
+        $data['sendNum'] = $riseNum;
+        $data['num'] = 1;
+        $data['smallNum'] = 1;
+        $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
+        //订单30分钟后过期
+        $data['deadline'] = date("Y-m-d H:i:s", (time() + 1800));
+        $data['sendCost'] = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
+        $return = self::add($data);
+        $orderId = $return['id'];
+
+        //全部订单+1,待付款订单+1
+        $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $merchantAsset->unPayOrder += 1;
+        $merchantAsset->totalOrder += 1;
+        $merchantAsset->save();
+
+        //增加下单流程
+        $payTime = date("Y-m-d H:i:s");
+        $sendData = ['orderId' => $orderId, 'orderSn' => $orderSn, 'payTime' => $payTime];
+        OrderSendClass::placeOrder($sendData);
+
+        //扣库存 2021.2.23 linqh
+        foreach ($product as $key => $val) {
+            ProductClass::decreaseStock($val['productId'], $val['num'], $val['smallNum']);
+        }
+        return $return;
+    }
+
+    //根据订单编号查询 shish 2021.19
+    public static function getByOrderSn($orderSn)
+    {
+        return self::getByCondition(['orderSn' => $orderSn]);
+    }
+
+    //订单列表 shish 2021.1.19
+    public static function getOrderList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        $data['list'] = self::groupOrder($data['list'], true);
+        $data['allNum'] = 0;
+        $data['unPayNum'] = 0;
+        $data['unSendNum'] = 0;
+        $data['sendingNum'] = 0;
+        $data['finishNum'] = 0;
+        return $data;
+    }
+
+    //显示操作按钮
+    public static function getShowButton($showButton, $order)
+    {
+        if ($showButton == false) {
+            return [];
+        }
+
+        //待确认订单显示延期付和已付款
+        if ($order['status'] == OrderClass::ORDER_STATUS_UN_PAY) {
+            $debtPay = ['type' => 'debtPay', 'show' => 1, 'disable' => 0];
+            $hasPay = ['type' => 'hasPay', 'show' => 1, 'disable' => 0];
+            return [$debtPay, $hasPay];
+        }
+
+        //待配送订单显示打印、发货和自取
+        if ($order['status'] == OrderClass::ORDER_STATUS_UN_SEND) {
+            //没有花材的订单按钮全部置灰色不可点
+            if ($order['hasItem'] == 2) {
+                $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
+                $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
+                return [$print, $selfGet];
+            }
+        }
+
+        $item = ['type' => 'item', 'show' => 1, 'disable' => 0];
+        if ($order['sendStatus'] > 0) {
+            //只有待发货订单,花材按钮才能点击
+            $item['disable'] = 1;
+        }
+        $send = ['type' => 'send', 'show' => 1, 'disable' => 0];
+        if ($order['sendType'] == 1) {
+            //自取订单,发货按钮不可点
+            $send['disable'] = 1;
+        }
+        $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
+        if ($order['sendType'] == 0) {
+            //只有未确认配送方式的订单才可点击自取
+            $selfGet['disable'] = 0;
+        }
+        return [$item, $send, $selfGet];
+    }
+
+    //显示进度 shish 2021.3.1
+    public static function getShowProgress($showProgress, $order)
+    {
+        if ($showProgress == false) {
+            return [];
+        }
+        $create = ['name' => '创建', 'complete' => 1];
+        $unConfirm = ['name' => '待确认', 'complete' => 0];
+        if ($order['status'] > 0) {
+            $unConfirm['complete'] = 1;
+        }
+        $out = ['name' => '出库', 'complete' => 0];
+        if ($order['status'] > 1) {
+            $out['complete'] = 1;
+        }
+        return [$create, $unConfirm, $out];
+    }
+
+    public static function getShowItem($showItem, $order)
+    {
+        if ($showItem == false) {
+            return ['list' => [], 'itemStat' => []];
+        }
+        $orderSn = $order['orderSn'];
+        $list = OrderItemClass::getOrderItem($orderSn);
+        $totalPrice = 0;
+        $totalBigNum = 0;
+        $totalSmallNum = 0;
+        $kind = 0;
+        $itemStat = [];
+        if (!empty($list)) {
+            foreach ($list as $key => $val) {
+                $list[$key]['property'] = $val['rank'] . '级';
+                $price = $val['price'];
+                $totalPrice = stringUtil::calcAdd($totalPrice, $price);
+                $kind++;
+                $currentBigNum = $val['bigNum'];
+                $currentSmallNum = $val['smallNum'];
+                $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
+                $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
+            }
+            $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
+        }
+        return ['list' => $list, 'itemStat' => $itemStat];
+    }
+
+    //整合订单员工和供货商等信息 shish 2021.1.19
+    public static function groupOrder($list, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false)
+    {
+        if (empty($list)) {
+            return $list;
+        }
+
+        $customIds = array_unique(array_filter(array_column($list, 'customId')));
+        $customInfo = CustomClass::getCustomByIds($customIds);
+
+        $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
+        $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
+
+        foreach ($list as $key => $val) {
+            $adminId = $val['adminId'] ?? 0;
+            $list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
+            $customId = $val['customId'] ?? 0;
+            $list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
+            $list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
+            $list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
+            $list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
+            //显示列表页的操作按钮
+            $list[$key]['buttonList'] = self::getShowButton($showButton, $val);
+            //显示进度条
+            $list[$key]['progress'] = self::getShowProgress($showProgress, $val);
+            //显示产品
+            $showItem = self::getShowItem($showItem, $val);
+            $list[$key]['product'] = $showItem['list'];
+            $list[$key]['productStat'] = $showItem['itemStat'];
+
+            //显示重选花材按钮
+            $showResetItem = 1;
+            //配送中和已完成的不显示重选花材按钮
+            if (in_array($val['sendStatus'], [self::SEND_STATUS_SENDING, self::SEND_STATUS_COMPLETE])) {
+                $showResetItem = 0;
+            }
+            $list[$key]['showResetItem'] = $showResetItem;
+            //获取配送进展
+            $list[$key]['expressProgress'] = OrderExpressClass::getProgress($showExpress, $val);
+        }
+        return $list;
+    }
+
+    //订单的验证 shish 2021.3.2
+    public static function valid($info, $shopId)
+    {
+        if (empty($info)) {
+            util::fail('没有找到订单');
+        }
+        if (isset($info['shopId']) && $info['shopId'] == $shopId) {
+            return true;
+        }
+        util::fail('没有权限操作的订单');
+    }
+
+    //获取订单详情 shish 2021.1.21
+    public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false)
+    {
+        $info = self::getById($id);
+        if (empty($info)) {
+            util::fail('没有找到订单');
+        }
+        $respond = self::groupOrder([$info], $showButton, $showProgress, $showItem, $showExpress);
+        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]);
+            }
+        }
+    }
+
+    //本店送 shish 2021.1.24
+    public static function selfSend($info)
+    {
+        if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_PAY) {
+            util::fail('订单不是待配送状态!');
+        }
+        if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_SEND) {
+            util::fail('订单不是待配送状态');
+        }
+        $id = $info['id'];
+        self::updateById($id, [
+            'status' => self::ORDER_STATUS_SENDING,
+            'sendType' => self::SEND_TYPE_MYSELF,
+        ]);
+    }
+
+    //自取和免发货流程的处理 shish 2021.1.24
+    public static function withoutSend($order)
+    {
+        $id = $order['id'];
+        if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
+            util::fail('订单已完成');
+        }
+
+        //订单状态变更
+        self::updateById($id, ['sendType' => self::SEND_TYPE_NO, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
+        self::complete($order, self::TOTAL_FLOW);
+
+        OrderSendClass::withoutSend($order);
+
+        //待发货订单-1,完成订单+1
+        $merchantId = $order['merchantId'];
+        $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $asset->finishOrder += 1;
+        $asset->unSendOrder -= 1;
+        $asset->save();
+
+        return self::TOTAL_FLOW;
+    }
+
+    //订单完成 shish 2020.3.12
+    public static function complete($order, $currentFlow)
+    {
+        $id = $order['id'];
+        self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]);
+    }
+
 }

+ 5 - 0
biz-ghs/order/services/OrderItemService.php

@@ -5,6 +5,7 @@ namespace bizGhs\order\services;
 use bizGhs\base\services\BaseService;
 use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderItemClass;
+use bizGhs\product\classes\ProductClass;
 use common\components\util;
 use Yii;
 
@@ -23,6 +24,10 @@ class OrderItemService extends BaseService
         if ($info['sendStatus'] >= OrderClass::ORDER_STATUS_SENDING) {
             util::fail('此订单已经不能修改花材');
         }
+
+        //价格等信息
+        $product = ProductClass::computedPriceByItemInfo($product);
+
         $orderSn = $info['orderSn'];
         OrderItemClass::replace($orderSn, $product);
 

+ 10 - 9
biz-ghs/product/classes/ProductClass.php

@@ -19,9 +19,9 @@ class ProductClass extends BaseClass
     const LOCK_PRICE = 'lock_price'; //改价锁
 
     //根据itemIds获取相应的花材信息
-    public static function getProductInfoByItemIds(array $itemIds,$shopId)
+    public static function getProductInfoByItemIds(array $itemIds, $shopId)
     {
-        $where = ['itemId' => ['in', $itemIds], 'delStatus' => 0,'shopId'=>$shopId];
+        $where = ['itemId' => ['in', $itemIds], 'delStatus' => 0, 'shopId' => $shopId];
         $data = self::getAllList('*', $where);
         $data = self::groupItemBaseInfo($data);
         return $data;
@@ -143,6 +143,7 @@ class ProductClass extends BaseClass
 
 
     //加库存,允许负库存,负数数量(盘点时)
+
     /**
      * @param $productId  门店下的花材ID(xhGhsItemInfo 主键ID)
      * @param $itemNumBundle  花材数量(扎)
@@ -320,7 +321,7 @@ class ProductClass extends BaseClass
         if (!empty($productList)) {
             foreach ($productList as $product) {
                 if (isset($product['shopId']) == false || $product['shopId'] != $shopId) {
-                    util::fail('只能选择一家的商品');
+                    util::fail('只能选择一家的商品下单');
                 }
             }
             if (count($productList) != count($ids)) {
@@ -341,16 +342,16 @@ class ProductClass extends BaseClass
     //todo 库存修改 加锁
     public static function updateStockById($id, $stock, $adminId = 0)
     {
-        $key = self::LOCK_STOCK.'_'.$id;
+        $key = self::LOCK_STOCK . '_' . $id;
         $lock = util::lock($key);
-        if(!$lock){
+        if (!$lock) {
             util::fail("系统繁忙中,请稍后再试!");
         }
         $data['stock'] = $stock;
-        if($adminId){
+        if ($adminId) {
             $data['adminId'] = $adminId;
         }
-        $res =  self::updateById($id, $data);
+        $res = self::updateById($id, $data);
         util::unlock($key);
         return $res;
     }
@@ -406,12 +407,12 @@ class ProductClass extends BaseClass
     public static function changePrice($id, $shopId, $price, $priceLabel)
     {
 
-        $res =  ProductClass::updateByCondition(['id'=>$id,'shopId'=>$shopId],['price'=>$price,'priceLabel'=>$priceLabel]);
+        $res = ProductClass::updateByCondition(['id' => $id, 'shopId' => $shopId], ['price' => $price, 'priceLabel' => $priceLabel]);
         return $res;
     }
 
     //下单时计算商品的价格  linqh 2021.1.28
-	//itemInfo : [{"classId":5,"productId":3,"bigNum":1,"smallNum":2},{"classId":5,"productId":4,"bigNum":1,"smallNum":5}]
+    //itemInfo : [{"classId":5,"productId":3,"bigNum":1,"smallNum":2},{"classId":5,"productId":4,"bigNum":1,"smallNum":5}]
     //返回 [{"productId":3,"price":2.1}]
     public static function computedPriceByItemInfo(array $itemInfo)
     {

+ 2 - 1
sql.sql

@@ -1357,4 +1357,5 @@ ALTER TABLE `xhGhsOrderItem` ADD `rank` CHAR(5) NOT NULL DEFAULT 'A' COMMENT '
 ALTER TABLE `xhGhsOrderItem` ADD `name` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '花材名称' AFTER `id`;
 ALTER TABLE `xhGhsOrderItem` ADD cover VARCHAR(500) NOT NULL DEFAULT '' COMMENT '花材封面' AFTER `name`;
 ALTER TABLE xhGhsOrderItem ADD INDEX orderSn(`orderSn`);
-
+ALTER TABLE xhGhsOrder CHANGE `num` bigNum SMALLINT NOT NULL DEFAULT 0 COMMENT '大单位数量';
+ALTER TABLE xhGhsOrder ADD hasItem TINYINT NOT NULL DEFAULT 1 COMMENT '1订单有花材 2没有花材' AFTER `smallNum`;