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

update pay order product store rules

abiao пре 4 година
родитељ
комит
007e1b6e41

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

@@ -213,7 +213,6 @@ func UpdatePdSaleNums(order *order_model.Order) {
 	for _, item := range orderDtList {
 		SaleNumsMap[item.ProductId] = item.Count
 	}
-
 	go order_model.UpdateSaleNums(SaleNumsMap)
 }
 

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

@@ -113,6 +113,11 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
 			total_price += product.Price * item.Count
 			SaleNumsMap[product.Id] = item.Count
 		}
+		storeMap := SaleNumsMap
+		resultStore, prdName := FindNotEnoughPrd(storeMap)
+		if resultStore {
+			self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
+		}
 		order.Remark = remark
 		order.PayWay = payWay
 		order.Contact = address.Contact
@@ -333,6 +338,11 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
 		total_price += product.Price * item.Count
 		SaleNumsMap[product.Id] = item.Count
 	}
+	storeMap := SaleNumsMap
+	resultStore, prdName := FindNotEnoughPrd(storeMap)
+	if resultStore {
+		self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
+	}
 	order.Remark = remark
 	order.PayWay = order_model.PAY_WAY_CENT
 	order.Contact = address.Contact
@@ -407,3 +417,29 @@ func CreateOrderNotify(order *order_model.Order, product *product_model.Product)
 		}
 	}
 }
+
+//获取库存不足商品
+func FindNotEnoughPrd(storeMap map[int64]int64) (bool, string) {
+
+	//判断商品库存
+	for pId, nums := range storeMap {
+		//商品状态
+		product := product_model.GetProductById(pId, true)
+		if product.Package {
+			packageList := product_model.GetPackageList(pId, true)
+			for _, one := range packageList {
+				if _, ok := storeMap[one.ItemId]; ok {
+					//基本商品存在
+					storeMap[one.ItemId] = storeMap[one.ItemId] + nums*one.Nums
+				}
+			}
+		}
+	}
+	for r_pid, r_nums := range storeMap {
+		product := product_model.GetProductById(r_pid, true)
+		if product.Count < r_nums {
+			return true, product.Name
+		}
+	}
+	return false, ""
+}

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

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