好友助战刷新机制调整

This commit is contained in:
meixiongfeng 2024-01-08 18:39:24 +08:00
parent 16ed4231ec
commit 1de8394dbd
2 changed files with 38 additions and 30 deletions

View File

@ -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
}
}
}

View File

@ -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"
@ -32,11 +33,12 @@ func (this *modelRank) updateRank(Score int32, uid string, nandu int) (err error
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)
}
@ -56,8 +58,10 @@ func (this *modelRank) updateRank(Score int32, uid string, nandu int) (err error
func (this *modelRank) queryIntegralRankUser(nandu int) (ranks []string, err error) {
var (
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
}