From eba9e2c25089e4196b94c5d8148f5f41ea35bc11 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Fri, 22 Jul 2022 11:32:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BE=AE=E4=BF=A1=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=85=85=E5=80=BC=E4=BC=9A=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/financial/financial.go | 2 +- business/jxstore/financial/pay.go | 40 ++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/business/jxstore/financial/financial.go b/business/jxstore/financial/financial.go index ca90a8eeb..efa068399 100644 --- a/business/jxstore/financial/financial.go +++ b/business/jxstore/financial/financial.go @@ -270,7 +270,7 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) { } //充值会员 增加微信支付处理业务 if order.OrderType == 2 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { - if err := OnPayFinished(order); err != nil { + if err := OnWXPayFinished(order); err != nil { return err } } diff --git a/business/jxstore/financial/pay.go b/business/jxstore/financial/pay.go index 293446343..1584983aa 100644 --- a/business/jxstore/financial/pay.go +++ b/business/jxstore/financial/pay.go @@ -2,10 +2,10 @@ package financial import ( "fmt" - "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/business/jxstore/cms" "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" @@ -102,3 +102,41 @@ func OnCashFinished(order *model.Order) (err error) { globals.SugarLogger.Debugf("OnCashFinished end modify account ...") return err } + +//微信支付充值会员 +func OnWXPayFinished(order *model.Order) (err error) { + var ( + db = dao.GetDB() + ctx *jxcontext.Context + ) + globals.SugarLogger.Debugf("OnWXPayFinished begin modify account order: %v", utils.Format4Output(order, false)) + txDB, _ := dao.Begin(db) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db, txDB) + panic(r) + } + }() + //如果用户没有对应账单信息就给他生成一条 + userBill, err := dao.GetUserBill(db, order.UserID, "") + if userBill == nil { + globals.SugarLogger.Debugf("OnPayFinished 未找到该用户的账单 order: %v", utils.Format4Output(order, false)) + return fmt.Errorf("未找到该用户的账单!%v", order.UserID) + } + //获取用户会员信息 + userMember, err := dao.GetUserMember(db, order.UserID, model.UserStatusNormal) + //根据订单类型来操作账户 + switch order.Type { + case model.OrderTpyeMember: + //微信支付充值会员 + if _, err = cms.InvestMember(ctx, userMember[0].MemberType, order.UserID, true); err != nil { + dao.Rollback(db, txDB) + } + default: + globals.SugarLogger.Debugf("OnPayFinished 暂不支持此订单类型 order: %v", utils.Format4Output(order, false)) + return fmt.Errorf("暂不支持此订单类型!") + } + dao.Commit(db, txDB) + globals.SugarLogger.Debugf("OnWXPayFinished end modify account ...") + return err +}