This commit is contained in:
richboo111
2022-07-28 17:37:25 +08:00
parent 46c422aee5
commit 64178e8bdf
2 changed files with 19 additions and 22 deletions

View File

@@ -108,9 +108,7 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
}() }()
// 给用户创建一个银行卡账户 // 给用户创建一个银行卡账户
globals.SugarLogger.Debugf("createbill begin……")
userBill, err := dao.GetUserBill(db, order.UserID, "") userBill, err := dao.GetUserBill(db, order.UserID, "")
globals.SugarLogger.Debug("user_bill.billID……", userBill.BillID)
if userBill == nil { if userBill == nil {
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID) err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
} }
@@ -127,7 +125,7 @@ var (
) )
//余额支付 微信补差值 //余额支付 微信补差值
func PayByBalance(ctx *jxcontext.Context, orderID string, restPrice, payType int, vendorPayType, appID string) (errMsg string, err error) { func PayByBalance(ctx *jxcontext.Context, orderID string, restPrice, payType int, vendorPayType, appID string) (*financial.WxPayParam, string, error) {
var ( var (
db = dao.GetDB() db = dao.GetDB()
//wxPayParam *financial.WxPayParam //wxPayParam *financial.WxPayParam
@@ -136,14 +134,14 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, restPrice, payType int
globals.SugarLogger.Debug("begin get order+info") globals.SugarLogger.Debug("begin get order+info")
orderInfo, err := dao.GetOrderByID(db, orderID) orderInfo, err := dao.GetOrderByID(db, orderID)
if err != nil { if err != nil {
return "获取订单信息失败", err return nil, "获取订单信息失败", err
} }
globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType) globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType)
//获取用户 会员账户信息 //获取用户 会员账户信息
globals.SugarLogger.Debug("开始获取会员信息") globals.SugarLogger.Debug("开始获取会员信息")
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "") userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
if err != nil { if err != nil {
return "获取用户会员账户余额失败", err return nil, "获取用户会员账户余额失败", err
} }
txDB, _ := dao.Begin(db) txDB, _ := dao.Begin(db)
defer func() { defer func() {
@@ -161,7 +159,7 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, restPrice, payType int
if userBill.AccountBalance > orderInfo.PayPrice && userBill.AccountBalance-orderInfo.PayPrice > 0 { if userBill.AccountBalance > orderInfo.PayPrice && userBill.AccountBalance-orderInfo.PayPrice > 0 {
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil { if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil {
dao.Rollback(db, txDB) dao.Rollback(db, txDB)
return "使用余额支付失败:", err return nil, "使用余额支付失败:", err
} }
orderInfo.Status = AlreadyPay orderInfo.Status = AlreadyPay
} }
@@ -172,32 +170,31 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, restPrice, payType int
globals.SugarLogger.Debug("进入混合支付部分") globals.SugarLogger.Debug("进入混合支付部分")
orderInfo.PayPrice = restPrice orderInfo.PayPrice = restPrice
globals.SugarLogger.Debug("orderInfo.PayPrice=================", orderInfo.PayPrice) globals.SugarLogger.Debug("orderInfo.PayPrice=================", orderInfo.PayPrice)
if _, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID); err != nil { //修改余额为0
//dao.Rollback(db, txDB)
globals.SugarLogger.Debug("err=================", err)
return "微信支付失败:", err
}
//支付成功后修改余额为0
if err := dao.UpdateUserBill(orderInfo.UserID, 0); err != nil { if err := dao.UpdateUserBill(orderInfo.UserID, 0); err != nil {
globals.SugarLogger.Debug("支付后修改余额失败") globals.SugarLogger.Debug("修改余额失败")
dao.Rollback(db, txDB) dao.Rollback(db, txDB)
return "余额修改失败:", err return nil, "余额修改失败:", err
} }
//增加一条用户账单 //增加用户账单
globals.SugarLogger.Debug("开始创建用户账单") globals.SugarLogger.Debug("开始创建用户账单")
globals.SugarLogger.Debug("微信需支付", orderInfo.PayPrice) globals.SugarLogger.Debug("微信需支付", orderInfo.PayPrice)
if err = financial.AddBillExpend(txDB, userBill.BillID, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil { if err = financial.AddBillExpend(txDB, userBill.BillID, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil {
globals.SugarLogger.Debug("创建账单失败") globals.SugarLogger.Debug("创建账单失败")
dao.Rollback(db, txDB) dao.Rollback(db, txDB)
return "创建账单失败", err return nil, "创建账单失败", err
} }
return "混合支付成功", err WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID)
if err != nil {
dao.Rollback(db, txDB)
globals.SugarLogger.Debug("err=================", err)
return nil, "微信支付失败:", err
}
dao.Commit(db, txDB)
return WxPayParam, "", err
} }
dao.Commit(db, txDB)
} }
return "", err return nil, "", err
} }
func Cash(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (errCode string, err error) { func Cash(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (errCode string, err error) {

View File

@@ -44,7 +44,7 @@ func (c *OrderController) Pay() {
// @router /PayByBalance [post] // @router /PayByBalance [post]
func (c *OrderController) PayByBalance() { func (c *OrderController) PayByBalance() {
c.callPayByBalance(func(params *tOrderPayByBalanceParams) (interface{}, string, error) { c.callPayByBalance(func(params *tOrderPayByBalanceParams) (interface{}, string, error) {
retVal, err := cms.PayByBalance(params.Ctx, params.OrderID, params.RestPrice, params.PayType, params.VendorPayType, params.AppId) retVal, _, err := cms.PayByBalance(params.Ctx, params.OrderID, params.RestPrice, params.PayType, params.VendorPayType, params.AppId)
return retVal, "", err return retVal, "", err
}) })
} }