From 07123285398ce0f172e3f4bb409f79c531ebf6b3 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 23 Aug 2023 15:29:19 +0800 Subject: [PATCH] group support --- cron/gift_cron/send_gift_redis.go | 46 ++++++++++++++++++++++++++-- domain/service/event_s/event_init.go | 46 +--------------------------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/cron/gift_cron/send_gift_redis.go b/cron/gift_cron/send_gift_redis.go index cc9f581..d2216a1 100644 --- a/cron/gift_cron/send_gift_redis.go +++ b/cron/gift_cron/send_gift_redis.go @@ -1,12 +1,18 @@ package gift_cron import ( + "context" + "git.hilo.cn/hilo-common/_const/rediskey" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" + "git.hilo.cn/hilo-common/resource/redisCli" + "hilo-group/_const/enum/gift_e" "hilo-group/_const/enum/groupPower_e" "hilo-group/domain/cache/gift_c" "hilo-group/domain/event/gift_ev" "hilo-group/domain/model/groupPower_m" + "hilo-group/domain/model/group_m" + "time" ) // 送礼事件 @@ -18,8 +24,9 @@ func SendGiftEvent() { for true { model := domain.CreateModelNil() if sendGiftEvent := gift_c.BLPopQueueSendGift(model); sendGiftEvent != nil { - groupPowerGrade(model, sendGiftEvent) // 家族经验 - groupPowerStar(model, sendGiftEvent) // 家族之星 + groupPowerGrade(model, sendGiftEvent) // 家族经验 + groupPowerStar(model, sendGiftEvent) // 家族之星 + groupSupportAddConsume(model, sendGiftEvent) // 群组扶持 } } }() @@ -88,3 +95,38 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { } return } + +// 群组扶持增加流水数据 +func groupSupportAddConsume(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { + //if time.Now().Unix() <= 1692964800 { // cwj---- + // return nil + //} + if sendGiftEvent.SceneType != gift_e.GroupSceneType || sendGiftEvent.SceneUid == "" { + return + } + _, _, period := group_m.GetSupportLevelTime(time.Now()) + // 钻石数 + diamond := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum + keyDiamond := rediskey.GetGroupSupportConsumeSummary(period) + _, err := model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(diamond), sendGiftEvent.SceneUid).Result() + if err != nil { + model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, val:%d, member:%s, err:%v", + keyDiamond, diamond, sendGiftEvent.SceneUid, err) + } + err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周 + if err != nil { + model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, val:%d, member:%s, err:%v", + keyDiamond, diamond, sendGiftEvent.SceneUid, err) + } + // 支持者数量 + keySupportNum := rediskey.GetGroupSupportCountSupporter(period, sendGiftEvent.SceneUid) + err = model.RedisCluster.SAdd(context.Background(), keySupportNum, sendGiftEvent.SendUserId).Err() + if err != nil { + model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, UserId:%d, err:%v", keySupportNum, sendGiftEvent.SendUserId, err) + } + err = redisCli.SetExpire(model.RedisCluster, keySupportNum, time.Hour*24*14) // 保留两周 + if err != nil { + model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, UserId:%d, err:%v", keySupportNum, sendGiftEvent.SendUserId, err) + } + return +} diff --git a/domain/service/event_s/event_init.go b/domain/service/event_s/event_init.go index 45b4bfa..6f9d894 100644 --- a/domain/service/event_s/event_init.go +++ b/domain/service/event_s/event_init.go @@ -1,20 +1,15 @@ package event_s import ( - "context" "encoding/json" - "git.hilo.cn/hilo-common/_const/rediskey" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" - "git.hilo.cn/hilo-common/resource/redisCli" "git.hilo.cn/hilo-common/rpc" "git.hilo.cn/hilo-common/sdk/tencentyun" - "hilo-group/_const/enum/gift_e" "hilo-group/_const/enum/group_e" "hilo-group/_const/enum/msg_e" "hilo-group/_const/enum/task_e" "hilo-group/domain/cache/group_c" - "hilo-group/domain/event/gift_ev" "hilo-group/domain/event/group_ev" "hilo-group/domain/event/group_power_ev" "hilo-group/domain/event/mic_ev" @@ -37,7 +32,7 @@ func EventInit() { GroupEvents() GroupImMass() GroupTheme() - SendGift() // 送礼事件 + //SendGift() // 送礼事件 OnMic() // 在麦上事件 GroupInMicChangeEvent() // 用户进房推送mic位置信息 } @@ -473,45 +468,6 @@ func FlushHiloInfo(extId string, isVip bool, isPrettyCode bool, medals []uint32, } func SendGift() { - // 送礼事件-群组扶持数据累加 - gift_ev.AddSendGiftEventAsync(func(model *domain.Model, event interface{}) error { - //if time.Now().Unix() <= 1692964800 { // cwj---- - // return nil - //} - sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent) - if !ok { - model.Log.Errorf("AddSendGiftEventAsync event type err 群组扶持") - return nil - } - if sendGiftEvent.SceneType != gift_e.GroupSceneType || sendGiftEvent.SceneUid == "" { - return nil - } - _, _, period := group_m.GetSupportLevelTime(time.Now()) - // 钻石数 - diamond := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum - keyDiamond := rediskey.GetGroupSupportConsumeSummary(period) - _, err := model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(diamond), sendGiftEvent.SceneUid).Result() - if err != nil { - model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, val:%d, member:%s, err:%v", - keyDiamond, diamond, sendGiftEvent.SceneUid, err) - } - err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周 - if err != nil { - model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, val:%d, member:%s, err:%v", - keyDiamond, diamond, sendGiftEvent.SceneUid, err) - } - // 支持者数量 - keySupportNum := rediskey.GetGroupSupportCountSupporter(period, sendGiftEvent.SceneUid) - err = model.RedisCluster.SAdd(context.Background(), keySupportNum, sendGiftEvent.SendUserId).Err() - if err != nil { - model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, UserId:%d, err:%v", keySupportNum, sendGiftEvent.SendUserId, err) - } - err = redisCli.SetExpire(model.RedisCluster, keySupportNum, time.Hour*24*14) // 保留两周 - if err != nil { - model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, UserId:%d, err:%v", keySupportNum, sendGiftEvent.SendUserId, err) - } - return nil - }) // 送礼事件-势力经验 //gift_ev.AddSendGiftEventAsync(func(model *domain.Model, event interface{}) error { // sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent) -- 2.22.0