|
|
@@ -85,11 +85,7 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
|
|
|
}
|
|
|
}
|
|
|
buy_price_total += product.BuyPrice * item.Count
|
|
|
- if payWay == order_model.PAY_WAY_WEIXIN { //微信支付总价
|
|
|
- total_price += product.Price * item.Count
|
|
|
- } else if payWay == order_model.PAY_WAY_BALANCE { //代金券支付总价
|
|
|
- total_price += product.Price * item.Count
|
|
|
- }
|
|
|
+ total_price += product.Price * item.Count
|
|
|
SaleNumsMap[product.Id] = item.Count
|
|
|
}
|
|
|
order.PayWay = payWay
|
|
|
@@ -98,46 +94,52 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
|
|
|
order.Address = fmt.Sprintf("%s%s%s%s", address.Province, address.City, address.District, address.Address)
|
|
|
order.BuyPrice = buy_price_total
|
|
|
order.TotalPrice = total_price
|
|
|
-
|
|
|
- switch payWay { // 1.代金券购买 2.微信支付
|
|
|
- case pay_model.PAYWAY_BALANCE: // 代金券购买
|
|
|
-
|
|
|
- curWxUser := user_model.GetWxUserById(wxUId, false)
|
|
|
- if curWxUser == nil {
|
|
|
- self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
- }
|
|
|
- //黑名单用户
|
|
|
- curUser := user_model.GetUserById(curWxUser.UserId, false)
|
|
|
- if curUser != nil && curUser.IsBlackUser == 1 {
|
|
|
- self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
- }
|
|
|
- //再次增加订单状态判断
|
|
|
- if order.Status != order_model.STATUS_UNPAY {
|
|
|
- self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
- }
|
|
|
-
|
|
|
- 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
|
|
|
+ //支付信息判断
|
|
|
+ curWxUser := user_model.GetWxUserById(wxUId, false)
|
|
|
+ if curWxUser == nil {
|
|
|
+ self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
+ }
|
|
|
+ //黑名单用户
|
|
|
+ curUser := user_model.GetUserById(curWxUser.UserId, false)
|
|
|
+ if curUser != nil && curUser.IsBlackUser == 1 {
|
|
|
+ self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
+ }
|
|
|
+ //再次增加订单状态判断
|
|
|
+ if order.Status != order_model.STATUS_UNPAY {
|
|
|
+ self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
+ }
|
|
|
+ //若账户有代金券则优先抵扣代金券
|
|
|
+ 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 {
|
|
|
if userLeftBalanceCount < tp {
|
|
|
- self.ReturnError(403, apps.BalanceNotEnough, "", nil)
|
|
|
- }
|
|
|
-
|
|
|
- if tp > 0 {
|
|
|
- source := balance_model.BALANCE_SOURCE_EXCHANGE_PRODUCT
|
|
|
- remark := fmt.Sprintf("代金券兑换商品")
|
|
|
- new(balance_model.Balance).Create(wxUId, uId, -tp, source, oId, remark)
|
|
|
+ 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
|
|
|
+ switch needWx { // 1.true需要微信支付,2.false不需要微信支付
|
|
|
+ case false: // 代金券抵扣完毕
|
|
|
//更新订单状态
|
|
|
order.Status = order_model.STATUS_PROCESSING
|
|
|
order.PaiedAt = time.Now().Unix()
|
|
|
order.PaiedTime = time.Now()
|
|
|
- order.PaiedPrice = order.TotalPrice
|
|
|
+ order.PaiedPrice = 0
|
|
|
order.PayWay = pay_model.PAYWAY_BALANCE
|
|
|
order.Source = source
|
|
|
order.Save()
|
|
|
@@ -162,18 +164,16 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
|
|
|
//wxUser := user_model.GetWxUserById(order.WxUserId, true)
|
|
|
//go sendInviterBenefit(wxUser, order.OrderId, user_model.SOURCE_PRODUCT_BENEFIT)
|
|
|
payUrl, payData = fmt.Sprintf("%s?order_id=%s", returnUrl, order.OrderId), nil
|
|
|
- result := PayUrl{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})
|
|
|
- case pay_model.PAYWAY_WEIXINPAY: // 微信支付
|
|
|
+ case true: // 微信支付
|
|
|
|
|
|
wxUser := self.GetCurrentWxUser(false)
|
|
|
-
|
|
|
order.Contact = address.Contact
|
|
|
order.Tel = address.Tel
|
|
|
order.Address = fmt.Sprintf("%s%s%s%s", address.Province, address.City, address.District, address.Address)
|
|
|
order.Source = source
|
|
|
order.Save()
|
|
|
-
|
|
|
if order.Source == order_model.SOURCE_XCX { //小程序微信支付
|
|
|
freight := order_model.FREIGHT
|
|
|
if order.TotalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
|
|
|
@@ -186,9 +186,10 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
|
|
|
|
|
|
//返回数据
|
|
|
type PayData struct {
|
|
|
+ NeedWx bool `json:"need_wx"`
|
|
|
PayData map[string]string `json:"pay_data"`
|
|
|
}
|
|
|
- self.Data["json"] = &PayData{PayData: payData}
|
|
|
+ self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
|
|
|
} else { //公众号微信支付
|
|
|
|
|
|
@@ -203,9 +204,10 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
|
|
|
|
|
|
//返回数据
|
|
|
type PayData struct {
|
|
|
+ NeedWx bool `json:"need_wx"`
|
|
|
PayData map[string]string `json:"pay_data"`
|
|
|
}
|
|
|
- self.Data["json"] = &PayData{PayData: payData}
|
|
|
+ self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
}
|
|
|
default:
|
|
|
beego.BeeLogger.Error("pay way not match, payway:%s", payWay)
|