From 68a75a818463411be2835109831faa4cc1a23dae Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 23 Jan 2024 20:57:30 +0800 Subject: [PATCH] by Robin at 20240123; add consume his --- app/mix/service/logic/vas.go | 25 +++++++++++++++++++++++-- app/mix/service/vasservice.go | 9 ++++++++- dbstruct/vas_mysql.go | 5 +++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 2e14e394..c4d2470c 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -1685,7 +1685,7 @@ func (v *Vas) AlipayCallback(ctx *gin.Context, p *vasproto.AlipayCallbackParamIn } case product.Id == dbstruct.ProductIdMembership: // 解锁会员资格 - _, err = v.UnlockMembership(ctx, util.DerefInt64(order.Mid), product, order) + _, err = v.UnlockMembership(ctx, util.DerefInt64(order.Mid), product, order, wallet) if err != nil { logger.Error("UnlockMembership fail, order: %v", util.ToJson(order)) return @@ -2037,12 +2037,13 @@ func (v *Vas) DealOneCoinOrder(ctx *gin.Context, coinOrderId string) (err error) } // 解锁会员资格 -func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Product, order *dbstruct.Order) (orderId string, err error) { +func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Product, order *dbstruct.Order, wallet *dbstruct.Wallet) (orderId string, err error) { var ( did = util.DerefString(order.Did) productId = product.Id timeNow = time.Now().Unix() + coinPrice = order.GetCoins() ) orderId = util.DerefString(order.ID) @@ -2078,6 +2079,26 @@ func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Pr inviterWallet, _ = v.CheckWalletExist(ctx, inviterMid) } + // 增加金币消费历史(伪记录,仅为对账平插入一条消费流水) + ch := &dbstruct.ConsumeHistory{ + Mid: goproto.Int64(mid), + Uid: goproto.Int64(mid), + Did: goproto.String(did), + Type: goproto.Int32(dbstruct.CHTypeCost), + SType: goproto.Int32(dbstruct.CHSTypeCostMembership), + TypeId: goproto.String(productId), + OrderId: goproto.String(orderId), + Change: goproto.Int64(-coinPrice), + Before: goproto.Int64(util.DerefInt64(wallet.Coins)), + After: goproto.Int64(util.DerefInt64(wallet.Coins) - coinPrice), + Ct: goproto.Int64(timeNow), + } + err = v.store.CreateConsumeHistory(ctx, tx, ch) + if err != nil { + logger.Error("CreateConsumeHistory fail, ch: %v, err: %v", util.ToJson(ch), err) + return + } + // 解锁记录 userVasMembershipUnlock := &dbstruct.UserVasMembershipUnlock{ Mid: goproto.Int64(mid), diff --git a/app/mix/service/vasservice.go b/app/mix/service/vasservice.go index 66455888..7257809c 100644 --- a/app/mix/service/vasservice.go +++ b/app/mix/service/vasservice.go @@ -3,7 +3,6 @@ package service import ( "encoding/base64" "fmt" - "github.com/gin-gonic/gin" "service/api/errcode" "service/api/errs" vasproto "service/api/proto/vas/proto" @@ -12,6 +11,8 @@ import ( "service/dbstruct" "service/library/logger" "service/library/mycrypto" + + "github.com/gin-gonic/gin" ) // 一键解锁 @@ -248,6 +249,12 @@ func (s *Service) chListCost(ctx *gin.Context, chList []*dbstruct.ConsumeHistory case dbstruct.CHSTypeCostRefund: item.Desc = fmt.Sprintf("购买\"%s\"微信退款", util.DerefString(acnt.Name)) item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange()) + case dbstruct.CHSTypeCostMembership: + item.Desc = "购买会员" + item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange()) + if chDB.GetChange() < 0 { + item.Change = fmt.Sprintf("%d金币", chDB.GetChange()) + } } list = append(list, item) } diff --git a/dbstruct/vas_mysql.go b/dbstruct/vas_mysql.go index df488789..2aef9158 100644 --- a/dbstruct/vas_mysql.go +++ b/dbstruct/vas_mysql.go @@ -490,8 +490,9 @@ const ( CHTypeIncome = 3 // 收入明细(钻石) CHTypeWithdraw = 4 // 提现明细(钻石) - CHSTypeCostContact = 10001 // 消费明细,联系方式 - CHSTypeCostRefund = 10002 // 消费明细,金币退款 + CHSTypeCostContact = 10001 // 消费明细,联系方式 + CHSTypeCostRefund = 10002 // 消费明细,金币退款 + CHSTypeCostMembership = 10003 // 消费明细,会员资格解锁(伪金币记录,会员资格解锁中间无转金币过程) CHSTypeChargeUser = 20001 // 充值明细,用户自己冲 CHSTypeChargeOp = 20002 // 充值明细,OP充值