ソースを参照

下单计入赠品

abiao 3 年 前
コミット
433277b8be

+ 11 - 0
go/gopath/src/fohow.com/apps/controllers/order_controller/order_controller.go

@@ -2,6 +2,7 @@ package order_controller
 
 import (
 	"fmt"
+	"fohow.com/apps/helpers"
 	"fohow.com/apps/models/cent_model"
 	"fohow.com/apps/models/sys_config"
 	"fohow.com/libs/lib_redis"
@@ -135,6 +136,9 @@ func (self *OrderController) Create() {
 	new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, product.Name,
 		sizeName, colorName, count, wxUser.Depart)
 
+	//发放赠品
+	helpers.SetOrderPromotionPro(order.OrderId, wxUser.Id)
+
 	//未支付订单加入取消队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowInRedisList(cancelKey, order.OrderId)
@@ -270,6 +274,10 @@ func (self *OrderController) MultipleCreate() {
 	order.Save()
 	//购物册清理
 	go ClearCart(order.WxUserId, order.OrderId)
+
+	//发放赠品
+	helpers.SetOrderPromotionPro(order.OrderId, wxUser.Id)
+
 	//未支付订单加入取消队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowInRedisList(cancelKey, order.OrderId)
@@ -354,6 +362,9 @@ func (self *OrderController) MultShopCreate() {
 	order.Freight = freight
 	order.Save()
 
+	//发放赠品
+	helpers.SetOrderPromotionPro(order.OrderId, wxUser.Id)
+
 	//未支付订单加入取消队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowInRedisList(cancelKey, order.OrderId)

+ 1 - 1
go/gopath/src/fohow.com/apps/controllers/pay_controller/after_pay_controller.go

@@ -185,7 +185,7 @@ func (self *PayController) wxPayExchangeAsync() {
 	}
 
 	//发放赠品
-	go helpers.SetOrderPromotionPro(order.OrderId, wxUser.Id)
+	//go helpers.SetOrderPromotionPro(order.OrderId, wxUser.Id)
 	//已支付订单移除队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)

+ 53 - 38
go/gopath/src/fohow.com/apps/controllers/pay_controller/pay_exchange_controller.go

@@ -109,51 +109,66 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
 		if product == nil {
 			self.ReturnError(403, []string{apps.ProductNotExist[0], fmt.Sprintf("%s产品不存在", product.Name)}, "", nil)
 		}
-		//商品下架
-		if product.Status == product_model.PRODUCT_STATUS_DOWN {
-			self.ReturnError(403, []string{apps.ProductOffSale[0], fmt.Sprintf("%s产品已经下架", product.Name)}, "", nil)
-		}
+		//非赠品计入价格
+		if !item.Send {
+			//商品下架
+			if product.Status == product_model.PRODUCT_STATUS_DOWN {
+				self.ReturnError(403, []string{apps.ProductOffSale[0], fmt.Sprintf("%s产品已经下架", product.Name)}, "", nil)
+			}
 
-		//秒杀逻辑: 判断是否处于秒杀时间段内
-		if product.SeckilShowPrice > 0 {
-			now := time.Now()
-			if now.Unix() < product.SeckillStart.Unix() {
-				self.ReturnError(403, []string{apps.SeckillNotStart[0], fmt.Sprintf("%s秒杀活动尚未开始", product.Name)}, "", nil)
-			} else if now.Unix() > product.SeckillEnd.Unix() {
-				self.ReturnError(403, []string{apps.SeckillIsEnd[0], fmt.Sprintf("%s秒杀活动已经结束", product.Name)}, "", nil)
+			//秒杀逻辑: 判断是否处于秒杀时间段内
+			if product.SeckilShowPrice > 0 {
+				now := time.Now()
+				if now.Unix() < product.SeckillStart.Unix() {
+					self.ReturnError(403, []string{apps.SeckillNotStart[0], fmt.Sprintf("%s秒杀活动尚未开始", product.Name)}, "", nil)
+				} else if now.Unix() > product.SeckillEnd.Unix() {
+					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 > 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)
+					}
 				}
-				//历史没买够数量,但是历史总数+想购买的数量 超过限购数量
-				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)
+			}
+			//仅发货地区省,市判断
+			if len(product.OnlyDeliveryArea) > 0 {
+				if product_model.GetProductByIdAndProvince(product.Id, allowPro, true) == nil && helper.NewStr(product.OnlyDeliveryArea).Strpos(allowAddr, 0) < 0 {
+					self.ReturnError(403, []string{apps.OnlyDeliveryArea[0], fmt.Sprintf("%s产品不在限售区域内", product.Name)}, "", nil)
 				}
 			}
-		}
-		//仅发货地区省,市判断
-		if len(product.OnlyDeliveryArea) > 0 {
-			if product_model.GetProductByIdAndProvince(product.Id, allowPro, true) == nil && helper.NewStr(product.OnlyDeliveryArea).Strpos(allowAddr, 0) < 0 {
-				self.ReturnError(403, []string{apps.OnlyDeliveryArea[0], fmt.Sprintf("%s产品不在限售区域内", product.Name)}, "", nil)
+
+			//微信支付金额统计
+			if product.Pv >= product.Price || specialPromotion {
+				total_quan += product.Price * item.Count
 			}
+			total_price += product.Price * item.Count
+
 		}
 
-		//微信支付金额统计
-		if product.Pv >= product.Price || specialPromotion {
-			total_quan += product.Price * item.Count
+		if _, ok := SaleNumsMap[product.Id]; ok {
+			SaleNumsMap[product.Id] = item.Count + SaleNumsMap[product.Id]
+		} else {
+			SaleNumsMap[product.Id] = item.Count
 		}
-		total_price += product.Price * item.Count
-		SaleNumsMap[product.Id] = item.Count
-		storeMap[product.Id] = item.Count
+
+		if _, ok := storeMap[product.Id]; ok {
+			storeMap[product.Id] = item.Count + storeMap[product.Id]
+		} else {
+			storeMap[product.Id] = item.Count
+		}
+
 	}
 	//beego.BeeLogger.Error("SaleNumsMap1 %v", SaleNumsMap)
 
@@ -238,7 +253,7 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
 			order.Source = source
 			order.Save()
 			//发放赠品
-			go helpers.SetOrderPromotionPro(order.OrderId, wxUser.Id)
+			//go helpers.SetOrderPromotionPro(order.OrderId, wxUser.Id)
 			//已支付订单移除未支付队列
 			cancelKey := lib_redis.GetOrderCancelList()
 			lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
@@ -268,7 +283,7 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
 				//获取paycode
 				payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, false)
 
-				beego.BeeLogger.Warn("payCode--%s", payCode)
+				//beego.BeeLogger.Warn("payCode--%s", payCode)
 				payData := wx_mp.GetPayData(wxUser.Openid, order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
 
 				//返回数据

+ 2 - 2
go/gopath/src/fohow.com/apps/models/order_model/order_detail.go

@@ -102,8 +102,8 @@ func SendCreate(oId string, orderId, pId, pPrice, unitRoboBalancePrice int64, pN
 	if item != nil {
 		go GenerateOrderDtItem(item)
 		//更新赠品已售数量
-		sendMap := map[int64]int64{pId: pCount}
-		go UpdateSaleNums(sendMap)
+		//sendMap := map[int64]int64{pId: pCount}
+		//go UpdateSaleNums(sendMap)
 	}
 
 	return item