Browse Source

下单功能优化

shish 6 years ago
parent
commit
d62b9088ea
3 changed files with 38 additions and 37 deletions
  1. 22 36
      app/client/controllers/OrderController.php
  2. 14 1
      biz/order/services/OrderService.php
  3. 2 0
      sql.txt

+ 22 - 36
app/client/controllers/OrderController.php

@@ -19,17 +19,17 @@ use common\components\util;
 
 class OrderController extends BaseController
 {
-
+	
 	//商城下单操作 shish 2019.12.3
 	public function actionCreateOrder()
 	{
-
+		
 		//给出省市区的接口 todo
 		//给出商家门店地址接口 todo
 		//给出腾讯的接口 todo
 		//运费 计算方式 todo
 		//余额支付 要使用哪个接口 todo
-
+		
 		$post = Yii::$app->request->post();
 		$goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
 		$goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
@@ -99,11 +99,16 @@ class OrderController extends BaseController
 			//优惠券在支付成功后变更状态
 			$showPrice = stringUtil::calcSub($actPrice, $discountAmount);
 		}
+		
+		$now = time();
+		$expireTime = $now + 1800;//订单30分钟后过期
+		$post['deadline'] = $expireTime;
+		
 		$post['prePrice'] = $prePrice;
 		$post['actPrice'] = $actPrice;
 		$order = OrderService::addOrder($post);
 		$orderId = $order['id'];
-
+		
 		$data = [
 			'orderId' => $orderId,
 			'goodsId' => $goodsId,
@@ -128,31 +133,12 @@ class OrderController extends BaseController
 		ini_set('date.timezone', 'Asia/Shanghai');
 		$post = Yii::$app->request->post();
 		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-		$now = time();
-		$expireTime = $now + 1800;//订单30分钟后过期
-		if ($this->merchantExtend['payment'] == 0) {
-			util::fail('还没开通支付功能哟');
-		}
 		$orderId = isset($post['orderId']) ? $post['orderId'] : 0;
 		$order = OrderService::getById($orderId);
-		if (!empty($couponId)) {
-			$coupon = xhCouponService::getById($couponId);
-			if ($coupon['useStatus'] == 1 || $now > $coupon['deadline']) {
-				util::fail('代金劵已经失效');
-			}
-			if ($coupon['meetAmount'] > $order['prePrice']) {
-				util::fail('消费金额不足' . $coupon['meetAmount'] . '元');
-			}
-		}
-		if ($order['userId'] != 0 && $order['userId'] != $this->userId) {//当 快速下单时,字段userId为0(未保存指定用户);用户操作后,就只能该用户访问
-			util::fail('非法访问');
-		}
-		if (!empty($order['deadline']) && $now > $order['deadline']) {
-			util::fail('订单已经过期');
-		}
-		if (ceil($order['actPrice']) <= 0) {
-			util::fail('消费金额小于(等于)0');
-		}
+		
+		//验证订单有效性
+		OrderService::valid($order, $this->userId);
+		
 		$name = $order['orderName'];
 		$totalFee = $order['actPrice'];
 		$openId = $this->user['openId'];
@@ -175,7 +161,6 @@ class OrderController extends BaseController
 		
 		//服务商 代设置微信支付,要添加的参数设置
 		if ($this->merchantExtend['generalMerchant'] == 1) {
-			//$input->SetOpenid($openId);
 			$input->SetSub_openid($openId);
 			//自设置 微信支付
 		} else {
@@ -186,17 +171,18 @@ class OrderController extends BaseController
 		$tools = new \JsApiPay();
 		$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->merchantExtend);
 		$newParams = json_decode($jsApiParameters, true);
-		
-		$updateData = ['modPriceStatus' => 1];//已经请求微信不能修改价格
+		//已请求微信不能修改价格
+		$updateData = [];
+		$updateData['modPriceStatus'] = 1;
 		if (empty($order['deadline'])) {
 			$updateData['deadline'] = $expireTime;
 		}
-		xhOrderService::updateById($orderId, $updateData);//已经请求微信不能修改价格
+		OrderService::updateById($orderId, $updateData);
 		util::success($newParams);
 	}
-	
+
 	//快速付款订单
-	public function actionFastCreateOrder()
+	public function actionFastWxPay()
 	{
 		ini_set('date.timezone', 'Asia/Shanghai');
 		$post = Yii::$app->request->post();
@@ -325,7 +311,7 @@ class OrderController extends BaseController
 		}
 		util::success(['orderId' => $orderId]);
 	}
-	
+
 	//快捷支付使用支付宝付款 shish 2019.12.3
 	public function actionFastZfbPay()
 	{
@@ -419,7 +405,7 @@ class OrderController extends BaseController
 		$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
 		util::success($result);
 	}
-
+	
 	/**
 	 * 订单 - 支付宝支付
 	 */
@@ -464,5 +450,5 @@ class OrderController extends BaseController
 		$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $config['notify_url']);
 		util::success($result);
 	}
-
+	
 }

+ 14 - 1
biz/order/services/OrderService.php

@@ -24,7 +24,7 @@ class OrderService extends BaseService
 	{
 		return OrderClass::addOrder($data);
 	}
-
+	
 	//获取订单信息 shish 2019.11.28
 	public static function getOrderList($where)
 	{
@@ -60,4 +60,17 @@ class OrderService extends BaseService
 		return self::getLimitList('*', $where, $limit, $order, $with);
 	}
 	
+	public static function valid($order, $userId)
+	{
+		if ($order['userId'] != 0 && $order['userId'] != $userId) {
+			util::fail('非法访问');
+		}
+		if (!empty($order['deadline']) && $now > $order['deadline']) {
+			util::fail('订单已经过期');
+		}
+		if (ceil($order['actPrice']) <= 0) {
+			util::fail('订单金额有问题');
+		}
+	}
+	
 }

+ 2 - 0
sql.txt

@@ -2,6 +2,8 @@
 ALTER TABLE xhOrderGoods CHANGE `multipleTitle` `goodsStyleName` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '款式名称';
 ALTER TABLE xhOrderGoods CHANGE `multiPriceId` `goodsStyleId` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '款式id';
 ALTER TABLE xhCoupon MODIFY `status` TINYINT NOT NULL DEFAULT 0 COMMENT '状态 0未使用 1使用 2过期';
+ALTER TABLE xhOrder DROP COLUMN `luckyNum`;
+ALTER TABLE xhOrder DROP COLUMN `uniCode`;
 
 2019.12.4 11:44 shish
 ALTER TABLE xhShop CHANGE `businessName` `shopName` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '门店名称';