|
|
@@ -110,29 +110,35 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
|
|
|
}
|
|
|
//若账户有代金券则优先抵扣代金券
|
|
|
needWx := true
|
|
|
- totalCoupon := int64(0)
|
|
|
- userLeftBalanceCount := balance_model.GetUserTotalBalance(wxUId)
|
|
|
- tp := order.TotalPrice
|
|
|
- freight := order_model.FREIGHT
|
|
|
- if tp >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
|
|
|
- freight = int64(0)
|
|
|
- }
|
|
|
- tp += freight
|
|
|
- if order.OrderType != order_model.ORDER_TYPE_SEKILL && useCoupon {
|
|
|
- if userLeftBalanceCount < tp {
|
|
|
- totalCoupon = userLeftBalanceCount
|
|
|
- } else {
|
|
|
- needWx = false
|
|
|
- totalCoupon = tp
|
|
|
+ //订单第一次支付
|
|
|
+ if len(order.PayWay) == 0 {
|
|
|
+ totalCoupon := int64(0)
|
|
|
+ userLeftBalanceCount := balance_model.GetUserTotalBalance(wxUId)
|
|
|
+ tp := order.TotalPrice
|
|
|
+ freight := order_model.FREIGHT
|
|
|
+ if tp >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
|
|
|
+ freight = int64(0)
|
|
|
}
|
|
|
+ tp += freight
|
|
|
+ if order.OrderType != order_model.ORDER_TYPE_SEKILL && useCoupon {
|
|
|
+ if userLeftBalanceCount < tp {
|
|
|
+ totalCoupon = userLeftBalanceCount
|
|
|
+ } else {
|
|
|
+ needWx = false
|
|
|
+ totalCoupon = tp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //先扣减代金券
|
|
|
+ if totalCoupon > 0 {
|
|
|
+ source := balance_model.BALANCE_SOURCE_EXCHANGE_PRODUCT
|
|
|
+ remark := fmt.Sprintf("代金券兑换商品")
|
|
|
+ new(balance_model.Balance).Create(wxUId, uId, -totalCoupon, source, oId, remark)
|
|
|
+ }
|
|
|
+ order.CouponPrice = totalCoupon
|
|
|
+ } else {
|
|
|
+
|
|
|
}
|
|
|
- //先扣减代金券
|
|
|
- if totalCoupon > 0 {
|
|
|
- source := balance_model.BALANCE_SOURCE_EXCHANGE_PRODUCT
|
|
|
- remark := fmt.Sprintf("代金券兑换商品")
|
|
|
- new(balance_model.Balance).Create(wxUId, uId, -totalCoupon, source, oId, remark)
|
|
|
- }
|
|
|
- order.CouponPrice = totalCoupon
|
|
|
+
|
|
|
switch needWx { // 1.true需要微信支付,2.false不需要微信支付
|
|
|
case false: // 代金券抵扣完毕
|
|
|
//更新订单状态
|