|
@@ -88,8 +88,6 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
|
|
|
self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
}
|
|
}
|
|
|
SaleNumsMap := make(map[int64]int64)
|
|
SaleNumsMap := make(map[int64]int64)
|
|
|
-
|
|
|
|
|
- storeMap := make(map[int64]int64)
|
|
|
|
|
specialPromotion = order.SpecialPro
|
|
specialPromotion = order.SpecialPro
|
|
|
//支付方式判断
|
|
//支付方式判断
|
|
|
if order.OrderType == order_model.ORDER_TYPE_SHOP && payWay == pay_model.PAYWAY_BALANCE {
|
|
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 {
|
|
} else {
|
|
|
SaleNumsMap[product.Id] = item.Count
|
|
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
|
|
dis_amount := order.DisAmount
|
|
|
-
|
|
|
|
|
- resultStore, prdName := FindNotEnoughPrd(storeMap)
|
|
|
|
|
|
|
+ resultStore, prdName := FindNotEnoughPrd(SaleNumsMap)
|
|
|
if resultStore {
|
|
if resultStore {
|
|
|
self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
}
|
|
}
|
|
@@ -323,7 +313,7 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
|
|
|
cancelKey := lib_redis.GetOrderCancelList()
|
|
cancelKey := lib_redis.GetOrderCancelList()
|
|
|
lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
|
|
lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
|
|
|
//更新已售数量
|
|
//更新已售数量
|
|
|
- order_model.UpdateSaleNums(SaleNumsMap)
|
|
|
|
|
|
|
+ helpers.UpdatePdSaleNums(order, 0)
|
|
|
//赠品写入订单
|
|
//赠品写入订单
|
|
|
helpers.PresentTransferToOrder(order.OrderId, wxUId)
|
|
helpers.PresentTransferToOrder(order.OrderId, wxUId)
|
|
|
//go CreateOrderNotify(order, product)
|
|
//go CreateOrderNotify(order, product)
|
|
@@ -518,8 +508,7 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
|
|
|
total_price += product.Price * item.Count
|
|
total_price += product.Price * item.Count
|
|
|
SaleNumsMap[product.Id] = item.Count
|
|
SaleNumsMap[product.Id] = item.Count
|
|
|
}
|
|
}
|
|
|
- storeMap := SaleNumsMap
|
|
|
|
|
- resultStore, prdName := FindNotEnoughPrd(storeMap)
|
|
|
|
|
|
|
+ resultStore, prdName := FindNotEnoughPrd(SaleNumsMap)
|
|
|
if resultStore {
|
|
if resultStore {
|
|
|
self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
}
|
|
}
|
|
@@ -570,9 +559,8 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
|
|
|
//已支付订单移除未支付队列
|
|
//已支付订单移除未支付队列
|
|
|
cancelKey := lib_redis.GetOrderCancelList()
|
|
cancelKey := lib_redis.GetOrderCancelList()
|
|
|
lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
|
|
lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
|
|
|
- //更新已售数量
|
|
|
|
|
- order_model.UpdateSaleNums(SaleNumsMap)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //0 减少 -- 更新已售数量
|
|
|
|
|
+ helpers.UpdatePdSaleNums(order, 0)
|
|
|
payUrl, payData = fmt.Sprintf("%s?order_id=%s", returnUrl, order.OrderId), nil
|
|
payUrl, payData = fmt.Sprintf("%s?order_id=%s", returnUrl, order.OrderId), nil
|
|
|
result := PayUrl{NeedWx: false, PayUrl: payUrl, PayData: payData, OrderId: order.OrderId}
|
|
result := PayUrl{NeedWx: false, PayUrl: payUrl, PayData: payData, OrderId: order.OrderId}
|
|
|
//self.Data["json"] = self.FormatResult([]interface{}{result})
|
|
//self.Data["json"] = self.FormatResult([]interface{}{result})
|
|
@@ -583,22 +571,25 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
|
|
|
// 获取库存不足商品
|
|
// 获取库存不足商品
|
|
|
func FindNotEnoughPrd(storeMap map[int64]int64) (bool, string) {
|
|
func FindNotEnoughPrd(storeMap map[int64]int64) (bool, string) {
|
|
|
//判断商品库存
|
|
//判断商品库存
|
|
|
|
|
+ tempStoreMap := make(map[int64]int64) // 创建一个临时map来存储修改后的库存信息
|
|
|
|
|
+
|
|
|
for pId, nums := range storeMap {
|
|
for pId, nums := range storeMap {
|
|
|
product := product_model.GetProductById(pId, true)
|
|
product := product_model.GetProductById(pId, true)
|
|
|
if product.Package {
|
|
if product.Package {
|
|
|
- //beego.BeeLogger.Error("product id %d", product.Id)
|
|
|
|
|
|
|
+ //如果产品是一个包装,则遍历包装中的每个项目
|
|
|
packageList := product_model.GetPackageList(pId, true)
|
|
packageList := product_model.GetPackageList(pId, true)
|
|
|
for _, one := range packageList {
|
|
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)
|
|
product := product_model.GetProductById(r_pid, false)
|
|
|
if product.Count > int64(0) && product.Count < (r_nums+product.SaleNums) {
|
|
if product.Count > int64(0) && product.Count < (r_nums+product.SaleNums) {
|
|
|
return true, product.Name
|
|
return true, product.Name
|
|
@@ -621,3 +612,143 @@ func FindMaxPaymentMethod(total_weixin, totalCoupon, paiedCash int64) string {
|
|
|
|
|
|
|
|
return paymentMethod
|
|
return paymentMethod
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+type PaymentDetails struct {
|
|
|
|
|
+ FirstPay bool // 是否首次支付
|
|
|
|
|
+ OrderLimit int64 // 免运费订单金额
|
|
|
|
|
+ TotalPrice int64 // 订单总金额
|
|
|
|
|
+ Freight int64 // 运费
|
|
|
|
|
+ PaySilver int64 // 用银币支付的金额
|
|
|
|
|
+ PayCoupon int64 // 用提货券支付的金额
|
|
|
|
|
+ PayBalance int64 // 用佣金支付的金额
|
|
|
|
|
+ Discount int64 // 店长折扣金额
|
|
|
|
|
+ ShouldPay int64 // 应支付金额
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (self *PayController) QueryPayInfo() {
|
|
|
|
|
+
|
|
|
|
|
+ oId := self.GetString("order_id")
|
|
|
|
|
+ pickWay, _ := self.GetInt64("pick_way")
|
|
|
|
|
+ useCoupon, _ := self.GetBool("use_coupon", false)
|
|
|
|
|
+ useBalance, _ := self.GetBool("use_balance", false)
|
|
|
|
|
+
|
|
|
|
|
+ payOrder.Lock()
|
|
|
|
|
+ defer payOrder.Unlock()
|
|
|
|
|
+ var details PaymentDetails
|
|
|
|
|
+
|
|
|
|
|
+ wxUId := self.GetCurrentWxUserIdByToken()
|
|
|
|
|
+ wxUser := user_model.GetWxUserById(wxUId, false)
|
|
|
|
|
+ if wxUser == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //订单状态
|
|
|
|
|
+ order := order_model.GetOrderById(oId, false)
|
|
|
|
|
+ if order == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.OrderNotExist, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if order.Status != order_model.STATUS_UNPAY {
|
|
|
|
|
+ self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ specialPromotion := order.SpecialPro
|
|
|
|
|
+ //获取购物商品明细
|
|
|
|
|
+ total_price := int64(0)
|
|
|
|
|
+ total_quan := int64(0)
|
|
|
|
|
+ total_weixin := int64(0)
|
|
|
|
|
+ paiedSilver := int64(0)
|
|
|
|
|
+ paiedCash := int64(0) //抵扣佣金
|
|
|
|
|
+ firstPay := true
|
|
|
|
|
+ //店长折扣
|
|
|
|
|
+ dis_amount := order.DisAmount
|
|
|
|
|
+ //若账户有提货券则优先抵扣提货券
|
|
|
|
|
+ totalCoupon := int64(0)
|
|
|
|
|
+ list := order_model.GetAllDetailsOrderId(order.OrderId, false)
|
|
|
|
|
+ for _, item := range list {
|
|
|
|
|
+ //商品状态
|
|
|
|
|
+ product := product_model.GetProductById(item.ProductId, false)
|
|
|
|
|
+ if product == nil {
|
|
|
|
|
+ self.ReturnError(403, []string{apps.ProductNotExist[0], fmt.Sprintf("%s产品不存在", product.Name)}, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ //非赠品计入价格
|
|
|
|
|
+ if !item.Send {
|
|
|
|
|
+ //微信支付金额统计
|
|
|
|
|
+ if product.UseQuan || specialPromotion {
|
|
|
|
|
+ total_quan += product.Price*item.Count - item.Silver
|
|
|
|
|
+ }
|
|
|
|
|
+ total_price += product.Price * item.Count
|
|
|
|
|
+ paiedSilver += item.Silver
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //运费
|
|
|
|
|
+ freight := sys_config.GetFreight()
|
|
|
|
|
+ orderLimt := sys_config.GetOrderLimit()
|
|
|
|
|
+ //第一次支付已更新支付方式,第一次支付才计算支付金额
|
|
|
|
|
+ if len(order.PayWay) <= 0 {
|
|
|
|
|
+ //计算运费
|
|
|
|
|
+ if total_price >= orderLimt || pickWay == order_model.PICK_SHOP {
|
|
|
|
|
+ freight = int64(0)
|
|
|
|
|
+ }
|
|
|
|
|
+ tp := total_price
|
|
|
|
|
+ //抵扣银豆
|
|
|
|
|
+ if paiedSilver > tp {
|
|
|
|
|
+ paiedSilver = tp
|
|
|
|
|
+ }
|
|
|
|
|
+ tp -= paiedSilver
|
|
|
|
|
+ userLeftBalanceCount := balance_model.GetUserTotalBalance(wxUId)
|
|
|
|
|
+ tp += freight
|
|
|
|
|
+ total_quan = total_quan + freight
|
|
|
|
|
+ useCoupon = true
|
|
|
|
|
+ if useCoupon && userLeftBalanceCount > 0 {
|
|
|
|
|
+ if userLeftBalanceCount < total_quan {
|
|
|
|
|
+ totalCoupon = userLeftBalanceCount
|
|
|
|
|
+ } else {
|
|
|
|
|
+ totalCoupon = total_quan
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ total_weixin = tp - totalCoupon
|
|
|
|
|
+
|
|
|
|
|
+ //店长先抵扣折扣
|
|
|
|
|
+ paiedDis := int64(0)
|
|
|
|
|
+ if wxUser.Rank >= user_model.WX_USER_RANK_ONE && dis_amount > int64(0) {
|
|
|
|
|
+ if dis_amount < total_weixin {
|
|
|
|
|
+ paiedDis = dis_amount
|
|
|
|
|
+ } else {
|
|
|
|
|
+ paiedDis = total_weixin
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ total_weixin = total_weixin - paiedDis
|
|
|
|
|
+ userLeftBalanceCash := balance_model.GetCashTotalBalance(wxUId)
|
|
|
|
|
+ if userLeftBalanceCash > int64(0) && useBalance {
|
|
|
|
|
+ if userLeftBalanceCash < total_weixin && total_weixin > 0 {
|
|
|
|
|
+ paiedCash = userLeftBalanceCash
|
|
|
|
|
+ } else {
|
|
|
|
|
+ paiedCash = total_weixin
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ total_weixin = total_weixin - paiedCash
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ firstPay = false
|
|
|
|
|
+ freight = order.Freight
|
|
|
|
|
+ paiedSilver = order.PaiedSilver
|
|
|
|
|
+ totalCoupon = order.CouponPrice
|
|
|
|
|
+ total_weixin = order.PaiedPrice
|
|
|
|
|
+ paiedCash = order.PaiedCash
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ details.FirstPay = firstPay
|
|
|
|
|
+ details.OrderLimit = orderLimt
|
|
|
|
|
+ details.Freight = freight
|
|
|
|
|
+ details.TotalPrice = total_price
|
|
|
|
|
+ details.PayBalance = paiedCash
|
|
|
|
|
+ details.PaySilver = paiedSilver
|
|
|
|
|
+ details.PayCoupon = totalCoupon
|
|
|
|
|
+ details.Discount = dis_amount
|
|
|
|
|
+ details.ShouldPay = total_weixin
|
|
|
|
|
+
|
|
|
|
|
+ self.Data["json"] = details
|
|
|
|
|
+ self.ServeJSON()
|
|
|
|
|
+}
|