@@ -7,8 +7,8 @@ const ( | |||||
PlanRewardCfgCacheKey = "%s:plan_reward_cfg" | PlanRewardCfgCacheKey = "%s:plan_reward_cfg" | ||||
UnionSetCacheCfg = "%s:union_set_cfg:%s" // 联盟设置缓存key | UnionSetCacheCfg = "%s:union_set_cfg:%s" // 联盟设置缓存key | ||||
UserFinValidUpdateLock = "%s:user_fin_valid_update_lock:%s" // 用户余额更新锁(能拿到锁才能更新余额) | |||||
UserVirtualAmountUpdateLock = "%s:user_virtual_amount_update_lock:%s" // 用户虚拟币更新锁(能拿到锁才能更新余额) | |||||
UserFinValidUpdateLock = "%s:user_fin_valid_update_lock:%s" // 用户余额更新锁(能拿到锁才能更新余额) | |||||
UserVirtualAmountUpdateLock = "%s:user_virtual_amount_update_lock:%s:%s" // 用户虚拟币更新锁(能拿到锁才能更新余额) | |||||
WithdrawApplyQueueListKey = "withdraw_apply_queue" // 提现队列 | WithdrawApplyQueueListKey = "withdraw_apply_queue" // 提现队列 | ||||
@@ -563,7 +563,7 @@ func DealUserCoinForGreen(session *xorm.Session, req md.DealUserCoinReq) (err er | |||||
} | } | ||||
//1、分布式锁阻拦 | //1、分布式锁阻拦 | ||||
requestIdPrefix := fmt.Sprintf(md.DealUserCoinForGreenRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | requestIdPrefix := fmt.Sprintf(md.DealUserCoinForGreenRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | ||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix) | |||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix, strconv.Itoa(req.CoinId)) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
@@ -352,7 +352,7 @@ func DealUserCoinForIntegralRelease(session *xorm.Session, req md.DealUserCoinRe | |||||
} | } | ||||
//1、分布式锁阻拦 | //1、分布式锁阻拦 | ||||
requestIdPrefix := fmt.Sprintf(DealUserCoinForIntegralReleaseRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | requestIdPrefix := fmt.Sprintf(DealUserCoinForIntegralReleaseRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | ||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix) | |||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix, strconv.Itoa(req.CoinId)) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
@@ -365,7 +365,7 @@ func DealUserCoinForNiuBeiRelease(session *xorm.Session, req md.DealUserCoinReq) | |||||
} | } | ||||
//1、分布式锁阻拦 | //1、分布式锁阻拦 | ||||
requestIdPrefix := fmt.Sprintf(DealUserCoinForIntegralReleaseRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | requestIdPrefix := fmt.Sprintf(DealUserCoinForIntegralReleaseRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | ||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix) | |||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix, strconv.Itoa(req.CoinId)) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
@@ -21,7 +21,7 @@ func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) { | |||||
} | } | ||||
//1、分布式锁阻拦 | //1、分布式锁阻拦 | ||||
requestIdPrefix := fmt.Sprintf(md.DealUserCoinRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | requestIdPrefix := fmt.Sprintf(md.DealUserCoinRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | ||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix) | |||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix, strconv.Itoa(req.CoinId)) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
@@ -48,8 +48,8 @@ func SetCacheUserVirtualAmount(session *xorm.Session, masterId, amount string, c | |||||
} | } | ||||
} | } | ||||
//_, err := cache.Set(redisKey, int64(utils.StrToFloat64(amount))) | //_, err := cache.Set(redisKey, int64(utils.StrToFloat64(amount))) | ||||
//TODO::默认缓存1小时 (先调整为 2 min) | |||||
_, err := cache.SetEx(redisKey, zhios_order_relate_utils.StrToFloat64(amount), 60*2) | |||||
//TODO::默认缓存1小时 (先调整为 20 min) | |||||
_, err := cache.SetEx(redisKey, zhios_order_relate_utils.StrToFloat64(amount), 60*20) | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
@@ -67,9 +67,9 @@ func GetDistributedLockRequestId(prefix string) string { | |||||
} | } | ||||
// HandleDistributedLock 处理余额更新时获取锁和释放锁 如果加锁成功,使用语句 ` defer cb() ` 释放锁 | // HandleDistributedLock 处理余额更新时获取锁和释放锁 如果加锁成功,使用语句 ` defer cb() ` 释放锁 | ||||
func HandleDistributedLock(masterId, uid, requestIdPrefix string) (cb func(), err error) { | |||||
func HandleDistributedLock(masterId, uid, coinId, requestIdPrefix string) (cb func(), err error) { | |||||
// 获取余额更新锁 | // 获取余额更新锁 | ||||
balanceLockKey := fmt.Sprintf(md.UserVirtualAmountUpdateLock, masterId, uid) | |||||
balanceLockKey := fmt.Sprintf(md.UserVirtualAmountUpdateLock, masterId, uid, coinId) | |||||
requestId := GetDistributedLockRequestId(requestIdPrefix) | requestId := GetDistributedLockRequestId(requestIdPrefix) | ||||
balanceLockOk := TryGetDistributedLock(balanceLockKey, requestId, true) | balanceLockOk := TryGetDistributedLock(balanceLockKey, requestId, true) | ||||
if !balanceLockOk { | if !balanceLockOk { | ||||