mixpay优化
This commit is contained in:
@@ -108,10 +108,10 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
|||||||
//支付金额<原金额
|
//支付金额<原金额
|
||||||
if payPrice < order.PayPrice {
|
if payPrice < order.PayPrice {
|
||||||
temp_PayPrice = payPrice
|
temp_PayPrice = payPrice
|
||||||
temp_PayMethod = 5
|
temp_PayMethod = model.OrderPayMethodMix
|
||||||
} else {
|
} else {
|
||||||
temp_PayPrice = orderInfo.PayPrice
|
temp_PayPrice = orderInfo.PayPrice
|
||||||
temp_PayMethod = 2
|
temp_PayMethod = model.OrderPayMethodWX
|
||||||
}
|
}
|
||||||
//微信支付实际金额更新到数据库
|
//微信支付实际金额更新到数据库
|
||||||
if _, err := dao.SetOrderStatus(txDB, temp_PayPrice, temp_PayMethod, orderInfo.Status, orderID); err != nil {
|
if _, err := dao.SetOrderStatus(txDB, temp_PayPrice, temp_PayMethod, orderInfo.Status, orderID); err != nil {
|
||||||
@@ -136,20 +136,13 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
|||||||
return payHandler.WxPayParam, err
|
return payHandler.WxPayParam, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
NotPay = 2 //订单待支付
|
|
||||||
AlreadyPay = 1 //订单已支付
|
|
||||||
Choose = 1 //选中余额支付
|
|
||||||
NotChoose = -1 //未选中余额支付
|
|
||||||
)
|
|
||||||
|
|
||||||
//余额支付 微信补差值
|
//余额支付 微信补差值
|
||||||
func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int, vendorPayType, appID string) (*financial.WxPayParam, string, error) {
|
func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int, vendorPayType, appID string) (*financial.WxPayParam, string, error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
)
|
)
|
||||||
//获取订单信息
|
//获取订单信息
|
||||||
globals.SugarLogger.Debug("begin get order_info")
|
globals.SugarLogger.Debug("begin get pay_by_balance")
|
||||||
orderInfo, err := dao.GetOrderByID(db, orderID)
|
orderInfo, err := dao.GetOrderByID(db, orderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "获取订单信息失败", err
|
return nil, "获取订单信息失败", err
|
||||||
@@ -160,19 +153,19 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "获取用户会员账户余额失败", err
|
return nil, "获取用户会员账户余额失败", err
|
||||||
}
|
}
|
||||||
if orderInfo.Status == NotPay {
|
if orderInfo.Status == model.OrderNotPay {
|
||||||
//需要充值余额支付的方式//todo 后续添加
|
//需要充值余额支付的方式//todo 后续添加
|
||||||
if orderInfo.OrderType == 6 {
|
//if orderInfo.OrderType == 6 {
|
||||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
// WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, "微信支付失败:", err
|
// return nil, "微信支付失败:", err
|
||||||
}
|
// }
|
||||||
return WxPayParam, "", err
|
// return WxPayParam, "", err
|
||||||
}
|
//}
|
||||||
// (3)使用余额且 余额大于支付金额
|
|
||||||
//快递混合支付
|
//快递混合支付
|
||||||
if orderInfo.OrderType == 3 {
|
if orderInfo.OrderType == model.OrderTypeDelivery {
|
||||||
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == Choose {
|
// (3)使用余额且 余额大于支付金额
|
||||||
|
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == model.PayChooseBalance {
|
||||||
globals.SugarLogger.Debug("进入余额支付部分")
|
globals.SugarLogger.Debug("进入余额支付部分")
|
||||||
txDB, _ := dao.Begin(db)
|
txDB, _ := dao.Begin(db)
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -221,30 +214,35 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
|||||||
} else {
|
} else {
|
||||||
return nil, "order/user_vendor_order更新状态出错", nil
|
return nil, "order/user_vendor_order更新状态出错", nil
|
||||||
}
|
}
|
||||||
|
} else if isChoose == model.PayChooseBalance {
|
||||||
}
|
//(1)用户选中余额 但余额<订单总价 需混合微信支付
|
||||||
if isChoose == Choose {
|
|
||||||
//(1)用户不使用余额或者余额=0 即直接微信支付
|
|
||||||
if userBill.AccountBalance == 0 {
|
if userBill.AccountBalance == 0 {
|
||||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "微信支付失败:", err
|
return nil, "微信支付失败:", err
|
||||||
}
|
}
|
||||||
return WxPayParam, "", err
|
return WxPayParam, "", err
|
||||||
}
|
} else if userBill.AccountBalance > 0 {
|
||||||
//(2)用户使用余额,剩余微信支付
|
//(2)用户使用余额,剩余微信支付
|
||||||
totalPrice := orderInfo.PayPrice //订单原价
|
totalPrice := orderInfo.PayPrice //订单原价
|
||||||
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
|
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
|
||||||
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
||||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
|
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "微信支付失败:", err
|
return nil, "微信支付失败:", err
|
||||||
|
}
|
||||||
|
return WxPayParam, "", err
|
||||||
}
|
}
|
||||||
return WxPayParam, "", err
|
|
||||||
}
|
}
|
||||||
|
} else if isChoose == model.PayNotChooseBalance {
|
||||||
|
//(4)不选中余额支付 即直接微信支付
|
||||||
|
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "微信支付失败:", err
|
||||||
|
}
|
||||||
|
return WxPayParam, "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,17 @@ const (
|
|||||||
PayType4Member = 1 // 购买会员
|
PayType4Member = 1 // 购买会员
|
||||||
PayType4Recharge = 2 // 充值余额
|
PayType4Recharge = 2 // 充值余额
|
||||||
PayType4Express = 3 // 支付快递
|
PayType4Express = 3 // 支付快递
|
||||||
|
|
||||||
|
//订单支付方式
|
||||||
|
OrderPayMethodBalance = 1 //余额支付
|
||||||
|
OrderPayMethodWX = 2 //微信支付
|
||||||
|
OrderPayMethodMix = 5 //余额+微信混合支付
|
||||||
|
|
||||||
|
OrderNotPay = 2 //订单待支付
|
||||||
|
PayChooseBalance = 1 //选中余额支付
|
||||||
|
PayNotChooseBalance = -1 //不选中余额支付
|
||||||
|
//UserVendorOrder订单状态
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -727,7 +727,7 @@ func TryAgainOrder(ctx *jxcontext.Context, oldNo string) (*model.UserVendorOrder
|
|||||||
Bulk: utils.Int2Float64(fee[fmt.Sprintf("%d", oldOrder.Type)].Data.Bulk),
|
Bulk: utils.Int2Float64(fee[fmt.Sprintf("%d", oldOrder.Type)].Data.Bulk),
|
||||||
ServiceCharge: fee[fmt.Sprintf("%d", oldOrder.Type)].Data.ServiceCharge,
|
ServiceCharge: fee[fmt.Sprintf("%d", oldOrder.Type)].Data.ServiceCharge,
|
||||||
GuarantFee: fee[fmt.Sprintf("%d", oldOrder.Type)].Data.GuarantFee,
|
GuarantFee: fee[fmt.Sprintf("%d", oldOrder.Type)].Data.GuarantFee,
|
||||||
OriginalFee: utils.Int2Float64(fee[fmt.Sprintf("%d", oldOrder.Type)].Data.OriginalFee),
|
OriginalFee: utils.MustInterface2Float64(fee[fmt.Sprintf("%d", oldOrder.Type)].Data.OriginalFee),
|
||||||
Increment: fee[fmt.Sprintf("%d", oldOrder.Type)].Data.IncrementFee,
|
Increment: fee[fmt.Sprintf("%d", oldOrder.Type)].Data.IncrementFee,
|
||||||
}
|
}
|
||||||
return CreateWayOrder(ctx, param, oldOrder.UserId)
|
return CreateWayOrder(ctx, param, oldOrder.UserId)
|
||||||
|
|||||||
Reference in New Issue
Block a user