|
|
@@ -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, ""
|
|
|
+}
|