shish 6 лет назад
Родитель
Сommit
f48718e697
2 измененных файлов с 18 добавлено и 21 удалено
  1. 15 19
      app/client/controllers/OrderController.php
  2. 3 2
      biz/order/services/OrderService.php

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

@@ -80,26 +80,17 @@ class OrderController extends BaseController
 		}
 		$goodsPrice = $unitPrice * $goodsNum;
 		$prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
-		$actPrice = $prePrice;
 		$showPrice = $prePrice;
-		
-		//计算优惠金额
-		$couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
-		//没有使用优惠券,默认使用会员优惠
-		if (empty($couponId)) {
-			$discountInfo = UserAssetService::getDiscount($this->userId);
-			if (isset($discountInfo['member'])) {
-				$discount = $discountInfo['member']['discount'];
-				$actPrice = ($actPrice * ($discount * 10000)) / 10000;
-				$showPrice = $actPrice;
-			}
-		} else {
-			//验证优惠券有效性
-			$discountAmount = CouponService::valid($couponId, $actPrice, $this->userId);
-			//优惠券在支付成功后变更状态
-			$showPrice = stringUtil::calcSub($actPrice, $discountAmount);
+		$sourceType = $this->isWx ? 0 : 1;
+		if (httpUtil::isMiniProgram()) {
+			$sourceType = 2;
 		}
-		
+		$couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
+		$discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->userId]);
+		$actPrice = $discountData['price'];
+		$post['discountType'] = $discountData['discountType'];
+		$post['discountAmount'] = $discountData['discountAmount'];
+
 		$now = time();
 		$expireTime = $now + 1800;//订单30分钟后过期
 		$post['deadline'] = $expireTime;
@@ -243,7 +234,12 @@ class OrderController extends BaseController
 		$shopInfo = ShopService::getById($shopId);
 		ShopService::valid($shopInfo, $this->merchantId);
 		//来源 0微信 1支付宝 2小程序 3朋友圈 4美团
-		$sourceType = 3;
+		$sourceType = $this->isWx ? 0 : 1;
+		if (httpUtil::isMiniProgram()) {
+			$sourceType = 2;
+		}
+		$sourceType = isset($post['sourceType']) ? $post['source'] : 0;
+
 		$post['userId'] = $this->userId;
 		$prePrice = round($post['prePrice'], 2);
 		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;

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

@@ -199,7 +199,7 @@ class OrderService extends BaseService
 			$discountAmount = stringUtil::calcSub($price, $newPrice);
 			$discountPrice = $newPrice;
 		}
-
+		
 		//使用随机优惠 shish 2019.9.12
 		if ($sourceType == 3) {
 			$discountAmount = OrderClass::getRandDiscount($price);
@@ -209,10 +209,11 @@ class OrderService extends BaseService
 				$discountAmount = 0.01;
 			}
 			$discountPrice = stringUtil::calcSub($price, $discountAmount);
+			$discountPrice = $discountPrice <= 0 ? 0.01 : $discountPrice;
 			$discountType = 3;
 		}
 		$discountType = $discountAmount <= 0 ? 0 : $discountType;
 		return ['price' => $discountPrice, 'discountType' => $discountType, 'discountAmount' => $discountAmount];
 	}
-
+	
 }