Преглед изворни кода

order purchase limit logic edit

abiao пре 5 година
родитељ
комит
2f85fc1cf5

+ 34 - 0
go/gopath/src/fohow.com/apps/controllers/pay_controller/pay_exchange_controller.go

@@ -92,6 +92,23 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 					self.ReturnError(403, []string{apps.SeckillIsEnd[0], fmt.Sprintf("%s秒杀活动已经结束", product.Name)}, "", nil)
 				}
 			}
+			//限购逻辑
+			if product.PurchaseLimitCount > 0 {
+				if product.PurchaseLimitCount < item.Count {
+					self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
+				} else {
+					purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(product.Id, wxUId)
+					//历史已经买够到限购数量了
+					if product.PurchaseLimitCount <= purchaseTotalCount {
+						self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
+					}
+					//历史没买够数量,但是历史总数+想购买的数量 超过限购数量
+					if product.PurchaseLimitCount < (purchaseTotalCount + item.Count) {
+						canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
+						self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
+					}
+				}
+			}
 			buy_price_total += product.BuyPrice * item.Count
 			total_price += product.Price * item.Count
 			SaleNumsMap[product.Id] = item.Count
@@ -294,6 +311,23 @@ func (self *PayController) payCentExchange(oId, returnUrl, source string) {
 		if product.Status == product_model.PRODUCT_STATUS_DOWN {
 			self.ReturnError(403, []string{apps.ProductOffSale[0], fmt.Sprintf("%s产品已经下架", product.Name)}, "", nil)
 		}
+		//限购逻辑
+		if product.PurchaseLimitCount > 0 {
+			if product.PurchaseLimitCount < item.Count {
+				self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
+			} else {
+				purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(product.Id, wxUId)
+				//历史已经买够到限购数量了
+				if product.PurchaseLimitCount <= purchaseTotalCount {
+					self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
+				}
+				//历史没买够数量,但是历史总数+想购买的数量 超过限购数量
+				if product.PurchaseLimitCount < (purchaseTotalCount + item.Count) {
+					canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
+					self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
+				}
+			}
+		}
 		buy_price_total += product.BuyPrice * item.Count
 		total_price += product.Price * item.Count
 		SaleNumsMap[product.Id] = item.Count

+ 1 - 1
go/gopath/src/fohow.com/apps/models/order_model/order.go

@@ -568,7 +568,7 @@ func GetOrderCountByPIdAndWxUId(pId, wxUId int64) int64 {
 		FROM
 			order_details
 		WHERE
-			order_no in (select order_id from orders where wx_user_id = %d and status in ('processing','complete','dispatch','unconfirmed','unpay'))
+			order_no in (select order_id from orders where wx_user_id = %d and status in ('processing','complete','dispatch','unconfirmed'))
 		and
 			product_id = ?
 	`