You need to sign in or sign up before continuing.
Commit 1ccc8c2f authored by JiebinHu's avatar JiebinHu

fix:榜单漏了日期

parent e8e15102
...@@ -8,9 +8,10 @@ import ( ...@@ -8,9 +8,10 @@ import (
// 家族之星榜单 // 家族之星榜单
// type: 1:送礼 2:活跃 3:收礼 // type: 1:送礼 2:活跃 3:收礼
const GroupPowerStarPrefix = "groupPowerStar:${type}:${period}:${groupPowerId}" // zset member:userId score:分数 // date:天/周/月的开始时间
const GroupPowerStarPrefix = "groupPowerStar:${type}:${period}:${groupPowerId}:${date}" // zset member:userId score:分数
func GetGroupPowerStarRankKey(_type groupPower_e.GroupPowerStarType, period string, groupPowerId uint64) string { func GetGroupPowerStarRankKey(_type groupPower_e.GroupPowerStarType, period string, groupPowerId uint64, date string) string {
return redis_key.ReplaceKey(GroupPowerStarPrefix, return redis_key.ReplaceKey(GroupPowerStarPrefix,
fmt.Sprintf("%d", _type), period, fmt.Sprintf("%d", groupPowerId)) fmt.Sprintf("%d", _type), period, fmt.Sprintf("%d", groupPowerId), date)
} }
...@@ -5,6 +5,8 @@ import ( ...@@ -5,6 +5,8 @@ import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8"
"github.com/jinzhu/now"
"github.com/pkg/errors"
"github.com/spf13/cast" "github.com/spf13/cast"
"hilo-group/_const/enum/groupPower_e" "hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/redis_key/groupPower_k" "hilo-group/_const/redis_key/groupPower_k"
...@@ -28,7 +30,16 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. ...@@ -28,7 +30,16 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.
"month": time.Hour * 24 * 7 * 30 * 2, "month": time.Hour * 24 * 7 * 30 * 2,
} }
for _, period := range []string{"day", "week", "month"} { for _, period := range []string{"day", "week", "month"} {
key := groupPower_k.GetGroupPowerStarRankKey(_type, period, groupPowerId) date := ""
switch period {
case "day":
date = time.Now().Format("2006-01-02")
case "week":
date = now.BeginningOfWeek().Format("2006-01-02")
case "month":
date = now.BeginningOfMonth().Format("2006-01-02")
}
key := groupPower_k.GetGroupPowerStarRankKey(_type, period, groupPowerId, date)
model.RedisCluster.ZIncrBy(model, key, float64(score), fmt.Sprintf("%d", userId)) model.RedisCluster.ZIncrBy(model, key, float64(score), fmt.Sprintf("%d", userId))
model.RedisCluster.Expire(model, key, ttl[period]) model.RedisCluster.Expire(model, key, ttl[period])
} }
...@@ -38,7 +49,19 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. ...@@ -38,7 +49,19 @@ 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) { func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int) ([]*GroupPowerStarRank, error) {
var res []*GroupPowerStarRank var res []*GroupPowerStarRank
key := groupPower_k.GetGroupPowerStarRankKey(_type, period, groupPowerId) date := ""
switch period {
case "day":
date = time.Now().Format("2006-01-02")
case "week":
date = now.BeginningOfWeek().Format("2006-01-02")
case "month":
date = now.BeginningOfMonth().Format("2006-01-02")
}
if len(date) <= 0 {
return res, errors.New("illegal date")
}
key := groupPower_k.GetGroupPowerStarRankKey(_type, period, groupPowerId, date)
rows, err := model.RedisCluster.ZRevRangeByScoreWithScores(model, key, &redis.ZRangeBy{ rows, err := model.RedisCluster.ZRevRangeByScoreWithScores(model, key, &redis.ZRangeBy{
Min: "-inf", Min: "-inf",
Max: "+inf", Max: "+inf",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment