diff --git a/md/app_redis_key.go b/md/app_redis_key.go index af03a8f..4bd6397 100644 --- a/md/app_redis_key.go +++ b/md/app_redis_key.go @@ -7,8 +7,8 @@ const ( PlanRewardCfgCacheKey = "%s:plan_reward_cfg" 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" // 提现队列 diff --git a/md/mq.go b/md/mq.go index 04476c0..00711f5 100644 --- a/md/mq.go +++ b/md/mq.go @@ -4,10 +4,12 @@ const OneCirclesExchange = "one.circles" const ( OneCirclesRoutKeyForSignIn = "sign_in" // 签到 + OneCirclesRoutKeyForSignInUpdateRecords = "sign_in_update_records" // 签到更新记录 OneCirclesRoutKeyForStarLevelDividend = "star_level_dividend" // 星级分红 OneCirclesRoutKeyForAutoExchangeGreenEnergyToPerson = "auto_exchange_green_energy_to_person_1" // 自动兑换个人绿色能量 OneCirclesRoutKeyForAutoExchangeGreenEnergyToTeam = "auto_exchange_green_energy_to_team" // 自动兑换团队绿色能量 OneCirclesRoutKeyForSettlementPublicGiveActivityCoin = "settlement_public_give_activity_coin" // 计算观看激励视屏得到活跃积分 + OneCirclesRoutKeyForRewardUserCoin = "reward_user_coin" // 奖励用户虚拟币 ) @@ -17,6 +19,10 @@ type OneCirclesStructForSignIn struct { Id int64 `json:"id"` EndTime string `json:"end_time"` } +type UpdateOneCirclesStructForSignInRecords struct { + Id int64 `json:"id"` + Uid int `json:"uid"` +} type OneCirclesStructForAutoExchangeGreenEnergy struct { MasterId string `json:"master_id"` diff --git a/rule/block_green_chain_settlement.go b/rule/block_green_chain_settlement.go index 5c74ee4..7792cda 100644 --- a/rule/block_green_chain_settlement.go +++ b/rule/block_green_chain_settlement.go @@ -563,7 +563,7 @@ func DealUserCoinForGreen(session *xorm.Session, req md.DealUserCoinReq) (err er } //1、分布式锁阻拦 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 { return err } diff --git a/rule/integral_release_settlement.go b/rule/integral_release_settlement.go index c355aa9..9b59c29 100644 --- a/rule/integral_release_settlement.go +++ b/rule/integral_release_settlement.go @@ -352,7 +352,7 @@ func DealUserCoinForIntegralRelease(session *xorm.Session, req md.DealUserCoinRe } //1、分布式锁阻拦 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 { return err } diff --git a/rule/niu_bei_release_settlement.go b/rule/niu_bei_release_settlement.go index 6bf0361..5b6ca1d 100644 --- a/rule/niu_bei_release_settlement.go +++ b/rule/niu_bei_release_settlement.go @@ -365,7 +365,7 @@ func DealUserCoinForNiuBeiRelease(session *xorm.Session, req md.DealUserCoinReq) } //1、分布式锁阻拦 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 { return err } diff --git a/rule/one_circles/one_circles_auto_adjust_prices.go b/rule/one_circles/one_circles_auto_adjust_prices.go index 3f100d1..56b436f 100644 --- a/rule/one_circles/one_circles_auto_adjust_prices.go +++ b/rule/one_circles/one_circles_auto_adjust_prices.go @@ -62,7 +62,7 @@ func AutoAdjustPrice(engine *xorm.Engine, masterId string) (err error) { } // 市商数量 减少、原始数量 增加、原始资金 减少、市商资金 增加 - err = DealAvailableGreenEnergyCoin(session, int(enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds), zhios_order_relate_utils.StrToFloat64(marketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue.String()), zhios_order_relate_utils.StrToFloat64(amount), enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue) + err = DealAvailableGreenEnergyCoin(session, int(enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds), zhios_order_relate_utils.StrToFloat64(marketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue.String()), zhios_order_relate_utils.StrToFloat64(amount), enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue, masterId) if err != nil { fmt.Println("err:::::22222", err) _ = session.Rollback() @@ -78,7 +78,7 @@ func AutoAdjustPrice(engine *xorm.Engine, masterId string) (err error) { return err1 } // 市商数量 增加、原始数量 减少、原始资金 增加、市商资金 减少 - err = DealAvailableGreenEnergyCoin(session, int(enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums), zhios_order_relate_utils.StrToFloat64(greenEnergy), zhios_order_relate_utils.StrToFloat64(marketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue.String()), enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue) + err = DealAvailableGreenEnergyCoin(session, int(enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums), zhios_order_relate_utils.StrToFloat64(greenEnergy), zhios_order_relate_utils.StrToFloat64(marketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue.String()), enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue, masterId) if err != nil { fmt.Println("err:::::44444", err) _ = session.Rollback() diff --git a/rule/one_circles/one_circles_community_dividends.go b/rule/one_circles/one_circles_community_dividends.go index 36a25cc..9941930 100644 --- a/rule/one_circles/one_circles_community_dividends.go +++ b/rule/one_circles/one_circles_community_dividends.go @@ -84,7 +84,7 @@ func CommunityDividends(engine *xorm.Engine, masterId string) (err error) { } //6、 减少“社区分红”钱包中的值 totalDividend, _ := totalValue.Float64() - err = DealAvailableGreenEnergyCoin(session, int(enum.CommunityDividends), totalDividend, 0, enum.CommunityDividends.String(), nil, masterId) + err = DealAvailableGreenEnergyCoin(session, int(enum.CommunityDividends), totalDividend, 0, enum.CommunityDividends.String(), nil, "", masterId) if err != nil { _ = session.Rollback() fmt.Println("err:::::444444", err) diff --git a/rule/one_circles/one_circles_deal_available_green_energy_points.go b/rule/one_circles/one_circles_deal_available_green_energy_points.go index 499a044..b2f3d0b 100644 --- a/rule/one_circles/one_circles_deal_available_green_energy_points.go +++ b/rule/one_circles/one_circles_deal_available_green_energy_points.go @@ -12,10 +12,11 @@ import ( "xorm.io/xorm" ) -func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amountFee float64, title string, chain *model.OneCirclesGreenEnergyBasicSetting, nowPriceValue string) error { +func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amountFee float64, title string, chain *model.OneCirclesGreenEnergyBasicSetting, nowPriceValue, masterId string) error { if chain == nil { // 查找 `one_circles_green_energy_basic_setting` 基础设置 - oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(session.Engine(), nowPriceValue) + oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(session.Engine(), masterId) + nowPriceValue = oneCirclesGreenEnergyBasicSetting.NowPrice if err != nil { return err } diff --git a/rule/one_circles/one_circles_sign_in_green_energy_settlement.go b/rule/one_circles/one_circles_sign_in_green_energy_settlement.go index 36d4a80..73a02f4 100644 --- a/rule/one_circles/one_circles_sign_in_green_energy_settlement.go +++ b/rule/one_circles/one_circles_sign_in_green_energy_settlement.go @@ -5,12 +5,10 @@ import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/svc" zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" - zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" "encoding/json" "errors" "fmt" @@ -72,26 +70,20 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, ch *rabbi return } -func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id int64, uid int, endTime string) (err error) { - //var signRecord model.OneCirclesGreenEnergySignIn - //has, err00000 := engine.Where("id =?", id).Get(&signRecord) - //if err00000 != nil { - // fmt.Println("err:::::0000000", err00000) - // return err00000 +func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, masterId string, id int64, uid int, endTime string) (err error) { + //1、查找 `one_circles_green_energy_basic_setting` 基础设置 + //oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(engine, masterId) + //if err != nil { + // return //} - //if !has { - // //不活跃不需要奖励 - // return errors.New("未查询到对应记录") + //if cb != nil { + // defer cb() // 释放锁 //} - //1、查找 `one_circles_green_energy_basic_setting` 基础设置 - oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(engine, masterId) - if err != nil { - return - } - if cb != nil { - defer cb() // 释放锁 - } + oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ + "key": "is_open", + "value": 1, + }) var teamRewardSetting *md2.TeamRewardSettingStruct err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.TeamReward), &teamRewardSetting) @@ -116,18 +108,10 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id rewardValue := zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(reward) * float64(oneRoundDuration) * 60 * 60) //3、统计签到结束的用户数据 - session := engine.NewSession() - defer func() { - session.Close() - if err := recover(); err != nil { - _ = zhios_order_relate_logx.Error(err) - } - }() - session.Begin() var reduceTotalGreenEnergy float64 //4.2给相应的用户加上个人的绿色积分(可用数量) - err = rule.DealUserCoin(session, md.DealUserCoinReq{ + var oneCirclesDealUserCoinData = md.DealUserCoinReq{ Kind: "add", Mid: masterId, Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, @@ -136,21 +120,16 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, Uid: uid, Amount: zhios_order_relate_utils.StrToFloat64(rewardValue), - }) - if err != nil { - _ = session.Rollback() - fmt.Println("err:::::2222", err) - return err } - reduceTotalGreenEnergy += zhios_order_relate_utils.StrToFloat64(rewardValue) + reduceTotalGreenEnergy += zhios_order_relate_utils.StrToFloat64(rewardValue) //4.2给相应的上级用户加上团队奖励的绿色积分(结算数量) relates, err1 := db.DbsUserRelate(engine, uid, 0) if err1 != nil { - _ = session.Rollback() fmt.Println("err:::::3333", err1) return err1 } + var oneCirclesDealUserCoinDataForParents []md.DealUserCoinReq var parentRewardValue = zhios_order_relate_utils.StrToFloat64(rewardValue) if relates != nil { for _, relate := range *relates { @@ -163,7 +142,6 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id if endTime != "" { has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", endTime).Get(&m) if err3333333 != nil { - _ = session.Rollback() fmt.Println("err:::::3333333", err3333333) return err3333333 } @@ -174,7 +152,6 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id } else { has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", time.Now().Format("2006-01-02 15:04:05")).Get(&m) if err3333333 != nil { - _ = session.Rollback() fmt.Println("err:::::3333333", err3333333) return err3333333 } @@ -184,7 +161,7 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id } } - err = rule.DealUserCoin(session, md.DealUserCoinReq{ + oneCirclesDealUserCoinDataForParents = append(oneCirclesDealUserCoinDataForParents, md.DealUserCoinReq{ Kind: "add", Mid: masterId, Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, @@ -194,34 +171,32 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id Uid: relate.ParentUid, Amount: parentRewardValue, }) - if err != nil { - _ = session.Rollback() - fmt.Println("err:::::44444", err) - return err - } reduceTotalGreenEnergy += parentRewardValue } } //5、减少“活跃赠送” 中的绿色能量 if reduceTotalGreenEnergy > 0 { - err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice) + err = DealAvailableGreenEnergyCoin(engine.NewSession(), int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice, masterId) if err != nil { - _ = session.Rollback() fmt.Println("err:::::55555", err) return err } } //6、更新 `one_circles_green_energy_sign_in` 中的 is_completed 状态 - _, err = session.Where("id = ?", id).Update(&model.OneCirclesGreenEnergySignIn{ + _, err = engine.Where("id = ?", id).Update(&model.OneCirclesGreenEnergySignIn{ IsCompleted: 1, }) - - err = session.Commit() if err != nil { - _ = session.Rollback() - return errors.New("事务提交失败") + fmt.Println("err:::::66666", err) + return err + } + + ////TODO::推入rabbitmq 异步处理 + ch.Publish(md.OneCirclesExchange, oneCirclesDealUserCoinData, md.OneCirclesRoutKeyForRewardUserCoin) //个人的奖励 + for _, oneCirclesDealUserCoinDataForParent := range oneCirclesDealUserCoinDataForParents { + ch.Publish(md.OneCirclesExchange, oneCirclesDealUserCoinDataForParent, md.OneCirclesRoutKeyForRewardUserCoin) //上级的奖励 } return @@ -229,38 +204,43 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id // CalcNowSignInGreenEnergy 计算当前签到拿多少绿色能量/秒 func CalcNowSignInGreenEnergy(engine *xorm.Engine, oneCirclesGreenEnergyBasicSetting *model.OneCirclesGreenEnergyBasicSetting) (err error, rewardValue string) { - if oneCirclesGreenEnergyBasicSetting == nil { - //1、查找 `one_circles_green_energy_basic_setting` 基础设置 - oneCirclesGreenEnergyBasicSetting, err = db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ - "key": "is_open", - "value": 1, - }) + rewardValue, _ = cache.GetString("one_circle_reward_value") + if rewardValue == "" { + if oneCirclesGreenEnergyBasicSetting == nil { + //1、查找 `one_circles_green_energy_basic_setting` 基础设置 + oneCirclesGreenEnergyBasicSetting, err = db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ + "key": "is_open", + "value": 1, + }) + if err != nil { + return + } + } + + var signInRewards []*md2.SignInRewardStruct + err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.SignInReward), &signInRewards) if err != nil { return } - } - - var signInRewards []*md2.SignInRewardStruct - err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.SignInReward), &signInRewards) - if err != nil { - return - } - if len(signInRewards) == 0 { - err = errors.New("未设置签到奖励!") - return - } + if len(signInRewards) == 0 { + err = errors.New("未设置签到奖励!") + return + } - //2、统计全网用户数 - sqlStr := "SELECT COUNT(*) AS total FROM user " - nativeString, _ := db.QueryNativeString(engine, sqlStr) - userCount := zhios_order_relate_utils.StrToInt64(nativeString[0]["total"]) + //2、统计全网用户数 + sqlStr := "SELECT COUNT(*) AS total FROM user " + nativeString, _ := db.QueryNativeString(engine, sqlStr) + userCount := zhios_order_relate_utils.StrToInt64(nativeString[0]["total"]) - for _, v := range signInRewards { - if zhios_order_relate_utils.StrToInt64(v.VipMemberEndNums) >= userCount && userCount >= zhios_order_relate_utils.StrToInt64(v.VipMemberStartNums) { - //rewardValue = zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(v.RewardValue) * float64(oneRoundDuration) * 60 * 60) - rewardValue = v.RewardValue + for _, v := range signInRewards { + if zhios_order_relate_utils.StrToInt64(v.VipMemberEndNums) >= userCount && userCount >= zhios_order_relate_utils.StrToInt64(v.VipMemberStartNums) { + //rewardValue = zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(v.RewardValue) * float64(oneRoundDuration) * 60 * 60) + rewardValue = v.RewardValue + } } + cache.SetEx("one_circle_reward_value", rewardValue, 3600*8) //8小时 } + return } diff --git a/rule/one_circles/one_circles_star_level_dividends.go b/rule/one_circles/one_circles_star_level_dividends.go index 30c5318..0c059c0 100644 --- a/rule/one_circles/one_circles_star_level_dividends.go +++ b/rule/one_circles/one_circles_star_level_dividends.go @@ -288,7 +288,7 @@ func SettlementStarLevelDividends(engine *xorm.Engine, masterId string, ch *rabb //6、 减少“星级分红”中的绿色能量 totalDividend, _ := totalDividendValue.Float64() - err = DealAvailableGreenEnergyCoin(session, int(enum.SettlementStarLevelDividends), totalDividend, 0, enum.SettlementStarLevelDividends.String(), nil, masterId) + err = DealAvailableGreenEnergyCoin(session, int(enum.SettlementStarLevelDividends), totalDividend, 0, enum.SettlementStarLevelDividends.String(), nil, "", masterId) if err != nil { _ = session.Rollback() fmt.Println("err:::::9999999", err) diff --git a/rule/one_circles/svc/svc_now_price_redis_mutex_lock.go b/rule/one_circles/svc/svc_now_price_redis_mutex_lock.go index 70fe5eb..a324f2a 100644 --- a/rule/one_circles/svc/svc_now_price_redis_mutex_lock.go +++ b/rule/one_circles/svc/svc_now_price_redis_mutex_lock.go @@ -28,7 +28,7 @@ func TryGetDistributedLock(lockKey, requestId string, isNegative bool) bool { if retry > 99 { return false } - time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + time.Sleep(time.Millisecond * time.Duration(rand.Intn(100))) retry += 1 } } else { // 只尝试一次 @@ -73,7 +73,7 @@ func HandleDistributedLock(masterId, requestIdPrefix string) (cb func(), err err requestId := GetDistributedLockRequestId(requestIdPrefix) balanceLockOk := TryGetDistributedLock(balanceLockKey, requestId, true) if !balanceLockOk { - return nil, errors.New("系统繁忙,请稍后再试") + return nil, errors.New("获取价格系统繁忙,请稍后再试") } cb = func() { diff --git a/rule/user_amount.go b/rule/user_amount.go index 98c04b7..ce77343 100644 --- a/rule/user_amount.go +++ b/rule/user_amount.go @@ -21,7 +21,7 @@ func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) { } //1、分布式锁阻拦 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 { return err } diff --git a/svc/svc_block_star_chain_settlement.go b/svc/svc_block_star_chain_settlement.go index 235e7f6..2ff7a51 100644 --- a/svc/svc_block_star_chain_settlement.go +++ b/svc/svc_block_star_chain_settlement.go @@ -48,8 +48,8 @@ func SetCacheUserVirtualAmount(session *xorm.Session, masterId, amount string, c } } //_, 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 { return err } diff --git a/svc/svc_redis_mutex_lock.go b/svc/svc_redis_mutex_lock.go index 98bbfce..8cc4d32 100644 --- a/svc/svc_redis_mutex_lock.go +++ b/svc/svc_redis_mutex_lock.go @@ -28,7 +28,7 @@ func TryGetDistributedLock(lockKey, requestId string, isNegative bool) bool { if retry > 50 { return false } - time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + time.Sleep(time.Millisecond * time.Duration(rand.Intn(100))) retry += 1 } } else { // 只尝试一次 @@ -67,9 +67,9 @@ func GetDistributedLockRequestId(prefix string) string { } // 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) balanceLockOk := TryGetDistributedLock(balanceLockKey, requestId, true) if !balanceLockOk {