From 8cd081671907274bf0a47f40ef574fe4525cd03b Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 3 Aug 2022 17:00:54 +0800 Subject: [PATCH] pay --- business/jxstore/cms/order.go | 42 +++++++++++++++++------------- business/jxstore/financial/bill.go | 3 +++ business/model/dao/dao_order.go | 6 +++-- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/business/jxstore/cms/order.go b/business/jxstore/cms/order.go index 766d74a7e..984f0092b 100644 --- a/business/jxstore/cms/order.go +++ b/business/jxstore/cms/order.go @@ -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.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 } //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, PayMethod: 1, //余额支付 } - txDB, _ := dao.Begin(db) - defer func() { - if r := recover(); r != nil { - panic(r) - } - dao.Commit(db, txDB) - }() + //txDB, _ := dao.Begin(db) + //defer func() { + // if r := recover(); r != nil { + // panic(r) + // } + // dao.Commit(db, txDB) + //}() //增加账单 余额减去相应金额 - if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, order.PayPrice, 0); err != nil { - dao.Rollback(db, txDB) - return nil, "使用余额支付失败:", err + money := userBill.AccountBalance - orderInfo.PayPrice + if err = dao.UpdateUserBill(userBill.UserID, money); err != nil { + 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{ - Status: 110, //支付成功 + order.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 { - dao.Rollback(db, txDB) - return nil, "", err - } - dao.Commit(db, txDB) + //if _, err := dao.UpdateEntityTx(txDB, order); err != nil { + // dao.Rollback(db, txDB) + // return nil, "", err + //} + //dao.Commit(db, txDB) } if isChoose == Choose { //(1)用户不使用余额或者余额=0 即直接微信支付 diff --git a/business/jxstore/financial/bill.go b/business/jxstore/financial/bill.go index 396fda19e..e368bb0c6 100644 --- a/business/jxstore/financial/bill.go +++ b/business/jxstore/financial/bill.go @@ -7,6 +7,7 @@ import ( "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/dao" + "git.rosy.net.cn/jx-callback/globals" "github.com/astaxie/beego/client/orm" "time" ) @@ -41,6 +42,7 @@ func AddBillExpend(txDB orm.TxOrmer, billID int64, billType, expendPrice, jobID ExpendPrice: expendPrice, JobID: jobID, } + globals.SugarLogger.Debug("进入AddBillExpend") dao.WrapAddIDCULEntity(billExpend, jxcontext.AdminCtx.GetUserName()) 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) { //1、账户支出增加一条记录 + globals.SugarLogger.Debug("进入AddExpendUpdateAccount") err = AddBillExpend(txDB, userBill.BillID, billType, price, jobID) if err != nil { return err diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 234af6260..1124ad746 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -687,10 +687,12 @@ func SetUserVendorOrderStatus(db *DaoDB, localWayBillID string, status int) (msg } //更新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 "更新Order状态成功", nil } + +//更新order 支付状态和