From c3f43c899fba193295477b7fc73258cb06fd36d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 24 Nov 2022 17:12:24 +0800 Subject: [PATCH] 1 --- business/jxstore/cms/order.go | 46 +++++++++++-------------- business/jxstore/financial/financial.go | 10 +++--- business/jxstore/financial/pay.go | 2 +- business/model/dao/dao_order.go | 6 ++-- business/model/order.go | 2 ++ 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/business/jxstore/cms/order.go b/business/jxstore/cms/order.go index 22778047f..10e43459e 100644 --- a/business/jxstore/cms/order.go +++ b/business/jxstore/cms/order.go @@ -144,10 +144,10 @@ func CheckMobileAndFlowCode(mobile, flowCode string) (bool, error) { func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string, isChoose int) (result *financial.WxPayParam, err error) { var ( - temp_PayPrice int - temp_PayMethod int - db = dao.GetDB() - txdb, _ = dao.Begin(db) + tempPayprice int + tempPaymethod int + db = dao.GetDB() + tdb, _ = dao.Begin(db) ) orderInfo, err := dao.GetOrderByID(db, orderID) if err != nil { @@ -169,23 +169,23 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app // 查询用户余额 userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "") if err != nil || userBill == nil { // 出现错误或异常直接使用金钱支付 - temp_PayPrice = orderInfo.PayPrice - temp_PayMethod = model.OrderPayMethodWX + tempPayprice = orderInfo.PayPrice + tempPaymethod = model.OrderPayMethodWX } else { if userBill.AccountBalance-orderInfo.PayPrice >= 0 { // 余额大于支付金额,使用余额支付 switch orderInfo.OrderType { // 1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单,7-话费 - case 2, 5: + case model.OrderTypeMember, model.OrderTypeMemberYear: if err := financial.OnWXPayFinished(orderInfo); err != nil { return nil, err } - case 3: + case model.OrderTypeDelivery: call := &tonglianpayapi.CallBackResult{} call.TrxID = "ziDingYi_" + utils.Int64ToStr(time.Now().Unix()) call.TrxStatus = tonglianpayapi.TrxStatusSuccess if err := financial.OnWxPaySendPage(dao.GetDB(), orderInfo, call, 4); err != nil { return nil, err } - case 7: + case model.OrderTypeMobile: if err := financial.OnWxPayTelephone(orderInfo); err != nil { return nil, err } @@ -193,39 +193,39 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app return nil, errors.New("其他待处理信息,联系管理员") } //账户支出 - if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 1); err != nil { - dao.Rollback(db, txdb) + if err = financial.AddExpendUpdateAccount(tdb, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 1); err != nil { + dao.Rollback(db, tdb) return nil, err } return nil, nil } else { // 混合支付 - temp_PayPrice = orderInfo.PayPrice - userBill.AccountBalance - temp_PayMethod = model.OrderPayMethodMix + tempPayprice = orderInfo.PayPrice - userBill.AccountBalance + tempPaymethod = model.OrderPayMethodMix //账户支出 - if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, userBill.AccountBalance, 1); err != nil { - dao.Rollback(db, txdb) + if err = financial.AddExpendUpdateAccount(tdb, userBill, model.BillTypePayByAccountBalance, userBill.AccountBalance, 1); err != nil { + dao.Rollback(db, tdb) return nil, err } } } } else { // 原价给 - temp_PayPrice = orderInfo.PayPrice - temp_PayMethod = model.OrderPayMethodWX + tempPayprice = orderInfo.PayPrice + tempPaymethod = model.OrderPayMethodWX } - orderInfo.PayPrice = temp_PayPrice - orderInfo.PayMethod = temp_PayMethod + orderInfo.PayPrice = tempPayprice + orderInfo.PayMethod = tempPaymethod dao.UpdateEntity(dao.GetDB(), orderInfo, "PayPrice", "PayMethod") payHandler.Order = orderInfo //如果用户没有对应账单信息就给他生成一条 // 给用户创建一个银行卡账户 userBill, err := dao.GetUserBill(db, orderInfo.UserID, "") if userBill == nil { - err = financial.AddUserBill(txdb, jxutils.GenBillID(), orderInfo.UserID) + err = financial.AddUserBill(tdb, jxutils.GenBillID(), orderInfo.UserID) } - err = payHandler.CreatePay(txdb, appId) + err = payHandler.CreatePay(tdb, appId) return payHandler.WxPayParam, err } @@ -235,12 +235,10 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int, db = dao.GetDB() ) //获取订单信息 - globals.SugarLogger.Debug("begin get pay_by_balance") orderInfo, err := dao.GetOrderByID(db, orderID) if err != nil { return nil, "获取订单信息失败", err } - globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType) //获取用户 会员账户信息 userBill, err := dao.GetUserBill(db, orderInfo.UserID, "") if err != nil { @@ -320,7 +318,6 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int, //(2)用户使用余额,剩余微信支付 totalPrice := orderInfo.PayPrice //订单原价 needPay := totalPrice - userBill.AccountBalance //需支付金额 - globals.SugarLogger.Debug("totalprice=====,needpay=====", totalPrice, needPay) WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay) if err != nil { return nil, "微信支付失败:", err @@ -331,7 +328,6 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int, } if isChoose == model.PayNotChooseBalance { //(3)不选中余额支付 即直接微信支付 - globals.SugarLogger.Debug("进入PayNotChooseBalance==================") WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice) if err != nil { return nil, "微信支付失败:", err diff --git a/business/jxstore/financial/financial.go b/business/jxstore/financial/financial.go index b3a2efd18..905c19f18 100644 --- a/business/jxstore/financial/financial.go +++ b/business/jxstore/financial/financial.go @@ -258,7 +258,7 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) { t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc) order.PayFinishedAt = t1 order.OriginalData = utils.Format4Output(call, true) - payStatus := 0 + payStatus := model.PayStatusNo //order.PayMethod = 2 // 通联微信支付 if call.TrxStatus == tonglianpayapi.TrxStatusSuccess { order.Status = model.OrderStatusFinished @@ -269,19 +269,19 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) { } //充值会员 增加微信支付处理业务 - if (order.OrderType == 2 || order.OrderType == 5) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { + if (order.OrderType == model.OrderTypeMember || order.OrderType == model.OrderTypeMemberYear) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { return OnWXPayFinished(order) } // 充值话费 - if order.OrderType == 7 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { + if order.OrderType == model.OrderTypeMobile && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { return OnWxPayTelephone(order) } // 发快递 - if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { + if order.OrderType == model.OrderTypeDelivery && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { return OnWxPaySendPage(db, order, call, payStatus) } //需要充值到余额方式 购买的 - if order.OrderType == 6 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { + if order.OrderType == model.OrderTypeBalance && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { if err := dao.UpdateUserBill(order.UserID, order.PayPrice); err != nil { return err } diff --git a/business/jxstore/financial/pay.go b/business/jxstore/financial/pay.go index fff722c20..cad1ebff2 100644 --- a/business/jxstore/financial/pay.go +++ b/business/jxstore/financial/pay.go @@ -196,7 +196,7 @@ func OnWxPaySendPage(db *dao.DaoDB, order *model.Order, call *tonglianpayapi.Cal return err } //1-余额,2-微信,5-混合 - if order.PayMethod == 5 { + if order.PayMethod == model.OrderPayMethodMix { userBill, err := dao.GetUserBill(db, order.UserID, "") if err != nil { return err diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 8009e1fee..1d425902b 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -681,7 +681,7 @@ func SetUserVendorOrderStatus(tx orm.TxOrmer, localWayBillID string, status int) // QueryRechargeRecommend 电话充值记录查询 func QueryRechargeRecommend(userId []string, mobile, orderId string, page, pageSize int, start, end time.Time, rechargeStatus int) ([]*model.RechargeUserModelData, int, error) { result := make([]*model.RechargeUserModelData, 0, 0) - sql := `SELECT SQL_CALC_FOUND_ROWS o.*,u.name FROM order o ` + sql := `SELECT SQL_CALC_FOUND_ROWS o.*,u.name FROM ` + "`order`" + ` o` sqlParams := make([]interface{}, 0, 0) sql += ` JOIN user u ON o.user_id = u.user_id WHERE 1=1 ` @@ -701,11 +701,11 @@ func QueryRechargeRecommend(userId []string, mobile, orderId string, page, pageS } if !utils.IsTimeZero(start) { - sql += ` AND o.created_at > ?` + sql += ` AND o.created_at > ? ` sqlParams = append(sqlParams, start) } if !utils.IsTimeZero(end) { - sql += ` AND o.created_at < ?` + sql += ` AND o.created_at < ? ` sqlParams = append(sqlParams, end) } diff --git a/business/model/order.go b/business/model/order.go index ca9a96f7e..fdaefd7a4 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -45,6 +45,8 @@ const ( OrderTypeMemberYear = 5 //充值会员年卡 OrderTypeDelivery = 3 //发快递 OrderTypeDropShipping = 4 //一件代发交钱 + OrderTypeMobile = 7 //充话费 + OrderTypeBalance = 6 //余额充值 ) var (