|
|
@@ -88,8 +88,6 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
|
|
|
self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
}
|
|
|
SaleNumsMap := make(map[int64]int64)
|
|
|
-
|
|
|
- storeMap := make(map[int64]int64)
|
|
|
specialPromotion = order.SpecialPro
|
|
|
//支付方式判断
|
|
|
if order.OrderType == order_model.ORDER_TYPE_SHOP && payWay == pay_model.PAYWAY_BALANCE {
|
|
|
@@ -171,17 +169,9 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
|
|
|
} else {
|
|
|
SaleNumsMap[product.Id] = item.Count
|
|
|
}
|
|
|
-
|
|
|
- if _, ok := storeMap[product.Id]; ok {
|
|
|
- storeMap[product.Id] = item.Count + storeMap[product.Id]
|
|
|
- } else {
|
|
|
- storeMap[product.Id] = item.Count
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
dis_amount := order.DisAmount
|
|
|
-
|
|
|
- resultStore, prdName := FindNotEnoughPrd(storeMap)
|
|
|
+ resultStore, prdName := FindNotEnoughPrd(SaleNumsMap)
|
|
|
if resultStore {
|
|
|
self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
}
|
|
|
@@ -518,8 +508,7 @@ 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)
|
|
|
+ resultStore, prdName := FindNotEnoughPrd(SaleNumsMap)
|
|
|
if resultStore {
|
|
|
self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
}
|
|
|
@@ -583,22 +572,25 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
|
|
|
// 获取库存不足商品
|
|
|
func FindNotEnoughPrd(storeMap map[int64]int64) (bool, string) {
|
|
|
//判断商品库存
|
|
|
+ tempStoreMap := make(map[int64]int64) // 创建一个临时map来存储修改后的库存信息
|
|
|
+
|
|
|
for pId, nums := range storeMap {
|
|
|
product := product_model.GetProductById(pId, true)
|
|
|
if product.Package {
|
|
|
- //beego.BeeLogger.Error("product id %d", product.Id)
|
|
|
+ //如果产品是一个包装,则遍历包装中的每个项目
|
|
|
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
|
|
|
- } else {
|
|
|
- storeMap[one.ItemId] = nums * one.Nums
|
|
|
- }
|
|
|
+ //累加或设置基本商品的库存数量
|
|
|
+ tempStoreMap[one.ItemId] += nums * one.Nums
|
|
|
}
|
|
|
+ } else {
|
|
|
+ //如果产品不是包装,则直接复制到临时map
|
|
|
+ tempStoreMap[pId] = nums
|
|
|
}
|
|
|
}
|
|
|
- for r_pid, r_nums := range storeMap {
|
|
|
+
|
|
|
+ //遍历临时库存map来检查是否有不足的商品
|
|
|
+ for r_pid, r_nums := range tempStoreMap {
|
|
|
product := product_model.GetProductById(r_pid, false)
|
|
|
if product.Count > int64(0) && product.Count < (r_nums+product.SaleNums) {
|
|
|
return true, product.Name
|