This commit is contained in:
richboo111
2022-08-03 17:00:54 +08:00
parent d7c472372e
commit 8cd0816719
3 changed files with 31 additions and 20 deletions

View File

@@ -117,7 +117,7 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
globals.SugarLogger.Debug("检验初始数据情况", order.OrderID, order.PayMethod) globals.SugarLogger.Debug("检验初始数据情况", order.OrderID, order.PayMethod)
globals.SugarLogger.Debug("检验初始数据情况", order.PayPrice) globals.SugarLogger.Debug("检验初始数据情况", order.PayPrice)
//微信支付实际金额更新到数据库 //微信支付实际金额更新到数据库
if _, err := dao.SetOrderStatus(temp_PayPrice, temp_PayMethod, orderID); err != nil { if _, err := dao.SetOrderStatus(temp_PayPrice, temp_PayMethod, orderInfo.Status, orderID); err != nil {
return nil, err return nil, err
} }
//if _, err := dao.UpdateEntityTx(txDB, order); err != nil { //if _, err := dao.UpdateEntityTx(txDB, order); err != nil {
@@ -189,27 +189,33 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
PayPrice: orderInfo.PayPrice, PayPrice: orderInfo.PayPrice,
PayMethod: 1, //余额支付 PayMethod: 1, //余额支付
} }
txDB, _ := dao.Begin(db) //txDB, _ := dao.Begin(db)
defer func() { //defer func() {
if r := recover(); r != nil { // if r := recover(); r != nil {
panic(r) // panic(r)
} // }
dao.Commit(db, txDB) // dao.Commit(db, txDB)
}() //}()
//增加账单 余额减去相应金额 //增加账单 余额减去相应金额
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, order.PayPrice, 0); err != nil { money := userBill.AccountBalance - orderInfo.PayPrice
dao.Rollback(db, txDB) if err = dao.UpdateUserBill(userBill.UserID, money); err != nil {
return nil, "使用余额支付失败", err return nil, "余额支付失败", err
} }
//if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil {
// //dao.Rollback(db, txDB)
// return nil, "使用余额支付失败:", err
//}
//更新订单状态 //更新订单状态
order = &model.Order{ order.Status = 110
Status: 110, //支付成功 order.PayMethod = 1
if _, err := dao.SetOrderStatus(orderInfo.PayPrice, 1, 110, orderID); err != nil {
return nil, "更新order状态失败", err
} }
if _, err := dao.UpdateEntityTx(txDB, order, "Status"); err != nil { //if _, err := dao.UpdateEntityTx(txDB, order); err != nil {
dao.Rollback(db, txDB) // dao.Rollback(db, txDB)
return nil, "", err // return nil, "", err
} //}
dao.Commit(db, txDB) //dao.Commit(db, txDB)
} }
if isChoose == Choose { if isChoose == Choose {
//1用户不使用余额或者余额=0 即直接微信支付 //1用户不使用余额或者余额=0 即直接微信支付

View File

@@ -7,6 +7,7 @@ import (
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
"github.com/astaxie/beego/client/orm" "github.com/astaxie/beego/client/orm"
"time" "time"
) )
@@ -41,6 +42,7 @@ func AddBillExpend(txDB orm.TxOrmer, billID int64, billType, expendPrice, jobID
ExpendPrice: expendPrice, ExpendPrice: expendPrice,
JobID: jobID, JobID: jobID,
} }
globals.SugarLogger.Debug("进入AddBillExpend")
dao.WrapAddIDCULEntity(billExpend, jxcontext.AdminCtx.GetUserName()) dao.WrapAddIDCULEntity(billExpend, jxcontext.AdminCtx.GetUserName())
return dao.CreateEntityTx(txDB, billExpend) return dao.CreateEntityTx(txDB, billExpend)
} }
@@ -68,6 +70,7 @@ func GetUserBillDetail(ctx *jxcontext.Context, userID, fromTime, toTime string,
func AddExpendUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) { func AddExpendUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) {
//1、账户支出增加一条记录 //1、账户支出增加一条记录
globals.SugarLogger.Debug("进入AddExpendUpdateAccount")
err = AddBillExpend(txDB, userBill.BillID, billType, price, jobID) err = AddBillExpend(txDB, userBill.BillID, billType, price, jobID)
if err != nil { if err != nil {
return err return err

View File

@@ -687,10 +687,12 @@ func SetUserVendorOrderStatus(db *DaoDB, localWayBillID string, status int) (msg
} }
//更新order 价格和状态 //更新order 价格和状态
func SetOrderStatus(payPrice, payMethod int, orderID string) (string, error) { func SetOrderStatus(payPrice, payMethod, status int, orderID string) (string, error) {
if _, err := ExecuteSQL(GetDB(), "UPDATE `order` SET pay_price = ?,pay_method= ? WHERE order_id = ? ", []interface{}{payPrice, payMethod, orderID}...); err != nil { if _, err := ExecuteSQL(GetDB(), "UPDATE `order` SET pay_price = ?,pay_method= ?,status=? WHERE order_id = ? ", []interface{}{payPrice, payMethod, status, orderID}...); err != nil {
return "", err return "", err
} }
return "更新Order状态成功", nil return "更新Order状态成功", nil
} }
//更新order 支付状态和