From b17347dfda58662e133df1ffd377133d26d6b1e0 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Sat, 27 Jul 2024 18:28:26 +0800 Subject: [PATCH] 1 --- ...circles_sign_in_green_energy_settlement.go | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) 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 35c36b5..1f7cba4 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 @@ -10,6 +10,7 @@ import ( 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" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" "encoding/json" "errors" @@ -228,38 +229,43 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, // 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 }