This commit is contained in:
richboo111
2022-09-20 17:40:06 +08:00
parent 40ab9dc95d
commit eaab50c8b2

View File

@@ -165,76 +165,80 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
//快递混合支付
if orderInfo.OrderType == model.OrderTypeDelivery {
// (3)使用余额且 余额大于支付金额
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == model.PayChooseBalance {
globals.SugarLogger.Debug("进入余额支付部分")
txDB, _ := dao.Begin(db)
defer func() {
if r := recover(); r != nil {
panic(r)
if isChoose == model.PayChooseBalance {
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice {
globals.SugarLogger.Debug("进入余额支付部分")
txDB, _ := dao.Begin(db)
defer func() {
if r := recover(); r != nil {
panic(r)
}
}()
//增加账单 余额减去相应金额
money := userBill.AccountBalance - orderInfo.PayPrice
if err = dao.UpdateUserBill(userBill.UserID, money); err != nil {
return nil, "余额支付失败", err
}
}()
//增加账单 余额减去相应金额
money := userBill.AccountBalance - orderInfo.PayPrice
if err = dao.UpdateUserBill(userBill.UserID, money); err != nil {
return nil, "余额支付失败", err
}
//更新订单状态
orderInfo.PayMethod = 1
orderInfo.Status = 110
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "PayMethod"); err != nil {
dao.Rollback(db, txDB)
return nil, "更新order.PayMethod状态失败", err
}
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "Status"); err != nil {
dao.Rollback(db, txDB)
return nil, "更新order.Status状态失败", err
}
//todo 后续需增加其他订单类型
//(1)更新快递 订单状态
temp_vendor_status := 4
if _, err := dao.SetUserVendorOrderStatus(txDB, orderInfo.OrderID, temp_vendor_status); err != nil {
dao.Rollback(db, txDB)
return nil, "更新user_vendor_order状态失败", err
}
dao.Commit(db, txDB)
//再次从数据库获取order、userOrder
orderNew, err := dao.GetOrderByID(db, orderID)
if err != nil {
return nil, "获取orderNew失败", err
}
userOrder, err := dao.GetUserVendorOrder(db, orderNew.UserID, orderNew.OrderID)
if err != nil {
return nil, "获取userOrder失败", err
}
//快递单 同步到qbd
if orderNew.Status == 110 && userOrder.OrderStatus == 4 {
if err := q_bida.CreateOrder2QBiDa(userOrder, orderInfo.OrderID); err != nil {
return nil, "", err
//更新订单状态
orderInfo.PayMethod = 1
orderInfo.Status = 110
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "PayMethod"); err != nil {
dao.Rollback(db, txDB)
return nil, "更新order.PayMethod状态失败", err
}
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "Status"); err != nil {
dao.Rollback(db, txDB)
return nil, "更新order.Status状态失败", err
}
//todo 后续需增加其他订单类型
//(1)更新快递 订单状态
temp_vendor_status := 4
if _, err := dao.SetUserVendorOrderStatus(txDB, orderInfo.OrderID, temp_vendor_status); err != nil {
dao.Rollback(db, txDB)
return nil, "更新user_vendor_order状态失败", err
}
dao.Commit(db, txDB)
//再次从数据库获取order、userOrder
orderNew, err := dao.GetOrderByID(db, orderID)
if err != nil {
return nil, "获取orderNew失败", err
}
userOrder, err := dao.GetUserVendorOrder(db, orderNew.UserID, orderNew.OrderID)
if err != nil {
return nil, "获取userOrder失败", err
}
//快递单 同步到qbd
if orderNew.Status == 110 && userOrder.OrderStatus == 4 {
if err := q_bida.CreateOrder2QBiDa(userOrder, orderInfo.OrderID); err != nil {
return nil, "", err
}
} else {
return nil, "order/user_vendor_order更新状态出错", nil
}
} else {
return nil, "order/user_vendor_order更新状态出错", nil
}
} else if isChoose == model.PayChooseBalance && userBill.AccountBalance < orderInfo.PayPrice {
//1用户选中余额 但余额<订单总价 需混合微信支付
if userBill.AccountBalance == 0 {
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
if err != nil {
return nil, "微信支付失败:", err
}
return WxPayParam, "", err
} else if userBill.AccountBalance > 0 {
//2用户使用余额剩余微信支付
totalPrice := orderInfo.PayPrice //订单原价
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
needPay := totalPrice - userBill.AccountBalance //需支付金额
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
//else if isChoose == model.PayChooseBalance && userBill.AccountBalance < orderInfo.PayPrice {
//1用户选中余额 但余额<订单总价 需混合微信支付
if userBill.AccountBalance == 0 {
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
if err != nil {
return nil, "微信支付失败:", err
}
return WxPayParam, "", err
} else if userBill.AccountBalance > 0 {
//2用户使用余额剩余微信支付
totalPrice := orderInfo.PayPrice //订单原价
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
needPay := totalPrice - userBill.AccountBalance //需支付金额
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
if err != nil {
return nil, "微信支付失败:", err
}
return WxPayParam, "", err
}
}
}
} else if isChoose == model.PayNotChooseBalance {
}
if isChoose == model.PayNotChooseBalance {
//4不选中余额支付 即直接微信支付
globals.SugarLogger.Debug("进入PayNotChooseBalance==================")
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)