From ef0417d69e2756f5995ad012a948fdb12e080297 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 30 Oct 2023 13:54:12 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=AD=89=E7=BA=A7=E4=B8=AD?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=88=86=E5=8C=BA=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 11 +++++++++-- manager/userManager.go | 8 +++++--- protocol/userCenter.proto | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 0da8243..873770e 100644 --- a/main.go +++ b/main.go @@ -309,11 +309,18 @@ func (s *server) Levelcast(ctx context.Context, in *userCenter.LevelMessage) (*u uids = append(uids, uid) } } - // 处理分区用户 - levelUserIds := userManager.GetLevelUsers(uids, in.Level) + // 处理等级用户 + levelUserIds, userIds := userManager.GetLevelUsers(uids, in.Level) if len(levelUserIds) <= 0 { 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) for uid := range levelUserIds { ok := false diff --git a/manager/userManager.go b/manager/userManager.go index 85cd610..6576dd9 100644 --- a/manager/userManager.go +++ b/manager/userManager.go @@ -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) + var resIds []uint64 // 从db中读,暂时不缓存(几千个) var users []UserTinyArea 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 Where("match_wealth_user_score.grade > ?", wealthLevel). Find(&users).Error; err != nil { mylogrus.MyLog.Errorf("GetLevelUsers fail:%v", err) - return res + return res, resIds } for _, u := range users { a := m.GetArea(u.Country) @@ -161,6 +162,7 @@ func (m *UserManager) GetLevelUsers(userIds []uint64, wealthLevel int32) map[uin Area: a, Avatar: u.Avatar, } + resIds = append(resIds, u.ID) } - return res + return res, resIds } diff --git a/protocol/userCenter.proto b/protocol/userCenter.proto index 207a5d2..acb6b1a 100644 --- a/protocol/userCenter.proto +++ b/protocol/userCenter.proto @@ -136,6 +136,7 @@ message LevelMessage { int32 level = 1; uint32 msgType = 2; bytes payLoad = 3; + int32 area = 4; } message LevelMessageRsp { -- 2.22.0