diff --git a/modules/friend/api_cross_refresh.go b/modules/friend/api_cross_refresh.go index e7a485a45..035880bcb 100644 --- a/modules/friend/api_cross_refresh.go +++ b/modules/friend/api_cross_refresh.go @@ -27,8 +27,10 @@ func (this *apiComp) RefreshAssistHero(session comm.IUserSession, req *pb.Friend heros []*pb.DBHero uids []string names []string + sz []int32 //aherofr []*pb.DBHero // 好友的助战列表 ) + strangerCount = comm.AssistHeroCount // 默认一个界面12条 list, err = this.module.modelAssist.getAssist(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ @@ -47,48 +49,50 @@ func (this *apiComp) RefreshAssistHero(session comm.IUserSession, req *pb.Friend } return } - if friends, err = this.module.modelFriend.GetFriends(self.FriendIds); err != nil { + if friends, err = this.module.modelFriend.GetFriends(self.FriendIds); err == nil { + for _, v := range friends { - if v.AssistHeroId != "" { + if v.AssistHeroId != "" && session.GetUserId() != v.Uid { names = append(names, v.Info.Name) uids = append(uids, v.Uid) heros = append(heros, v.Hero) + sz = append(sz, 1) } } } + list.Data = make(map[string]string) + if int32(len(sz)) > strangerCount { + szData := comm.GetRandWs(sz, strangerCount) + for _, v := range szData { + ahero = append(ahero, heros[v]) + list.Data[uids[v]] = names[v] + } + } else { + if len(sz) > 0 { + szData := comm.GetRandWs(sz, int32(len(sz)/2+1)) + for _, v := range szData { + ahero = append(ahero, heros[v]) + list.Data[uids[v]] = names[v] + } + } + } if list.RefreshNum >= this.module.ModuleTools.GetGlobalConf().FriendHelpHeroRefreshNum { return } list.RefreshNum++ - strangerCount = comm.AssistHeroCount // 默认一个界面12条 - if int32(len(uids)) > list.RefreshNum*comm.AssistHeroCount { - strangerCount = int32(len(uids)) - list.RefreshNum*comm.AssistHeroCount - if strangerCount > comm.AssistHeroCount { - strangerCount = comm.AssistHeroCount - } - heros = append(heros[list.RefreshNum*comm.AssistHeroCount : list.RefreshNum*comm.AssistHeroCount+strangerCount]) - names = append(names[list.RefreshNum*comm.AssistHeroCount : list.RefreshNum*comm.AssistHeroCount+strangerCount]) - uids = append(uids[list.RefreshNum*comm.AssistHeroCount : list.RefreshNum*comm.AssistHeroCount+strangerCount]) - } else { - heros = []*pb.DBHero{} - names = []string{} - uids = []string{} - } - for pos, key := range uids { - list.Data[key] = names[pos] - ahero = append(ahero, heros[pos]) - } - list.Data = make(map[string]string) - //localNum, _ := this.module.modelFriend.DB.CountDocuments(core.SqlTable(this.module.modelFriend.TableName), bson.M{}) - //randomIndex := comm.GetRandNum(0, int32(localNum)) + cur, err := this.module.modelFriend.DB.Find(core.SqlTable(this.module.modelFriend.TableName), bson.M{"assistHeroId": bson.M{"$ne": ""}}, options.Find().SetSkip(0).SetLimit(int64(strangerCount))) for cur.Next(context.TODO()) { tmp := &pb.DBFriend{} if err = cur.Decode(tmp); err == nil { if session.GetUserId() != tmp.Uid { + if int32(len(list.Data)) >= strangerCount { + break + } ahero = append(ahero, tmp.Hero) list.Data[tmp.Uid] = tmp.Info.Name + } } } diff --git a/modules/integral/model_rank.go b/modules/integral/model_rank.go index fafa8775b..e3bd23db1 100644 --- a/modules/integral/model_rank.go +++ b/modules/integral/model_rank.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/redis/pipe" "go_dreamfactory/modules" + "go_dreamfactory/sys/db" "strconv" "github.com/go-redis/redis/v8" @@ -29,14 +30,15 @@ func (this *modelRank) Init(service core.IService, module core.IModule, comp cor // 更新排名 func (this *modelRank) updateRank(Score int32, uid string, nandu int) (err error) { var ( - pipe *pipe.RedisPipe = this.DBModel.Redis.RedisPipe(context.TODO()) - menbers *redis.Z - cmd *redis.IntCmd + pipe *pipe.RedisPipe = this.DBModel.Redis.RedisPipe(context.TODO()) + menbers *redis.Z + cmd *redis.IntCmd + tableName string ) menbers = &redis.Z{Score: float64(Score), Member: uid} - - if cmd = pipe.ZAdd(this.TableName+strconv.Itoa(nandu), menbers); err != nil { + tableName = fmt.Sprintf("%s-%s", db.CrossTag(), this.TableName+strconv.Itoa(int(nandu))) + if cmd = pipe.ZAdd(tableName, menbers); err != nil { this.module.Errorln(err) } @@ -55,9 +57,11 @@ func (this *modelRank) updateRank(Score int32, uid string, nandu int) (err error // 获取排行榜前50的用户名单 func (this *modelRank) queryIntegralRankUser(nandu int) (ranks []string, err error) { var ( - result []string + result []string + tableName string ) - if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName+strconv.Itoa(nandu)), 0, 50).Result(); err != nil { + tableName = fmt.Sprintf("%s-%s", db.CrossTag(), this.TableName+strconv.Itoa(int(nandu))) + if result, err = this.DBModel.Redis.ZRevRange(tableName, 0, comm.MaxRankList).Result(); err != nil { this.module.Errorln(err) return }