shish 5 年 前
コミット
c890221dd5

+ 4 - 3
app-ghs/controllers/OrderSendController.php

@@ -17,7 +17,7 @@ class OrderSendController extends BaseController
     {
         $id = Yii::$app->request->get('id', 0);
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         //发货列表
         $list = OrderSendService::sendList($order);
         util::success($list);
@@ -29,8 +29,9 @@ class OrderSendController extends BaseController
         $post = Yii::$app->request->post();
         $id = isset($post['id']) ? $post['id'] : 0;
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         $post['merchantId'] = $this->sjId;
+        $post['orderSn'] = $order['orderSn'];
         OrderSendService::deliver($post);
     }
 
@@ -41,7 +42,7 @@ class OrderSendController extends BaseController
         $id = isset($post['id']) ? $post['id'] : 0;
         $option = isset($post['option']) ? $post['option'] : 0;
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         OrderSendService::reach($order, ['option' => $option]);
     }
 

+ 1 - 1
app-hd/controllers/GoodsController.php

@@ -213,7 +213,7 @@ class GoodsController extends BaseController
             util::fail("订单不存在");
         }
         $order = OrderService::getOrderBySn($orderSn);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         $save = GoodsService::saveItemGroup($order,$itemInfo,$goodsName,$classId,$this->adminId);
         if($save){
             util::complete();

+ 7 - 7
app-hd/controllers/OrderController.php

@@ -497,7 +497,7 @@ class OrderController extends BaseController
         $post = Yii::$app->request->post();
         $id = $post['id'];
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         if ($order['grade'] > 0) {
             util::fail('您已经评过了');
         }
@@ -517,7 +517,7 @@ class OrderController extends BaseController
         if (!empty($orderSn)) {
             $detail = OrderService::getOrderBySn($orderSn);
         }
-        OrderService::valid($detail, $this->sjId);
+        OrderService::valid($detail, $this->shopId);
         util::success($detail);
     }
 
@@ -555,7 +555,7 @@ class OrderController extends BaseController
         $post = Yii::$app->request->post();
         $id = isset($post['id']) ? $post['id'] : 0;
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
         $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
         OrderService::classify($id, $categoryId, $usageId);
@@ -569,7 +569,7 @@ class OrderController extends BaseController
         $id = isset($post['id']) ? $post['id'] : 0;
         unset($post['id']);
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         OrderService::updateSheet($order, $post);
         util::complete('提交成功');
     }
@@ -626,7 +626,7 @@ class OrderController extends BaseController
     {
         $id = Yii::$app->request->get('id');
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         //配送流程变更
         $currentFlow = OrderSendClass::withoutSend($order);
         util::success(['currentFlow' => $currentFlow]);
@@ -638,7 +638,7 @@ class OrderController extends BaseController
         $id = Yii::$app->request->get('id');
         $price = Yii::$app->request->get('price', 1);
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         if (isset($order['modPrice']) && $order['modPrice'] == 0) {
             util::fail('已发起支付,不能修改价格');
         }
@@ -651,7 +651,7 @@ class OrderController extends BaseController
     {
         $id = Yii::$app->request->get('id', 0);
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
         $reachPeriodId = $order['reachPeriod'];
         $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];

+ 78 - 76
app-hd/controllers/OrderSendController.php

@@ -9,80 +9,82 @@ use common\components\util;
 
 class OrderSendController extends BaseController
 {
-	
-	//发货 ssh 2019.12.16
-	public function actionDetail()
-	{
-		$id = Yii::$app->request->get('id', 0);
-		$order = OrderService::getById($id);
-		OrderService::valid($order, $this->sjId);
-		$list = OrderSendService::sendList($order);
-		util::success($list);
-	}
-	
-	//制单 免填单 填单 ssh 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->sjId);
-		OrderSendService::printOrder(['id' => $id, 'option' => $option]);
-	}
-	
-	//发货 ssh 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->sjId);
-		$post['merchantId'] = $this->sjId;
-		OrderSendService::deliver($post);
-	}
-	
-	//送达 ssh 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->sjId);
-		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);
-	}
-	
+
+    //发货 ssh 2019.12.16
+    public function actionDetail()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $order = OrderService::getById($id);
+        OrderService::valid($order, $this->shopId);
+        $list = OrderSendService::sendList($order);
+        util::success($list);
+    }
+
+    //制单 免填单 填单 ssh 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->shopId);
+        $orderSn = $order['orderSn'];
+        OrderSendService::printOrder(['id' => $id, 'option' => $option, 'orderSn' => $orderSn]);
+    }
+
+    //发货 ssh 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->shopId);
+        $post['merchantId'] = $this->sjId;
+        $post['orderSn'] = $order['orderSn'];
+        OrderSendService::deliver($post);
+    }
+
+    //送达 ssh 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->shopId);
+        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);
+    }
+
 }

+ 5 - 5
app-mall/controllers/OrderController.php

@@ -52,7 +52,7 @@ class OrderController extends BaseController
         $transaction = $connection->beginTransaction();
         try {
 
-            $post['userId'] = $this->userId;
+            $post['customId'] = $this->customId;
             $user = $this->user;
             $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
             $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
@@ -279,7 +279,7 @@ class OrderController extends BaseController
         //兼容旧系统sourceType=3表示朋友圈来源
         $fromType = $sourceType == 3 ? 2 : 0;
         $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
-        $post['userId'] = $this->userId;
+        $post['customId'] = $this->customId;
         $user = $this->user;
         $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
         $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
@@ -431,7 +431,7 @@ class OrderController extends BaseController
     //订单列表 ssh 2019.12.12
     public function actionList()
     {
-        $where = ['userId' => $this->userId];
+        $where = ['customId' => $this->customId];
         $list = OrderService::getOrderList($where);
         util::success($list);
     }
@@ -442,7 +442,7 @@ class OrderController extends BaseController
         $post = Yii::$app->request->post();
         $id = $post['id'];
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
+        OrderService::valid($order, $this->shopId);
         if ($order['grade'] > 0) {
             util::fail('您已经评过了');
         }
@@ -462,7 +462,7 @@ class OrderController extends BaseController
         if (!empty($orderSn)) {
             $detail = OrderService::getOrderBySn($orderSn);
         }
-        OrderService::valid($detail, $this->sjId);
+        OrderService::valid($detail, $this->shopId);
         util::success($detail);
     }
 

+ 245 - 247
app-mall/controllers/PayController.php

@@ -29,256 +29,254 @@ use common\components\dict;
 class PayController extends BaseController
 {
 
-	public $guestAccess = ['get-params'];
+    public $guestAccess = ['get-params'];
 
-	
 
-	//创建订单 ssh 2019.12.3
-	public function actionCreateOrder()
-	{
-		$post = Yii::$app->request->post();
-		//dump($post);die;
-		$userId = $this->userId;
-		$post['userId'] = $userId;
-		$post['payWay'] = $this->isWx == true ? 0 : 1;
-		$lat2 = $post['receiveLat'];//收货人纬度
-		$lng2 = $post['long'];//收货人经度
-		$lat1 = $this->sj['lat'];//花店纬度
-		$lng1 = $this->sj['long'];//花店经度
-		$calcDistance = util::getDistance($lat1, $lng1, $lat2, $lng2);//防止别人改动,PHP计算的距离会比腾讯js算的小,但能保证有一定准确性
-		$post['sendDistance'] = $post['sendDistance'] >= $calcDistance ? $post['sendDistance'] : $calcDistance;//二地距离
-		$sendDistance = $post['sendDistance'];
-		$freight = dict::getConfig('freight');
-		$firstDistance = $freight['firstDistance'];
-		$firstPrice = $freight['firstPrice'];
-		$nextDistance = $freight['nextDistance'];
-		$nextPrice = $freight['nextPrice'];
-		if ($sendDistance <= $firstDistance && $post['isCharge'] == 1) {
-			$post['sendCost'] = $firstPrice;
-		} else if ($post['isCharge'] == 1) {
-			$subDistance = $sendDistance - $firstDistance;
-			$addPrice = intval($subDistance / $nextDistance) * $nextPrice;
-			$post['sendCost'] = $firstPrice + $addPrice;
-		}
-		if (empty($this->sjExtend['payment'])) {
-			util::fail('支付功能未开通,暂时无法购买哦~');
-		}
-		$couponAmount = 0;
-		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;//代金劵
-		if (!empty($couponId)) {
-			$coupon = xhCouponService::getById($couponId);
-			$couponUserId = $coupon['userId'];
-			if ($couponUserId != $userId) {
-				util::fail('不是你的代金劵');
-			}
-			if ($coupon['useStatus'] == 1 || $coupon['deadline'] < time()) {
-				util::fail('代金劵已经失效了');
-			}
-			$couponAmount = $coupon['amount'];
-		}
-		//不要将代金劵保存到订单表,付款成功后再保存进去!!!
-		unset($post['couponId']);
-		$post['merchantId'] = $this->sjId;
-		//店铺id
-		$post['shopId'] = $this->sj['defaultShopId'];
-		$order = xhOrderService::add($post);//创建订单
-		if ($order == false) {
-			util::fail('创建订单失败');
-		}
-		$orderId = $order['id'];
-		$oData = [];
-		$goodsInfo = $post['goodsInfo'];
-		$totalFee = 0;//计算总价格
-		$goodsIdList = [];
-		$multiPriceIdList = [];
-		$orderName = '';
-		$goodsNum = 0;
-		foreach ($goodsInfo as $key => $val) {
-			$multiPriceId = 0;//多种价格表Id
-			$goodsId = $val['goodsId'];
-			$num = $val['num'];
-			$goodsNum += $num;
-			$goods = xhGoodsService::getById($goodsId);
-			if (empty($orderName)) {
-				$orderName = $goods['goodsName'];
-			}
-			$price = $goods['price'];
-			if ($val['multiPriceId'] != 0 && $goods['multiPrice'] != '') {
-				$pos = strpos($goods['multiPrice'], $val['multiPriceId']);
-				if ($pos === false) {
-					util::fail('订单的商品不存在');
-				}
-				$goodPrice = xhGoodsPriceService::getById($val['multiPriceId']);
-				
-				//$price = $goodPrice['price'];
-				$price = xhGoodsSettingService::changePrice($goods, $goodPrice['price']);//统一对商品进行价格等方面设置
-				//多种价格规格 替换 默认(单价格)
-				$goods['goodsName'] = $goodPrice['title'];
-				//$goods['cover'] = $goodPrice['picture'];//后台图片上传功能未开发,暂时使用默认商品图片
-				$multiPriceId = $val['multiPriceId'];
-			}
-			$totalFee += $price * $num;
-			$goodsIdList[] = $goodsId;
-			$multiPriceIdList[] = $multiPriceId;
-			$data = [
-				'orderId' => $orderId,
-				'goodsId' => $goodsId,
-				'userId' => $userId,
-				'merchantId' => $this->sjId,
-				'title' => $goods['goodsName'],
-				'cover' => $goods['cover'],
-				'unitPrice' => $price,
-				'num' => $num,
-				'multiPriceId' => $multiPriceId,
-				'createTime' => date("Y-m-d H:i:s"),
-			];
-			xhOrderGoodsService::add($data);//创建订单商品列表
-		}
-		$sendCost = $post['sendCost'];//运费
-		$oData['goodsNum'] = $goodsNum;//订单的商品数量类型,单个还是多个的
-		$oData['prePrice'] = $totalFee + $sendCost;
-		$oData['orderName'] = $goodsNum > 1 ? $orderName . '等' . $goodsNum . '件商品' : $orderName;
-		if (isset($post['sourceType']) && $post['sourceType'] == 'cart') {
-			if (!empty($goodsIdList)) {
-				foreach ($goodsIdList as $key => $goodsId) {
-					xhCartService::delByIds($userId, $goodsId, $multiPriceIdList[$key]);//删除购物车($userId, $goodsId, $goodsPriceId, $cartId)
-				}
-			}
-		}
-		$userAsset = xhUserAssetService::getByUserId($userId);
-		$level = $userAsset['member'];
-		if ($level > 0) {
-			$gradeList = xhMerchantExtendService::getGradeList($this->sjExtend);
-			$discount = $gradeList[$level]['discount'];
-			$discount = strlen($discount) == 1 ? $discount * 10 : $discount;
-			$totalFee = number_format($discount * $totalFee / 100, 2);
-		}
-		$oData['actPrice'] = $totalFee + $sendCost - $couponAmount;
-		xhOrderService::updateById($orderId, $oData);
-		util::success(['orderId' => $orderId, 'couponId' => $couponId],'订单创建成功');
-	}
+    //创建订单 ssh 2019.12.3
+    public function actionCreateOrder()
+    {
+        $post = Yii::$app->request->post();
+        $customId = $this->customId;
+        $post['customId'] = $customId;
+        $post['payWay'] = $this->isWx == true ? 0 : 1;
+        $lat2 = $post['receiveLat'];//收货人纬度
+        $lng2 = $post['long'];//收货人经度
+        $lat1 = $this->sj['lat'];//花店纬度
+        $lng1 = $this->sj['long'];//花店经度
+        $calcDistance = util::getDistance($lat1, $lng1, $lat2, $lng2);//防止别人改动,PHP计算的距离会比腾讯js算的小,但能保证有一定准确性
+        $post['sendDistance'] = $post['sendDistance'] >= $calcDistance ? $post['sendDistance'] : $calcDistance;//二地距离
+        $sendDistance = $post['sendDistance'];
+        $freight = dict::getConfig('freight');
+        $firstDistance = $freight['firstDistance'];
+        $firstPrice = $freight['firstPrice'];
+        $nextDistance = $freight['nextDistance'];
+        $nextPrice = $freight['nextPrice'];
+        if ($sendDistance <= $firstDistance && $post['isCharge'] == 1) {
+            $post['sendCost'] = $firstPrice;
+        } else if ($post['isCharge'] == 1) {
+            $subDistance = $sendDistance - $firstDistance;
+            $addPrice = intval($subDistance / $nextDistance) * $nextPrice;
+            $post['sendCost'] = $firstPrice + $addPrice;
+        }
+        if (empty($this->sjExtend['payment'])) {
+            util::fail('支付功能未开通,暂时无法购买哦~');
+        }
+        $couponAmount = 0;
+        $couponId = isset($post['couponId']) ? $post['couponId'] : 0;//代金劵
+        if (!empty($couponId)) {
+            $coupon = xhCouponService::getById($couponId);
+            $couponUserId = $coupon['userId'];
+            if ($couponUserId != $customId) {
+                util::fail('不是你的代金劵');
+            }
+            if ($coupon['useStatus'] == 1 || $coupon['deadline'] < time()) {
+                util::fail('代金劵已经失效了');
+            }
+            $couponAmount = $coupon['amount'];
+        }
+        //不要将代金劵保存到订单表,付款成功后再保存进去!!!
+        unset($post['couponId']);
+        $post['merchantId'] = $this->sjId;
+        //店铺id
+        $post['shopId'] = $this->sj['defaultShopId'];
+        $order = xhOrderService::add($post);//创建订单
+        if ($order == false) {
+            util::fail('创建订单失败');
+        }
+        $orderId = $order['id'];
+        $oData = [];
+        $goodsInfo = $post['goodsInfo'];
+        $totalFee = 0;//计算总价格
+        $goodsIdList = [];
+        $multiPriceIdList = [];
+        $orderName = '';
+        $goodsNum = 0;
+        foreach ($goodsInfo as $key => $val) {
+            $multiPriceId = 0;//多种价格表Id
+            $goodsId = $val['goodsId'];
+            $num = $val['num'];
+            $goodsNum += $num;
+            $goods = xhGoodsService::getById($goodsId);
+            if (empty($orderName)) {
+                $orderName = $goods['goodsName'];
+            }
+            $price = $goods['price'];
+            if ($val['multiPriceId'] != 0 && $goods['multiPrice'] != '') {
+                $pos = strpos($goods['multiPrice'], $val['multiPriceId']);
+                if ($pos === false) {
+                    util::fail('订单的商品不存在');
+                }
+                $goodPrice = xhGoodsPriceService::getById($val['multiPriceId']);
 
-	public function actionParams()
-	{
-		ini_set('date.timezone', 'Asia/Shanghai');
-		$post = Yii::$app->request->post();
-		$payWay = isset($post['payWay']) ? $post['payWay'] : '';
-		$shopId = isset($post['shopId']) ? $post['shopId'] : 0;
-		//来源 0自建商城 1门店 2微信朋友圈 3淘宝
-		$sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
-		$shopInfo = xhShop::find()->where(['id' => $shopId])->one();
-		if (empty($shopInfo) || $shopInfo->sjId != $this->sjId) {
-			util::fail('门店无效');
-		}
-		
-		unset($post['payWay']);
-		$post['userId'] = $this->userId;
-		$prePrice = round($post['prePrice'], 2);//四舍五入,保留二位小数
-		
-		$userAsset = xhUserAssetService::getByUserId($this->userId);
-		$level = isset($userAsset['member']) ? $userAsset['member'] : 0;
-		$sjExtend = xhMerchantExtendService::getByMerchantId($this->sjId);
-		$memberIntegral = xhMerchantExtendService::getGradeList($sjExtend, 'desc');
-		Yii::info(json_encode($sjExtend));
-		Yii::info(json_encode($memberIntegral));
-		//$discount = isset($memberIntegral[$level]['discount']) ? $memberIntegral[$level]['discount'] : $memberIntegral[$level]['discount'];
-		$discount = 0;
-		$actPrice = $prePrice;
-		$couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
-		Yii::info($this->userId . ' ' . $level . ' ' . $discount);
-		//没有优惠券才能使用会员折扣 ssh 2019.8.30
-		if (!empty($discount) && $prePrice >= 1 && empty($couponId)) {
-			$currentPrice = ($prePrice * $discount) / 100;
-			$actPrice = substr(sprintf("%.3f", $currentPrice), 0, -2);
-		}
-		//没有优惠卷,微信朋友圈付款才给随机优惠金额 ssh 2019.9.12
-		if ($sourceType == 2 && empty($couponId)) {
-			$discountAmount = OrderService::getRandDiscount($actPrice);
-			$discountAmount = 0.01;
-			$actPrice = stringUtil::calcSub($actPrice, $discountAmount);
-			$post['discountType'] = 2;//优惠类型是:付款随机优惠
-			$post['discountAmount'] = $discountAmount;
-		}
-		$post['actPrice'] = $actPrice;
-		$post['payStyle'] = 0;
-		$post['merchantId'] = $this->sjId;
-		$now = time();
-		$expireTime = $now + 1800;//订单30分钟后过期
-		$post['createTime'] = date("Y-m-d H:i:s", $now);
-		$post['deadline'] = $expireTime;
-		if (!empty($couponId)) {
-			$time = time();
-			$coupon = CouponService::getById($couponId);
-			if ($coupon['deadline'] <= $time) {
-				util::fail('优惠卷已经过期');
-			}
-			if ($coupon['status'] == 1) {
-				util::fail('优惠卷已经使用');
-			}
-			if ($coupon['meetAmount'] > $post['prePrice']) {
-				util::fail('消费金额不足' . $coupon['meetAmount'] . '元');
-			}
-			$post['actPrice'] = stringUtil::calcSub($post['prePrice'], $coupon['amount']);//浮点相减
-			$post['discountAmount'] = $coupon['amount'];
-			$post['discountType'] = 0;
-		}
-		if ($post['actPrice'] <= 0) {
-			util::fail('消费金额太低');
-		}
-		if ($this->isWx) {
-			$post['modPriceStatus'] = 1;//微信已经提交不能再修改价格
-		}
-		$post['sourceType'] = $sourceType;
-		$post['id'] = stringUtil::generateOrderNo($this->sjId, $this->userId);
-		$payment = xhOrderService::add($post);
-		$orderId = $payment['id'];
+                //$price = $goodPrice['price'];
+                $price = xhGoodsSettingService::changePrice($goods, $goodPrice['price']);//统一对商品进行价格等方面设置
+                //多种价格规格 替换 默认(单价格)
+                $goods['goodsName'] = $goodPrice['title'];
+                //$goods['cover'] = $goodPrice['picture'];//后台图片上传功能未开发,暂时使用默认商品图片
+                $multiPriceId = $val['multiPriceId'];
+            }
+            $totalFee += $price * $num;
+            $goodsIdList[] = $goodsId;
+            $multiPriceIdList[] = $multiPriceId;
+            $data = [
+                'orderId' => $orderId,
+                'goodsId' => $goodsId,
+                'customId' => $customId,
+                'merchantId' => $this->sjId,
+                'title' => $goods['goodsName'],
+                'cover' => $goods['cover'],
+                'unitPrice' => $price,
+                'num' => $num,
+                'multiPriceId' => $multiPriceId,
+                'createTime' => date("Y-m-d H:i:s"),
+            ];
+            xhOrderGoodsService::add($data);//创建订单商品列表
+        }
+        $sendCost = $post['sendCost'];//运费
+        $oData['goodsNum'] = $goodsNum;//订单的商品数量类型,单个还是多个的
+        $oData['prePrice'] = $totalFee + $sendCost;
+        $oData['orderName'] = $goodsNum > 1 ? $orderName . '等' . $goodsNum . '件商品' : $orderName;
+        if (isset($post['sourceType']) && $post['sourceType'] == 'cart') {
+            if (!empty($goodsIdList)) {
+                foreach ($goodsIdList as $key => $goodsId) {
+                    xhCartService::delByIds($customId, $goodsId, $multiPriceIdList[$key]);//删除购物车($userId, $goodsId, $goodsPriceId, $cartId)
+                }
+            }
+        }
+        $userAsset = xhUserAssetService::getByUserId($customId);
+        $level = $userAsset['member'];
+        if ($level > 0) {
+            $gradeList = xhMerchantExtendService::getGradeList($this->sjExtend);
+            $discount = $gradeList[$level]['discount'];
+            $discount = strlen($discount) == 1 ? $discount * 10 : $discount;
+            $totalFee = number_format($discount * $totalFee / 100, 2);
+        }
+        $oData['actPrice'] = $totalFee + $sendCost - $couponAmount;
+        xhOrderService::updateById($orderId, $oData);
+        util::success(['orderId' => $orderId, 'couponId' => $couponId], '订单创建成功');
+    }
 
-		if ($payWay == 'balance') {//余额支付
-			util::success(['orderId' => $orderId]);
-		}
-		$name = '购买商品';
-		$totalFee = $post['actPrice'];
-		if ($this->isWx) {
-			$userId = $post['userId'];
-			$user = xhUserService::getById($userId);
-			if ($user['merchantId'] != $this->sjId) {
-				util::fail('非法用户');
-			}
-			$openId = $user['openId'];
-			$typeList = dict::getConfig('capitalType');
-			$capitalType = $typeList['xhOrder']['id'];
-			$attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
-			$weixin = Yii::getAlias("@vendor/weixin");
-			require_once($weixin . '/lib/WxPay.Api.php');
-			require_once($weixin . '/example/WxPay.JsApiPay.php');
-			$input = new \WxPayUnifiedOrder();
-			$input->SetBody($name);
-			$input->SetOut_trade_no($orderId);
-			$input->SetTotal_fee($totalFee * 100);
-			$input->SetTime_start(date("YmdHis", $now));
-			$input->SetAttach($attach);
-			$input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
-			$input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
-			$input->SetTrade_type("JSAPI");
-			
-			
-			//服务商 代设置微信支付,要添加的参数设置
-			if ($this->sjExtend['wxPayApply'] == 1) {
-				//$input->SetOpenid($openId);
-				$input->SetSub_openid($openId);
-				//自设置 微信支付
-			} else {
-				$input->SetOpenid($openId);
-			}
-			
-			$wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->sjExtend);
-			$tools = new \JsApiPay();
-			$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->sjExtend);
-			$newParams = json_decode($jsApiParameters, true);
-			$newParams['orderId'] = $orderId;
-			util::success($newParams);
-		}
-		util::success(['orderId' => $orderId]);
-	}
+    public function actionParams()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $post = Yii::$app->request->post();
+        $payWay = isset($post['payWay']) ? $post['payWay'] : '';
+        $shopId = isset($post['shopId']) ? $post['shopId'] : 0;
+        //来源 0自建商城 1门店 2微信朋友圈 3淘宝
+        $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
+        $shopInfo = xhShop::find()->where(['id' => $shopId])->one();
+        if (empty($shopInfo) || $shopInfo->sjId != $this->sjId) {
+            util::fail('门店无效');
+        }
+
+        unset($post['payWay']);
+        $post['userId'] = $this->userId;
+        $prePrice = round($post['prePrice'], 2);//四舍五入,保留二位小数
+
+        $userAsset = xhUserAssetService::getByUserId($this->userId);
+        $level = isset($userAsset['member']) ? $userAsset['member'] : 0;
+        $sjExtend = xhMerchantExtendService::getByMerchantId($this->sjId);
+        $memberIntegral = xhMerchantExtendService::getGradeList($sjExtend, 'desc');
+        Yii::info(json_encode($sjExtend));
+        Yii::info(json_encode($memberIntegral));
+        //$discount = isset($memberIntegral[$level]['discount']) ? $memberIntegral[$level]['discount'] : $memberIntegral[$level]['discount'];
+        $discount = 0;
+        $actPrice = $prePrice;
+        $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
+        Yii::info($this->userId . ' ' . $level . ' ' . $discount);
+        //没有优惠券才能使用会员折扣 ssh 2019.8.30
+        if (!empty($discount) && $prePrice >= 1 && empty($couponId)) {
+            $currentPrice = ($prePrice * $discount) / 100;
+            $actPrice = substr(sprintf("%.3f", $currentPrice), 0, -2);
+        }
+        //没有优惠卷,微信朋友圈付款才给随机优惠金额 ssh 2019.9.12
+        if ($sourceType == 2 && empty($couponId)) {
+            $discountAmount = OrderService::getRandDiscount($actPrice);
+            $discountAmount = 0.01;
+            $actPrice = stringUtil::calcSub($actPrice, $discountAmount);
+            $post['discountType'] = 2;//优惠类型是:付款随机优惠
+            $post['discountAmount'] = $discountAmount;
+        }
+        $post['actPrice'] = $actPrice;
+        $post['payStyle'] = 0;
+        $post['merchantId'] = $this->sjId;
+        $now = time();
+        $expireTime = $now + 1800;//订单30分钟后过期
+        $post['createTime'] = date("Y-m-d H:i:s", $now);
+        $post['deadline'] = $expireTime;
+        if (!empty($couponId)) {
+            $time = time();
+            $coupon = CouponService::getById($couponId);
+            if ($coupon['deadline'] <= $time) {
+                util::fail('优惠卷已经过期');
+            }
+            if ($coupon['status'] == 1) {
+                util::fail('优惠卷已经使用');
+            }
+            if ($coupon['meetAmount'] > $post['prePrice']) {
+                util::fail('消费金额不足' . $coupon['meetAmount'] . '元');
+            }
+            $post['actPrice'] = stringUtil::calcSub($post['prePrice'], $coupon['amount']);//浮点相减
+            $post['discountAmount'] = $coupon['amount'];
+            $post['discountType'] = 0;
+        }
+        if ($post['actPrice'] <= 0) {
+            util::fail('消费金额太低');
+        }
+        if ($this->isWx) {
+            $post['modPriceStatus'] = 1;//微信已经提交不能再修改价格
+        }
+        $post['sourceType'] = $sourceType;
+        $post['id'] = stringUtil::generateOrderNo($this->sjId, $this->userId);
+        $payment = xhOrderService::add($post);
+        $orderId = $payment['id'];
+
+        if ($payWay == 'balance') {//余额支付
+            util::success(['orderId' => $orderId]);
+        }
+        $name = '购买商品';
+        $totalFee = $post['actPrice'];
+        if ($this->isWx) {
+            $userId = $post['userId'];
+            $user = xhUserService::getById($userId);
+            if ($user['merchantId'] != $this->sjId) {
+                util::fail('非法用户');
+            }
+            $openId = $user['openId'];
+            $typeList = dict::getConfig('capitalType');
+            $capitalType = $typeList['xhOrder']['id'];
+            $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
+            $weixin = Yii::getAlias("@vendor/weixin");
+            require_once($weixin . '/lib/WxPay.Api.php');
+            require_once($weixin . '/example/WxPay.JsApiPay.php');
+            $input = new \WxPayUnifiedOrder();
+            $input->SetBody($name);
+            $input->SetOut_trade_no($orderId);
+            $input->SetTotal_fee($totalFee * 100);
+            $input->SetTime_start(date("YmdHis", $now));
+            $input->SetAttach($attach);
+            $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
+            $input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
+            $input->SetTrade_type("JSAPI");
+
+
+            //服务商 代设置微信支付,要添加的参数设置
+            if ($this->sjExtend['wxPayApply'] == 1) {
+                //$input->SetOpenid($openId);
+                $input->SetSub_openid($openId);
+                //自设置 微信支付
+            } else {
+                $input->SetOpenid($openId);
+            }
+
+            $wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->sjExtend);
+            $tools = new \JsApiPay();
+            $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->sjExtend);
+            $newParams = json_decode($jsApiParameters, true);
+            $newParams['orderId'] = $orderId;
+            util::success($newParams);
+        }
+        util::success(['orderId' => $orderId]);
+    }
 
 }

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

@@ -533,7 +533,7 @@ class OrderClass extends BaseClass
 
         //增加已下单流程
         $time = date("Y-m-d H:i:s");
-        $placeData = ['payTime' => $time, 'orderSn' => $orderSn];
+        $placeData = ['payTime' => $time, 'orderSn' => $orderSn, 'orderId' => $orderId];
         OrderSendClass::placeOrder($placeData);
     }
 

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

@@ -45,7 +45,7 @@ class OrderSendService extends BaseService
 
         //进入发货流程
         $deliverId = $actionRelation['deliver'];
-        $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId];
+        $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId, 'orderSn' => $orderSn];
         OrderSendClass::add($data);
         $actionList = OrderSendClass::ACTION_LIST;
         $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
@@ -106,7 +106,7 @@ class OrderSendService extends BaseService
 
         //进入送达流程
         $reachId = $actionRelation['reach'];
-        $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId];
+        $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId, 'orderSn' => $orderSn];
         OrderSendClass::add($data);
         $actionList = OrderSendClass::ACTION_LIST;
         $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';

+ 2 - 2
biz-ghs/order/services/OrderService.php

@@ -114,13 +114,13 @@ class OrderService extends BaseService
     }
 
     //商家验证是否有效 ssh 2019.12.15
-    public static function valid($order, $merchantId)
+    public static function valid($order, $shopId)
     {
         OrderClass::setExpire($order);
         if (empty($order)) {
             util::fail('订单无效');
         }
-        if ($order['merchantId'] != $merchantId) {
+        if ($order['shopId'] != $shopId) {
             util::fail('不是您的订单');
         }
     }

+ 2 - 1
biz-hd/order/classes/OrderClass.php

@@ -191,10 +191,11 @@ class OrderClass extends BaseClass
     public static function payAfter($order, $updateData)
     {
         $orderId = $order['id'];
+        $orderSn = $order['orderSn'];
         $now = time();
         self::updateById($orderId, $updateData);
         //发货流程的完成下单
-        OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now]);
+        OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now, 'orderSn' => $orderSn]);
 
         //增加订单数
         $shopId = $order['shopId'];

+ 0 - 6
biz-hd/order/classes/OrderSendClass.php

@@ -3,17 +3,11 @@
 namespace bizHd\order\classes;
 
 use biz\shop\models\Shop;
-use biz\sj\classes\MerchantAssetClass;
 use biz\sj\classes\MerchantClass;
 use bizHd\message\classes\InformAdminClass;
 use bizHd\message\classes\InformUserClass;
-use bizHd\message\services\InformAdminService;
 use bizHd\user\classes\UserClass;
-use common\components\stringUtil;
 use common\components\util;
-use common\services\xhOrderDayNumService;
-use common\services\xhOrderMonthNumService;
-use Yii;
 use bizHd\base\classes\BaseClass;
 
 class OrderSendClass extends BaseClass

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

@@ -15,170 +15,170 @@ use linslin\yii2\curl;
 
 class OrderSendService extends BaseService
 {
-	
-	public static $baseFile = '\bizHd\order\classes\OrderSendClass';
-	
-	//制单 ssh 2019.12.17
-	public static function printOrder($data)
-	{
-		$id = $data['id'];
-		$orderSn = $data['orderSn'];
-		$option = $data['option'];
-		$actionIdList = OrderSendClass::$actionId;
-		$printOrderId = $actionIdList['printOrder'];
-		$currentId = OrderSendClass::toDoActionId($orderSn);
-		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]);
-	}
-	
-	//发货 ssh 2019.12.17
-	public static function deliver($data)
-	{
-		$id = $data['id'];
-		$orderSn = $data['orderSn'];
-		$option = $data['option'];
-		$actionIdList = OrderSendClass::$actionId;
-		$deliverId = $actionIdList['deliver'];
-		$currentId = OrderSendClass::toDoActionId($orderSn);
-		if ($deliverId != $currentId) {
-			util::fail('当前流程无法操作');
-		}
-		$time = time();
-		
-		$sendType = isset($data['sendType']) ? $data['sendType'] : OrderClass::SEND_TYPE_UNKNOWN;
-		
-		$sendInfo = [];
-		if ($sendType == OrderClass::SEND_TYPE_THIRD) {
-			
-			util::fail('即将开通...');
-			
-			$side = $data['expressId'];
-			$sendTime = date("Y-m-d") . ' ' . $data['sendTime'];
-			if (strtotime($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]);
-	}
-	
-	//送达 ssh 2019.12.17
-	public static function reach($order, $data)
-	{
-		$orderSn = $data['orderSn'];
-		$actionIdList = OrderSendClass::$actionId;
-		$reachId = $actionIdList['reach'];
-		$currentId = OrderSendClass::toDoActionId($orderSn);
-		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();
-	}
-	
-	//发货详情 ssh 2019.12.15
-	public static function sendList($order)
-	{
-		$orderId = $order['id'];
-		$list = OrderSendClass::getAllByCondition(['orderId' => $orderId], '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'],
-						'address' => $order['address'],
-						'floor' => $order['floor'],
-						'fullAddress' => $order['fullAddress'],
-					];
-				}
-			}
-			if ($actionId == $idList['deliver']) {
-				$list[$key]['sendInfo'] = $order['sendType'] == OrderClass::SEND_TYPE_THIRD ? 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;
-	}
-	
+
+    public static $baseFile = '\bizHd\order\classes\OrderSendClass';
+
+    //制单 ssh 2019.12.17
+    public static function printOrder($data)
+    {
+        $id = $data['id'];
+        $orderSn = $data['orderSn'];
+        $option = $data['option'];
+        $actionIdList = OrderSendClass::$actionId;
+        $printOrderId = $actionIdList['printOrder'];
+        $currentId = OrderSendClass::toDoActionId($orderSn);
+        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, 'orderSn' => $orderSn];
+        OrderSendClass::add($data);
+        $actionList = OrderSendClass::$action;
+        $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
+        util::success(['nextAction' => $data]);
+    }
+
+    //发货 ssh 2019.12.17
+    public static function deliver($data)
+    {
+        $id = $data['id'];
+        $orderSn = $data['orderSn'];
+        $option = $data['option'];
+        $actionIdList = OrderSendClass::$actionId;
+        $deliverId = $actionIdList['deliver'];
+        $currentId = OrderSendClass::toDoActionId($orderSn);
+        if ($deliverId != $currentId) {
+            util::fail('当前流程无法操作');
+        }
+        $time = time();
+
+        $sendType = isset($data['sendType']) ? $data['sendType'] : OrderClass::SEND_TYPE_UNKNOWN;
+
+        $sendInfo = [];
+        if ($sendType == OrderClass::SEND_TYPE_THIRD) {
+
+            util::fail('即将开通...');
+
+            $side = $data['expressId'];
+            $sendTime = date("Y-m-d") . ' ' . $data['sendTime'];
+            if (strtotime($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, 'orderSn' => $orderSn];
+        OrderSendClass::add($data);
+        $actionList = OrderSendClass::$action;
+        $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';
+        util::success(['nextAction' => $data, 'sendInfo' => $sendInfo]);
+    }
+
+    //送达 ssh 2019.12.17
+    public static function reach($order, $data)
+    {
+        $orderSn = $data['orderSn'];
+        $actionIdList = OrderSendClass::$actionId;
+        $reachId = $actionIdList['reach'];
+        $currentId = OrderSendClass::toDoActionId($orderSn);
+        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();
+    }
+
+    //发货详情 ssh 2019.12.15
+    public static function sendList($order)
+    {
+        $orderId = $order['id'];
+        $list = OrderSendClass::getAllByCondition(['orderId' => $orderId], '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'],
+                        'address' => $order['address'],
+                        'floor' => $order['floor'],
+                        'fullAddress' => $order['fullAddress'],
+                    ];
+                }
+            }
+            if ($actionId == $idList['deliver']) {
+                $list[$key]['sendInfo'] = $order['sendType'] == OrderClass::SEND_TYPE_THIRD ? 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;
+    }
+
 }

+ 210 - 210
biz-hd/order/services/OrderService.php

@@ -21,214 +21,214 @@ use linslin\yii2\curl;
 
 class OrderService extends BaseService
 {
-	
-	public static $baseFile = '\bizHd\order\classes\OrderClass';
-	
-	//添加订单
-	public static function addOrder($data)
-	{
-		return OrderClass::addOrder($data);
-	}
-	
-	//获取订单信息 ssh 2019.11.28
-	public static function getOrderList($where)
-	{
-		$data = self::getList('*', $where, 'addTime DESC');
-		if (isset($data['list']) == false || empty($data['list'])) {
-			return $data;
-		}
-		
-		$orderIds = array_column($data['list'], 'id');
-		
-		//获取订单的商品信息
-		$goodsList = OrderGoodsService::getGoodsListByOrderIds($orderIds);
-		
-		//获取订花人的用户信息
-		$orderUserIds = array_column($data['list'], 'customId');
-		$orderUserIds = array_unique(array_filter($orderUserIds));
-		$customList = CustomClass::getCustomByIds($orderUserIds);
-		
-		$merchantIdList = array_column($data['list'], 'merchantId');
-		$merchantIdList = array_filter(array_unique($merchantIdList));
-		$merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
-		
-		$periodData = [0 => '上午', 1 => '下午', 2 => '晚上'];
-		foreach ($data['list'] as $key => $val) {
-			$id = $val['id'];
-			$customId = $val['customId'];
-			$data['list'][$key]['goodsInfoList'] = isset($goodsList[$id]) ? $goodsList[$id] : [];
-			$data['list'][$key]['bookAvatar'] = isset($customList[$customId]['smallAvatarUrl']) ? $customList[$customId]['smallAvatarUrl'] : '';
-			$merchantId = $val['merchantId'];
-			$data['list'][$key]['name'] = isset($merchantList[$merchantId]['name']) ? $merchantList[$merchantId]['name'] : '';
-			$data['list'][$key]['reachTime'] = OrderClass::getReachTime($val);
-			$requireReachTime = '';
-			if ($val['reachDate'] != '0000-00-00') {
-				$reachPeriodId = $val['reachPeriod'];
-				$reachPeriod = isset($periodData[$reachPeriodId]) ? $periodData[$reachPeriodId] : '上午';
-				$requireReachTime = date("m-d", strtotime($val['reachDate'])) . ' ' . $reachPeriod;
-			}
-			$data['list'][$key]['requireReachTime'] = $requireReachTime;
-		}
-		return $data;
-	}
-	
-	//取客户最近若干条订单 ssh 2019.11.30
-	public static function getUserOrder($customId, $limit = 10, $order = null, $with = null)
-	{
-		$where = ['adminId' => $customId, 'payStatus' => 1];
-		return self::getLimitList('*', $where, $limit, $order, $with);
-	}
-	
-	//支付前验证订单 ssh 2019.12.6
-	public static function checkBeforePay($order, $customId)
-	{
-		$now = time();
-		OrderClass::setExpire($order);
-		if (empty($order)) {
-			util::fail('订单无效');
-		}
-		if (isset($order['userId']) && $order['userId'] != $customId) {
-			util::fail('非法访问');
-		}
-		if ($order['status'] != 0) {
-			util::fail('订单不是待付款状态');
-		}
-		if (!empty($order['deadline']) && $now > $order['deadline']) {
-			util::fail('订单已过期');
-		}
-		if (ceil($order['actPrice']) <= 0) {
-			util::fail('订单金额有问题');
-		}
-		if ($order['payStatus'] == 1) {
-			util::fail('您已经付过了');
-		}
-	}
-	
-	//商家验证是否有效 ssh 2019.12.15
-	public static function valid($order, $merchantId)
-	{
-		OrderClass::setExpire($order);
-		if (empty($order)) {
-			util::fail('订单无效');
-		}
-		if ($order['merchantId'] != $merchantId) {
-			util::fail('不是您的订单');
-		}
-	}
-	
-	//根据编号查询 ssh 2019.12.14
-	public static function getByOrderSn($orderSn)
-	{
-		return OrderClass::getByOrderSn($orderSn);
-	}
-	
-	//点评 ssh 2019.12.16
-	public static function comment($data)
-	{
-		return OrderClass::comment($data);
-	}
-	
-	//订单归类
-	public static function classify($id, $categoryId, $usageId)
-	{
-		$connection = Yii::$app->db;//事务处理
-		$transaction = $connection->beginTransaction();
-		try {
-			$order = OrderClass::getById($id, true);
-			if ($order->payStatus != 1) {
-				util::fail('订单还未付款');
-			}
-			if ($order->classify == 1) {
-				util::fail('已经归类过了');
-			}
-			$order->categoryId = $categoryId;
-			$order->usageId = $usageId;
-			$order->classify = 1;
-			$order->save();
-			
-			//设置流水的分类和用途并分配资金
-			$setData = [
-				'merchantId' => $order->merchantId,
-				'capitalId' => $order->capitalId,
-				'time' => $order->payTime,
-				'usageId' => $order->usageId,
-				'categoryId' => $order->categoryId,
-				'amount' => $order->actPrice,
-				'payWay' => $order->payWay,
-			];
-			SjCapitalService::orderClassify($setData);
-			
-			$transaction->commit();
-		} catch (Exception $e) {
-			$transaction->rollBack();
-			util::fail('没有归类成功');
-		}
-	}
-	
-	//更新配送单 ssh 2019.12.17
-	public static function updateSheet($order, $data)
-	{
-		$id = $order['id'];
-		if ($order['status'] != OrderClass::ORDER_STATUS_UN_SEND) {
-			util::fail('订单当前不是待配送状态');
-		}
-		$data['deliver'] = 1;
-		OrderClass::updateById($id, $data);
-	}
-	
-	//订单详情 ssh 2020.1.2
-	public static function getOrderById($id)
-	{
-		return OrderClass::getOrderById($id);
-	}
-	
-	//查看订单详情 ssh 2020.1.4
-	public static function getOrderBySn($orderSn)
-	{
-		return OrderClass::getOrderBySn($orderSn);
-	}
-	
-	//计算优惠 ssh 2020.3.9
-	public static function getDiscountPrice($params)
-	{
-		$couponId = isset($params['couponId']) ? $params['couponId'] : 0;
-		$customId = isset($params['userId']) ? $params['userId'] : 0;
-		$price = isset($params['price']) ? $params['price'] : 0;
-		$sourceType = isset($params['sourceType']) ? $params['sourceType'] : 0;
-		$discountAmount = 0;
-		$discountType = 0;
-		$discountPrice = $price;
-		//使用优惠券
-		if (!empty($couponId)) {
-			$discountAmount = CouponService::checkBeforeUse($couponId, $price, $customId);
-			$discountPrice = stringUtil::calcSub($price, $discountAmount);
-			$discountType = 1;
-		} else {
-			//使用会员
-			$asset = UserAssetClass::getByUserId($customId);
-			if (isset($asset['member']) && $asset['member'] > 0) {
-				$currentDiscount = $asset['discount'];
-				$currentPrice = $price * $currentDiscount;
-				$newPrice = substr(sprintf("%.3f", $currentPrice), 0, -1);
-				$discountType = 2;
-				$discountAmount = stringUtil::calcSub($price, $newPrice);
-				$discountPrice = $newPrice;
-			}
-		}
-		//如果没有优惠券和会员优惠,并且是朋友圈收款,则进行随机优惠 ssh 2019.9.12
-		if ($discountPrice == $price && $sourceType == 3) {
-			$discountAmount = OrderClass::getRandDiscount($price);
-			//开发和测试环境直接随机优惠
-			$env = getenv('YII_ENV');
-			if ($env == 'local' || $env == 'test') {
-				$discountAmount = 0.01;
-			}
-			$discountPrice = stringUtil::calcSub($price, $discountAmount);
-			$discountType = 3;
-		}
-		$discountType = $discountAmount <= 0 ? 0 : $discountType;
-		$discountPrice = $discountPrice <= 0 ? 0.01 : $discountPrice;
-		return ['price' => $discountPrice, 'discountType' => $discountType, 'discountAmount' => $discountAmount];
-	}
-	
+
+    public static $baseFile = '\bizHd\order\classes\OrderClass';
+
+    //添加订单
+    public static function addOrder($data)
+    {
+        return OrderClass::addOrder($data);
+    }
+
+    //获取订单信息 ssh 2019.11.28
+    public static function getOrderList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        if (isset($data['list']) == false || empty($data['list'])) {
+            return $data;
+        }
+
+        $orderIds = array_column($data['list'], 'id');
+
+        //获取订单的商品信息
+        $goodsList = OrderGoodsService::getGoodsListByOrderIds($orderIds);
+
+        //获取订花人的用户信息
+        $orderUserIds = array_column($data['list'], 'customId');
+        $orderUserIds = array_unique(array_filter($orderUserIds));
+        $customList = CustomClass::getCustomByIds($orderUserIds);
+
+        $merchantIdList = array_column($data['list'], 'merchantId');
+        $merchantIdList = array_filter(array_unique($merchantIdList));
+        $merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
+
+        $periodData = [0 => '上午', 1 => '下午', 2 => '晚上'];
+        foreach ($data['list'] as $key => $val) {
+            $id = $val['id'];
+            $customId = $val['customId'];
+            $data['list'][$key]['goodsInfoList'] = isset($goodsList[$id]) ? $goodsList[$id] : [];
+            $data['list'][$key]['bookAvatar'] = isset($customList[$customId]['smallAvatarUrl']) ? $customList[$customId]['smallAvatarUrl'] : '';
+            $merchantId = $val['merchantId'];
+            $data['list'][$key]['name'] = isset($merchantList[$merchantId]['name']) ? $merchantList[$merchantId]['name'] : '';
+            $data['list'][$key]['reachTime'] = OrderClass::getReachTime($val);
+            $requireReachTime = '';
+            if ($val['reachDate'] != '0000-00-00') {
+                $reachPeriodId = $val['reachPeriod'];
+                $reachPeriod = isset($periodData[$reachPeriodId]) ? $periodData[$reachPeriodId] : '上午';
+                $requireReachTime = date("m-d", strtotime($val['reachDate'])) . ' ' . $reachPeriod;
+            }
+            $data['list'][$key]['requireReachTime'] = $requireReachTime;
+        }
+        return $data;
+    }
+
+    //取客户最近若干条订单 ssh 2019.11.30
+    public static function getUserOrder($customId, $limit = 10, $order = null, $with = null)
+    {
+        $where = ['adminId' => $customId, 'payStatus' => 1];
+        return self::getLimitList('*', $where, $limit, $order, $with);
+    }
+
+    //支付前验证订单 ssh 2019.12.6
+    public static function checkBeforePay($order, $customId)
+    {
+        $now = time();
+        OrderClass::setExpire($order);
+        if (empty($order)) {
+            util::fail('订单无效');
+        }
+        if (isset($order['userId']) && $order['userId'] != $customId) {
+            util::fail('非法访问');
+        }
+        if ($order['status'] != 0) {
+            util::fail('订单不是待付款状态');
+        }
+        if (!empty($order['deadline']) && $now > $order['deadline']) {
+            util::fail('订单已过期');
+        }
+        if (ceil($order['actPrice']) <= 0) {
+            util::fail('订单金额有问题');
+        }
+        if ($order['payStatus'] == 1) {
+            util::fail('您已经付过了');
+        }
+    }
+
+    //商家验证是否有效 ssh 2019.12.15
+    public static function valid($order, $shopId)
+    {
+        OrderClass::setExpire($order);
+        if (empty($order)) {
+            util::fail('订单无效');
+        }
+        if ($order['shopId'] != $shopId) {
+            util::fail('不是您的订单');
+        }
+    }
+
+    //根据编号查询 ssh 2019.12.14
+    public static function getByOrderSn($orderSn)
+    {
+        return OrderClass::getByOrderSn($orderSn);
+    }
+
+    //点评 ssh 2019.12.16
+    public static function comment($data)
+    {
+        return OrderClass::comment($data);
+    }
+
+    //订单归类
+    public static function classify($id, $categoryId, $usageId)
+    {
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $order = OrderClass::getById($id, true);
+            if ($order->payStatus != 1) {
+                util::fail('订单还未付款');
+            }
+            if ($order->classify == 1) {
+                util::fail('已经归类过了');
+            }
+            $order->categoryId = $categoryId;
+            $order->usageId = $usageId;
+            $order->classify = 1;
+            $order->save();
+
+            //设置流水的分类和用途并分配资金
+            $setData = [
+                'merchantId' => $order->merchantId,
+                'capitalId' => $order->capitalId,
+                'time' => $order->payTime,
+                'usageId' => $order->usageId,
+                'categoryId' => $order->categoryId,
+                'amount' => $order->actPrice,
+                'payWay' => $order->payWay,
+            ];
+            SjCapitalService::orderClassify($setData);
+
+            $transaction->commit();
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            util::fail('没有归类成功');
+        }
+    }
+
+    //更新配送单 ssh 2019.12.17
+    public static function updateSheet($order, $data)
+    {
+        $id = $order['id'];
+        if ($order['status'] != OrderClass::ORDER_STATUS_UN_SEND) {
+            util::fail('订单当前不是待配送状态');
+        }
+        $data['deliver'] = 1;
+        OrderClass::updateById($id, $data);
+    }
+
+    //订单详情 ssh 2020.1.2
+    public static function getOrderById($id)
+    {
+        return OrderClass::getOrderById($id);
+    }
+
+    //查看订单详情 ssh 2020.1.4
+    public static function getOrderBySn($orderSn)
+    {
+        return OrderClass::getOrderBySn($orderSn);
+    }
+
+    //计算优惠 ssh 2020.3.9
+    public static function getDiscountPrice($params)
+    {
+        $couponId = isset($params['couponId']) ? $params['couponId'] : 0;
+        $customId = isset($params['userId']) ? $params['userId'] : 0;
+        $price = isset($params['price']) ? $params['price'] : 0;
+        $sourceType = isset($params['sourceType']) ? $params['sourceType'] : 0;
+        $discountAmount = 0;
+        $discountType = 0;
+        $discountPrice = $price;
+        //使用优惠券
+        if (!empty($couponId)) {
+            $discountAmount = CouponService::checkBeforeUse($couponId, $price, $customId);
+            $discountPrice = stringUtil::calcSub($price, $discountAmount);
+            $discountType = 1;
+        } else {
+            //使用会员
+            $asset = UserAssetClass::getByUserId($customId);
+            if (isset($asset['member']) && $asset['member'] > 0) {
+                $currentDiscount = $asset['discount'];
+                $currentPrice = $price * $currentDiscount;
+                $newPrice = substr(sprintf("%.3f", $currentPrice), 0, -1);
+                $discountType = 2;
+                $discountAmount = stringUtil::calcSub($price, $newPrice);
+                $discountPrice = $newPrice;
+            }
+        }
+        //如果没有优惠券和会员优惠,并且是朋友圈收款,则进行随机优惠 ssh 2019.9.12
+        if ($discountPrice == $price && $sourceType == 3) {
+            $discountAmount = OrderClass::getRandDiscount($price);
+            //开发和测试环境直接随机优惠
+            $env = getenv('YII_ENV');
+            if ($env == 'local' || $env == 'test') {
+                $discountAmount = 0.01;
+            }
+            $discountPrice = stringUtil::calcSub($price, $discountAmount);
+            $discountType = 3;
+        }
+        $discountType = $discountAmount <= 0 ? 0 : $discountType;
+        $discountPrice = $discountPrice <= 0 ? 0.01 : $discountPrice;
+        return ['price' => $discountPrice, 'discountType' => $discountType, 'discountAmount' => $discountAmount];
+    }
+
 }

+ 2 - 1
biz-mall/order/classes/OrderClass.php

@@ -196,10 +196,11 @@ class OrderClass extends BaseClass
     public static function payAfter($order, $updateData)
     {
         $orderId = $order['id'];
+        $orderSn = $order['orderSn'];
         $now = time();
         self::updateById($orderId, $updateData);
         //发货流程的完成下单
-        OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now]);
+        OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now, 'orderSn' => $orderSn]);
         $merchantId = $order['merchantId'];
         $asset = MerchantAssetClass::getByMerchantId($merchantId);
         //增加订单数

+ 6 - 4
biz-mall/order/services/OrderSendService.php

@@ -21,8 +21,9 @@ class OrderSendService extends BaseService
     //制单 ssh 2019.12.17
     public static function printOrder($data)
     {
-        $id = $data['id'];
-        $option = $data['option'];
+        $id = $data['id'] ?? 0;
+        $option = $data['option'] ?? '';
+        $orderSn = $data['orderSn'] ?? '';
         $actionIdList = OrderSendClass::$actionId;
         $printOrderId = $actionIdList['printOrder'];
         $currentId = OrderSendClass::toDoActionId($id);
@@ -48,7 +49,7 @@ class OrderSendService extends BaseService
 
         //进入发货流程
         $deliverId = $actionIdList['deliver'];
-        $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId];
+        $data = ['actionId' => $deliverId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $deliverId, 'orderSn' => $orderSn];
         OrderSendClass::add($data);
         $actionList = OrderSendClass::$action;
         $data['actionSign'] = isset($actionList[$deliverId]['sign']) ? $actionList[$deliverId]['sign'] : '';
@@ -60,6 +61,7 @@ class OrderSendService extends BaseService
     {
         $id = $data['id'];
         $option = $data['option'];
+        $orderSn = $data['orderSn'] ?? '';
         $actionIdList = OrderSendClass::$actionId;
         $deliverId = $actionIdList['deliver'];
         $currentId = OrderSendClass::toDoActionId($id);
@@ -108,7 +110,7 @@ class OrderSendService extends BaseService
 
         //进入送达流程
         $reachId = $actionIdList['reach'];
-        $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId];
+        $data = ['actionId' => $reachId, 'orderId' => $id, 'finishTime' => 0, 'addTime' => $time, 'inTurn' => $reachId, 'orderSn' => $orderSn];
         OrderSendClass::add($data);
         $actionList = OrderSendClass::$action;
         $data['actionSign'] = isset($actionList[$reachId]['sign']) ? $actionList[$reachId]['sign'] : '';

+ 2 - 2
biz-mall/order/services/OrderService.php

@@ -98,13 +98,13 @@ class OrderService extends BaseService
     }
 
     //商家验证是否有效 ssh 2019.12.15
-    public static function valid($order, $merchantId)
+    public static function valid($order, $shopId)
     {
         OrderClass::setExpire($order);
         if (empty($order)) {
             util::fail('订单无效');
         }
-        if ($order['merchantId'] != $merchantId) {
+        if ($order['shopId'] != $shopId) {
             util::fail('不是您的订单');
         }
     }