From 8dcb5b95c3b612bba66cf208b86611f5db8e0a04 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 22 Jan 2024 09:58:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A9=E6=88=98=E6=95=B0=E6=8D=AE=20?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=8E=89=E6=B2=A1=E6=9C=89=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E7=9A=84=E7=8E=A9=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api_cross_getassist.go | 33 +++++++++++++++------------ modules/friend/api_cross_refresh.go | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/modules/friend/api_cross_getassist.go b/modules/friend/api_cross_getassist.go index 2c284c6f7..81df20e9d 100644 --- a/modules/friend/api_cross_getassist.go +++ b/modules/friend/api_cross_getassist.go @@ -48,18 +48,18 @@ func (this *apiComp) GetAssistHero(session comm.IUserSession, req *pb.FriendGetA } } leftCount = int32(comm.AssistHeroCount - len(list.Data)) - // 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(int64(0)).SetLimit(int64(leftCount))) //.skip(1).limit(1) - // for cur.Next(context.TODO()) { - // tmp := &pb.DBFriend{} - // if err = cur.Decode(tmp); err == nil { - // if session.GetUserId() != tmp.Uid { - // list.Data[tmp.Uid] = tmp.Info.Name - // heros = append(heros, tmp.Hero) - // } - // } - // } + //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(int64(0)).SetLimit(int64(leftCount))) //.skip(1).limit(1) + for cur.Next(context.TODO()) { + tmp := &pb.DBFriend{} + if err = cur.Decode(tmp); err == nil { + if session.GetUserId() != tmp.Uid && tmp.Info != nil { + list.Data[tmp.Uid] = tmp.Info.Name + heros = append(heros, tmp.Hero) + } + } + } err = this.module.modelAssist.Add(session.GetUserId(), list) session.SendMsg(string(this.module.GetType()), "getassisthero", &pb.FriendGetAssistHeroResp{ @@ -85,9 +85,12 @@ func (this *apiComp) GetAssistHero(session comm.IUserSession, req *pb.FriendGetA for cur.Next(context.TODO()) { tmp := &pb.DBFriend{} if err = cur.Decode(tmp); err == nil { - if session.GetUserId() != tmp.Uid { - list.Data[tmp.Uid] = tmp.Info.Name - heros = append(heros, tmp.Hero) + if session.GetUserId() != tmp.Uid && tmp.Info != nil { + if tmp.Info != nil { + list.Data[tmp.Uid] = tmp.Info.Name + heros = append(heros, tmp.Hero) + } + } } } diff --git a/modules/friend/api_cross_refresh.go b/modules/friend/api_cross_refresh.go index 035880bcb..6ca31c624 100644 --- a/modules/friend/api_cross_refresh.go +++ b/modules/friend/api_cross_refresh.go @@ -86,7 +86,7 @@ func (this *apiComp) RefreshAssistHero(session comm.IUserSession, req *pb.Friend for cur.Next(context.TODO()) { tmp := &pb.DBFriend{} if err = cur.Decode(tmp); err == nil { - if session.GetUserId() != tmp.Uid { + if session.GetUserId() != tmp.Uid && tmp.Info != nil { if int32(len(list.Data)) >= strangerCount { break }