diff --git a/cron/gift_cron/send_gift_redis.go b/cron/gift_cron/send_gift_redis.go index 1a93f16779f9038f302408e3244be9fe470332e2..475927e31e89261aa4fc8865788e05bc68835409 100644 --- a/cron/gift_cron/send_gift_redis.go +++ b/cron/gift_cron/send_gift_redis.go @@ -75,9 +75,6 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { // 送礼加分 if data, ok := groupPowers[sendGiftEvent.SendUserId]; ok { diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum * mysql.Num(len(sendGiftEvent.ReceiveUserIds)) - if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil { - model.Log.Errorf("IncrGroupPowerMonthStarScore famous fail:%v", err) - } if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds); err != nil { model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err) @@ -87,9 +84,6 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { for _, userId := range sendGiftEvent.ReceiveUserIds { if data, ok := groupPowers[userId]; ok { diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum - if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil { - model.Log.Errorf("IncrGroupPowerMonthStarScore charm fail:%v", err) - } if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds); err != nil { model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err) diff --git a/domain/cache/groupPower_c/group_power_star.go b/domain/cache/groupPower_c/group_power_star.go index 018f7c3968145fce2ac35e1bb664d6dc5ea2cbef..a03f89ebb0a52f1037a320bc69a8d497b1f23477 100644 --- a/domain/cache/groupPower_c/group_power_star.go +++ b/domain/cache/groupPower_c/group_power_star.go @@ -47,7 +47,8 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. } // 获取家族之星排行 -func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int) ([]*GroupPowerStarRank, error) { +// param period: day|week|month +func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, targetDate ...string) ([]*GroupPowerStarRank, error) { var res []*GroupPowerStarRank date := "" switch period { @@ -61,6 +62,9 @@ func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerI if len(date) <= 0 { return res, errors.New("illegal date") } + if len(targetDate) > 0 { + date = targetDate[0] + } key := groupPower_k.GetGroupPowerStarRankKey(_type, period, groupPowerId, date) rows, err := model.RedisCluster.ZRevRangeByScoreWithScores(model, key, &redis.ZRangeBy{ Min: "-inf", diff --git a/domain/model/groupPower_m/group_grade.go b/domain/model/groupPower_m/group_grade.go index f925b6711dd648f245e06b29fcec0226b3fe3471..16e20a3805fbd7d0a0e96fa5ddad87fa860bbc39 100644 --- a/domain/model/groupPower_m/group_grade.go +++ b/domain/model/groupPower_m/group_grade.go @@ -154,56 +154,6 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID) return nil } -// 增加势力上麦时长-家族之星 -// 事务操作 -func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error { - // 月统计 - //star, err := GetGroupPowerMonthStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive) - //curTs := joinMicTimestamp - //nowTs := time.Now().Unix() - //month0Ts := now.BeginningOfMonth().Unix() - //if err != nil && err != gorm.ErrRecordNotFound { - // return err - //} - //if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小 - // curTs = star.LastCalTs - //} - //// 跨月 - //if curTs < month0Ts { - // curTs = month0Ts - //} - //score := nowTs - curTs - score := 60 - err := IncrGroupPowerMonthStarScore(model, groupPowerId, userId, - groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), 0) - return err -} - -// 增加势力上麦时长-家族之星 -// 事务操作 -func IncrGroupPowerStarOnMicDay(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error { - // 日统计 - //star, err := GetGroupPowerDayStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive) - //curTs := joinMicTimestamp - //nowTs := time.Now().Unix() - //day0Ts := now.BeginningOfDay().Unix() - //if err != nil && err != gorm.ErrRecordNotFound { - // return err - //} - //if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小 - // curTs = star.LastCalTs - //} - //// 跨天 - //if curTs < day0Ts { - // curTs = day0Ts - //} - //score := nowTs - curTs - score := 60 - err := IncrGroupPowerDayStarScore(model, groupPowerId, userId, - groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), 0) - return err -} - // 清理所有家族的经验 func ClearGroupPowerExp(model *domain.Model) error { var groupPowerGrades []*GroupPowerGrade diff --git a/domain/model/groupPower_m/group_star.go b/domain/model/groupPower_m/group_star.go index bc653ed8553c8f690cd62a7084bc903d0836c3e2..0c8815a95fe3ec840ff20eeb3ccdad67ba64be69 100644 --- a/domain/model/groupPower_m/group_star.go +++ b/domain/model/groupPower_m/group_star.go @@ -35,6 +35,7 @@ type GroupPowerDayStar struct { } // 增加家族之星分数 +// Deprecated: 用redis func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error { month := time.Now().Format("200601") star := &GroupPowerMonthStar{ @@ -83,6 +84,7 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. } // 获取家族之星排行 +// Deprecated: 用redis func GetGroupPowerMonthStarRank(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*GroupPowerMonthStar, error) { var res []*GroupPowerMonthStar //month := time.Now().Format("200601") diff --git a/domain/service/group_mic_s/group_mic.go b/domain/service/group_mic_s/group_mic.go index 2fdc2b4b2e566271bda22bcfec1950c61caf3db3..c6892e89d2173daae1867770eda793efa438452b 100644 --- a/domain/service/group_mic_s/group_mic.go +++ b/domain/service/group_mic_s/group_mic.go @@ -322,11 +322,7 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u if err := groupPower_m.IncrGroupPowerExpOnMic(model, groupPowerId, userId); err != nil { model.Log.Errorf("IncrGroupPowerExpOnMic fail:%v", err) } - // 增加势力上麦时长-月 - if err := groupPower_m.IncrGroupPowerStarOnMicMonth(model, groupPowerId, userId, joinMicTimestamp); err != nil { - model.Log.Errorf("IncrGroupPowerStarOnMicMonth fail:%v", err) - } - // 增加势力上麦时长-天 + // 增加势力上麦时长-天/周/月 //if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil { if err := groupPower_c.IncrGroupPowerDayStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, 60); err != nil { diff --git a/domain/service/group_power_s/group_power.go b/domain/service/group_power_s/group_power.go index cc5b2ed2d9f4eae078265ee6247c1c54d8076ea2..24f1eef399823e45e699864d20939f9c42eae95f 100644 --- a/domain/service/group_power_s/group_power.go +++ b/domain/service/group_power_s/group_power.go @@ -13,6 +13,7 @@ import ( "hilo-group/_const/enum/msg_e" "hilo-group/cv/group_power_cv" "hilo-group/cv/user_cv" + "hilo-group/domain/cache/groupPower_c" "hilo-group/domain/cache/user_c" "hilo-group/domain/event/group_power_ev" "hilo-group/domain/model/groupPower_m" @@ -154,7 +155,12 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI } func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*group_power_cv.CvGroupPowerStarData, error) { - rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month) + monthTime, err := time.Parse("200601", month) + if err != nil { + return nil, err + } + //rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month) + rank, err := groupPower_c.GetGroupPowerStarRankPeriod(model, "month", groupPowerId, _type, offset, limit, monthTime.Format("2006-01-02")) if err != nil { return nil, err } diff --git a/test/group_power_test.go b/test/group_power_test.go index 70b19f2cabc0c47fe06539c8b743a7fcf967bf75..73f584e128a8d5e1955dbfb9e14a04de7a493dcb 100644 --- a/test/group_power_test.go +++ b/test/group_power_test.go @@ -3,8 +3,10 @@ package test import ( "fmt" "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/resource/redisCli" "git.hilo.cn/hilo-common/utils" "github.com/jinzhu/now" + "hilo-group/domain/cache/groupPower_c" "hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/group_m" "hilo-group/domain/service/group_power_s" @@ -69,3 +71,14 @@ func TestGetRandomImProvider(t *testing.T) { fmt.Printf("true--------------times0:%v\n", times0) fmt.Printf("true--------------times1:%v\n", times1) } + +func TestMonthStar(t *testing.T) { + monthTime, err := time.Parse("200601", "202307") + if err != nil { + panic(err) + } + redisCli.InitCluster() + res, err := groupPower_c.GetGroupPowerStarRankPeriod(domain.CreateModelNil(), "month", 242, 1, 0, 10, monthTime.Format("2006-01-02")) + println(res) + println(err) +} diff --git a/test/local.ini b/test/local.ini index 81bbf6bb9147526a757b5e8c92a98a73f3e47865..c1f2d38d816441b16fc8be9bab713d176cd29bc1 100644 --- a/test/local.ini +++ b/test/local.ini @@ -11,6 +11,8 @@ MYSQL_DB=hilo_code [REDIS] REDIS_HOST=47.244.34.27:6379 REDIS_PASSWORD=8QZ9JD1zLvPR3yHf +REDIS_CLUSTER_HOST=47.244.34.27:6379 +REDIS_CLUSTER_PASSWORD=8QZ9JD1zLvPR3yHf [JWT] SECRET=hilo1632 ISSUER_API=hiloApi