by Robin at 20240628

This commit is contained in:
Leufolium 2024-06-28 16:10:17 +08:00
parent 2e9177c65c
commit af2c2fc366
4 changed files with 41 additions and 5 deletions

View File

@ -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()

View File

@ -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
}

View File

@ -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 {

View File

@ -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
}