From 8e516982b428b331a8ec17c231e28adbedb067c6 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Fri, 6 Dec 2024 15:52:15 +0800 Subject: [PATCH] update --- md/app_redis_key.go | 2 +- md/user_ecpm.go | 11 +++++++++++ rule/egg_energy/give_activty_coin.go | 20 +++++++++++++++++++- rule/egg_energy/md/mq_egg_energy.go | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 md/user_ecpm.go diff --git a/md/app_redis_key.go b/md/app_redis_key.go index 3d570a5..eff38dd 100644 --- a/md/app_redis_key.go +++ b/md/app_redis_key.go @@ -5,7 +5,7 @@ const RedisDataBase = 0 //Redis 0 号库 // 缓存key统一管理 const ( EggEnergyNowPriceUpdateLock = "egg_energy_core_data_update_lock" // 当前价格(能拿到锁才能更新价格) - DealEggEnergyNowPriceRequestIdPrefix = "egg_energy_core_data:%d" + DealEggEnergyNowPriceRequestIdPrefix = "egg_energy_core_data:%d" // 制度核心数据(能拿到锁才能更新数据) UserFinValidUpdateLock = "user_fin_valid_update_lock:%s" // 用户余额更新锁(能拿到锁才能更新余额) UserVirtualAmountUpdateLock = "%s:user_virtual_amount_update_lock:%s" // 用户虚拟币更新锁(能拿到锁才能更新余额) diff --git a/md/user_ecpm.go b/md/user_ecpm.go new file mode 100644 index 0000000..f3a8919 --- /dev/null +++ b/md/user_ecpm.go @@ -0,0 +1,11 @@ +package md + +const ( + UserEcpmCacheKey = "user:%d:ecpm" + UserEcpmCacheTime = 60 * 30 +) + +type DealUserEcpmReq struct { + Uid int64 `json:"uid"` + Ecpm string `json:"ecpm"` +} diff --git a/rule/egg_energy/give_activty_coin.go b/rule/egg_energy/give_activty_coin.go index a747267..62810b2 100644 --- a/rule/egg_energy/give_activty_coin.go +++ b/rule/egg_energy/give_activty_coin.go @@ -24,7 +24,7 @@ import ( ) // SettlementGiveActivityCoin 结算观看激励广告得到蛋蛋积分 -func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ch *rabbit.Channel) (err error) { +func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ecpm string, ch *rabbit.Channel) (err error) { uid := user.Id now := time.Now() @@ -62,6 +62,8 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ch *rabbit return } + go dealEcpm(user, ecpm, ch) //TODO::协程处理ecpm的变化 + var rewardValue float64 //TODO::奖励多少个活跃积分(根据ecpm, 新用户机制, 蛋蛋分机制) redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(engine, redisConn) @@ -284,9 +286,25 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ch *rabbit } cache.SetEx(redisKey, watchAdDate, 60*60*24) //TODO::默认缓存1小时 } + return } +func dealEcpm(user model.User, ecpm string, ch *rabbit.Channel) { + //查找缓存中的ecpm值和当前的ecpm是否一致 + key := fmt.Sprintf(md.UserEcpmCacheKey, user.Id) + ecpmCacheValue, _ := cache.GetString(key) + if ecpmCacheValue == "" || ecpmCacheValue != ecpm { + //更新缓存值 + cache.SetEx(key, ecpm, md.UserEcpmCacheTime) + + //TODO::推入rabbitmq 异步处理 + ch.Publish(md2.EggEnergyExchange, md.DealUserEcpmReq{ + Uid: user.Id, + Ecpm: ecpm, + }, md2.EggEnergyRoutKeyForDealUserEcpm) + } +} func ActivityCoinToAlipayRealName(engine *xorm.Engine, uid int64, amount string) (err error) { amountValue, _ := decimal.NewFromString(amount) diff --git a/rule/egg_energy/md/mq_egg_energy.go b/rule/egg_energy/md/mq_egg_energy.go index d48fa3b..b86ca92 100644 --- a/rule/egg_energy/md/mq_egg_energy.go +++ b/rule/egg_energy/md/mq_egg_energy.go @@ -10,6 +10,7 @@ const ( EggEnergyRoutKeyForEggEnergyFundData = "fund_data" // 资金汇入 EggEnergyRoutKeyForPlatformRevenueData = "platform_revenue_data" // 平台收入 EggEnergyRoutKeyForDealUserVirtualCoinData = "deal_user_virtual_coin" // 处理给用户虚拟币积分 + EggEnergyRoutKeyForDealUserEcpm = "user_ecpm" // 处理给用户Ecpm值 ) type EggEnergyStructForSignIn struct {