好友助战刷新机制调整
This commit is contained in:
parent
16ed4231ec
commit
1de8394dbd
@ -27,8 +27,10 @@ func (this *apiComp) RefreshAssistHero(session comm.IUserSession, req *pb.Friend
|
|||||||
heros []*pb.DBHero
|
heros []*pb.DBHero
|
||||||
uids []string
|
uids []string
|
||||||
names []string
|
names []string
|
||||||
|
sz []int32
|
||||||
//aherofr []*pb.DBHero // 好友的助战列表
|
//aherofr []*pb.DBHero // 好友的助战列表
|
||||||
)
|
)
|
||||||
|
strangerCount = comm.AssistHeroCount // 默认一个界面12条
|
||||||
list, err = this.module.modelAssist.getAssist(session.GetUserId())
|
list, err = this.module.modelAssist.getAssist(session.GetUserId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
@ -47,48 +49,50 @@ func (this *apiComp) RefreshAssistHero(session comm.IUserSession, req *pb.Friend
|
|||||||
}
|
}
|
||||||
return
|
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 {
|
for _, v := range friends {
|
||||||
if v.AssistHeroId != "" {
|
if v.AssistHeroId != "" && session.GetUserId() != v.Uid {
|
||||||
names = append(names, v.Info.Name)
|
names = append(names, v.Info.Name)
|
||||||
uids = append(uids, v.Uid)
|
uids = append(uids, v.Uid)
|
||||||
heros = append(heros, v.Hero)
|
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 {
|
if list.RefreshNum >= this.module.ModuleTools.GetGlobalConf().FriendHelpHeroRefreshNum {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
list.RefreshNum++
|
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)))
|
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()) {
|
for cur.Next(context.TODO()) {
|
||||||
tmp := &pb.DBFriend{}
|
tmp := &pb.DBFriend{}
|
||||||
if err = cur.Decode(tmp); err == nil {
|
if err = cur.Decode(tmp); err == nil {
|
||||||
if session.GetUserId() != tmp.Uid {
|
if session.GetUserId() != tmp.Uid {
|
||||||
|
if int32(len(list.Data)) >= strangerCount {
|
||||||
|
break
|
||||||
|
}
|
||||||
ahero = append(ahero, tmp.Hero)
|
ahero = append(ahero, tmp.Hero)
|
||||||
list.Data[tmp.Uid] = tmp.Info.Name
|
list.Data[tmp.Uid] = tmp.Info.Name
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/redis/pipe"
|
"go_dreamfactory/lego/sys/redis/pipe"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"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())
|
pipe *pipe.RedisPipe = this.DBModel.Redis.RedisPipe(context.TODO())
|
||||||
menbers *redis.Z
|
menbers *redis.Z
|
||||||
cmd *redis.IntCmd
|
cmd *redis.IntCmd
|
||||||
|
tableName string
|
||||||
)
|
)
|
||||||
|
|
||||||
menbers = &redis.Z{Score: float64(Score), Member: uid}
|
menbers = &redis.Z{Score: float64(Score), Member: uid}
|
||||||
|
tableName = fmt.Sprintf("%s-%s", db.CrossTag(), this.TableName+strconv.Itoa(int(nandu)))
|
||||||
if cmd = pipe.ZAdd(this.TableName+strconv.Itoa(nandu), menbers); err != nil {
|
if cmd = pipe.ZAdd(tableName, menbers); err != nil {
|
||||||
this.module.Errorln(err)
|
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) {
|
func (this *modelRank) queryIntegralRankUser(nandu int) (ranks []string, err error) {
|
||||||
var (
|
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)
|
this.module.Errorln(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user