From af2c2fc366ace7cd88eaf76a40ecc16c85b64931 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 28 Jun 2024 16:10:17 +0800 Subject: [PATCH] by Robin at 20240628 --- app/mix/dao/mongo.go | 18 ++++++++++++++++++ app/mix/service/apiservice.go | 10 +++++++++- app/mix/service/logic/single_distribute_his.go | 9 +++++++++ app/mix/service/logic/vas.go | 9 +++++---- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 3a21161d..60afb61c 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -5407,6 +5407,24 @@ func (m *Mongo) ClearSingleDistributeLock(ctx *gin.Context, mid int64) (err erro return nil } +func (m *Mongo) GetAndDecSingleDistributeLock(ctx *gin.Context, mid int64) (singleDistributeLock *dbstruct.SingleDistributeLock, err error) { + col := m.getColSingleDistributeLock() + + change := qmgo.Change{ + Update: qmgo.M{"$inc": qmgo.M{"lock": -1}}, + Upsert: true, + ReturnNew: false, + } + + singleDistributeLockInstance := dbstruct.SingleDistributeLock{} + if err = col.Find(ctx, qmgo.M{"_id": mid}).Apply(change, &singleDistributeLockInstance); err != nil { + logger.Error("change error : %v", err) + return + } + + return &singleDistributeLockInstance, err +} + func (m *Mongo) GetSingleDistributeHisById(ctx *gin.Context, id string) (*dbstruct.SingleDistributeHis, error) { one := &dbstruct.SingleDistributeHis{} col := m.getColSingleDistributeHis() diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 0a834b61..45ae0ba7 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -3497,13 +3497,21 @@ func (s *Service) ApiHvyogoSingleDistribute(ctx *gin.Context, req *hvyogoproto.A // 发起单侧提现申请 diamonds := int64(float64(distributeAmount) / 10) - resp, err := _DefaultVas.UnilaterallyHvyogoWithdrawApply(ctx, &vasproto.UnilaterallyWithdrawApplyReq{ + resp, err, isValidTimeErr := _DefaultVas.UnilaterallyHvyogoWithdrawApply(ctx, &vasproto.UnilaterallyWithdrawApplyReq{ BaseRequest: req.BaseRequest, Diamonds: diamonds, }, extWithdrawFunc) ec, err = errs.DealVasErr(err) if err != nil { logger.Error("WithdrawApply fail, req: %v, err: %v", util.ToJson(req), err) + if isValidTimeErr { //是验证时错误,锁-1 + _, err = _DefaultSingleDistributeHis.GetAndDecLock(ctx, req.BaseRequest.Mid) + if err != nil { + logger.Error("_DefaultSingleDistributeHis GetAndDecLock failed : %v", err) + ec, err = errcode.ErrCodeSingleDistributeHisSrvFail, nil + return + } + } err = nil return } diff --git a/app/mix/service/logic/single_distribute_his.go b/app/mix/service/logic/single_distribute_his.go index 2ed3e7b3..e0d5116a 100644 --- a/app/mix/service/logic/single_distribute_his.go +++ b/app/mix/service/logic/single_distribute_his.go @@ -82,6 +82,15 @@ func (p *SingleDistributeHis) ClearLock(ctx *gin.Context, mid int64) error { return nil } +func (p *SingleDistributeHis) GetAndDecLock(ctx *gin.Context, mid int64) (*dbstruct.SingleDistributeLock, error) { + lock, err := p.store.GetAndDecSingleDistributeLock(ctx, mid) + if err != nil { + logger.Error("DecSingleDistributeLock fail, err: %v", err) + return nil, err + } + return lock, nil +} + func (p *SingleDistributeHis) GetById(ctx *gin.Context, id string) (*dbstruct.SingleDistributeHis, error) { list, err := p.store.GetSingleDistributeHisById(ctx, id) if err != nil { diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index ac0030d8..896a447a 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -3825,19 +3825,20 @@ func (v *Vas) GetRefundRateGroupByMid(ctx *gin.Context, tx *sqlx.Tx) ([]*dbstruc } // 单侧提现申请 -func (v *Vas) UnilaterallyHvyogoWithdrawApply(ctx *gin.Context, req *vasproto.UnilaterallyWithdrawApplyReq, extWithdrawFunc func(orderId string) (*hvyogoproto.SingleDistributeVO, error)) (resp *hvyogoproto.SingleDistributeVO, err error) { +func (v *Vas) UnilaterallyHvyogoWithdrawApply(ctx *gin.Context, req *vasproto.UnilaterallyWithdrawApplyReq, extWithdrawFunc func(orderId string) (*hvyogoproto.SingleDistributeVO, error)) (resp *hvyogoproto.SingleDistributeVO, err error, isValidTimeErr bool) { var ( mid = req.Mid diamonds = req.Diamonds money = req.Diamonds * 10 ) + isValidTimeErr = false // 是否验证时错误 // 今日提现次数 st := util.GetTodayZeroTime().Unix() et := st + 86400 list, _ := v.store.GetWithdrawOrdersByMid(ctx, nil, mid, st, et) if len(list) > 0 { - err = errs.ErrVasOverTodayWithdrawCnt + err, isValidTimeErr = errs.ErrVasOverTodayWithdrawCnt, true return } @@ -3846,11 +3847,11 @@ func (v *Vas) UnilaterallyHvyogoWithdrawApply(ctx *gin.Context, req *vasproto.Un // 检查余额 wallet, _ := v.CheckWalletExist(ctx, nil, mid) if wallet == nil { - err = errs.ErrVasWalletNotExist + err, isValidTimeErr = errs.ErrVasWalletNotExist, true return } if wallet.GetWithdrawDiamonds() < diamonds { - err = errs.ErrVasNoEnoughWithdrawDias + err, isValidTimeErr = errs.ErrVasNoEnoughWithdrawDias, true return }