Commit 793f2fa9 authored by hujiebin's avatar hujiebin

Merge branch 'feature/fruit-up' into 'master'

feat:等级中处理分区用户

See merge request !5
parents 1e30a039 4a3e1b79
...@@ -309,11 +309,18 @@ func (s *server) Levelcast(ctx context.Context, in *userCenter.LevelMessage) (*u ...@@ -309,11 +309,18 @@ func (s *server) Levelcast(ctx context.Context, in *userCenter.LevelMessage) (*u
uids = append(uids, uid) uids = append(uids, uid)
} }
} }
// 处理分区用户 // 处理等级用户
levelUserIds := userManager.GetLevelUsers(uids, in.Level) levelUserIds, userIds := userManager.GetLevelUsers(uids, in.Level)
if len(levelUserIds) <= 0 { if len(levelUserIds) <= 0 {
return &userCenter.LevelMessageRsp{FailedUids: failed}, nil return &userCenter.LevelMessageRsp{FailedUids: failed}, nil
} }
if in.Area > 0 {
// 处理分区用户
levelUserIds = userManager.GetAreaUsers(userIds, int8(in.Area))
if len(levelUserIds) <= 0 {
return &userCenter.LevelMessageRsp{FailedUids: failed}, nil
}
}
m := make(map[string][]uint64, 0) m := make(map[string][]uint64, 0)
for uid := range levelUserIds { for uid := range levelUserIds {
ok := false ok := false
......
...@@ -138,8 +138,9 @@ func (m *UserManager) GetAreaUsers(userIds []uint64, area int8) map[uint64]UserT ...@@ -138,8 +138,9 @@ func (m *UserManager) GetAreaUsers(userIds []uint64, area int8) map[uint64]UserT
// 获取财富等级大于某等级的用户 // 获取财富等级大于某等级的用户
// 开区间 // 开区间
func (m *UserManager) GetLevelUsers(userIds []uint64, wealthLevel int32) map[uint64]UserTinyArea { func (m *UserManager) GetLevelUsers(userIds []uint64, wealthLevel int32) (map[uint64]UserTinyArea, []uint64) {
res := make(map[uint64]UserTinyArea) res := make(map[uint64]UserTinyArea)
var resIds []uint64
// 从db中读,暂时不缓存(几千个) // 从db中读,暂时不缓存(几千个)
var users []UserTinyArea var users []UserTinyArea
if err := m.MysqlDB.Table("user").Joins("JOIN match_wealth_user_score ON match_wealth_user_score.user_id = user.id"). if err := m.MysqlDB.Table("user").Joins("JOIN match_wealth_user_score ON match_wealth_user_score.user_id = user.id").
...@@ -148,7 +149,7 @@ func (m *UserManager) GetLevelUsers(userIds []uint64, wealthLevel int32) map[uin ...@@ -148,7 +149,7 @@ func (m *UserManager) GetLevelUsers(userIds []uint64, wealthLevel int32) map[uin
Where("match_wealth_user_score.grade > ?", wealthLevel). Where("match_wealth_user_score.grade > ?", wealthLevel).
Find(&users).Error; err != nil { Find(&users).Error; err != nil {
mylogrus.MyLog.Errorf("GetLevelUsers fail:%v", err) mylogrus.MyLog.Errorf("GetLevelUsers fail:%v", err)
return res return res, resIds
} }
for _, u := range users { for _, u := range users {
a := m.GetArea(u.Country) a := m.GetArea(u.Country)
...@@ -161,6 +162,7 @@ func (m *UserManager) GetLevelUsers(userIds []uint64, wealthLevel int32) map[uin ...@@ -161,6 +162,7 @@ func (m *UserManager) GetLevelUsers(userIds []uint64, wealthLevel int32) map[uin
Area: a, Area: a,
Avatar: u.Avatar, Avatar: u.Avatar,
} }
resIds = append(resIds, u.ID)
} }
return res return res, resIds
} }
...@@ -136,6 +136,7 @@ message LevelMessage { ...@@ -136,6 +136,7 @@ message LevelMessage {
int32 level = 1; int32 level = 1;
uint32 msgType = 2; uint32 msgType = 2;
bytes payLoad = 3; bytes payLoad = 3;
int32 area = 4;
} }
message LevelMessageRsp { message LevelMessageRsp {
......
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