package friend import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" ) //好友列表 func (this *apiComp) RefreshAssistHeroCheck(session comm.IUserSession, req *pb.FriendRefreshAssistHeroReq) (errdata *pb.ErrorData) { return } func (this *apiComp) RefreshAssistHero(session comm.IUserSession, req *pb.FriendRefreshAssistHeroReq) (errdata *pb.ErrorData) { var ( self *pb.DBFriend err error ahero []*pb.AssistHero ) self, err = this.module.modelFriend.GetFriend(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_FriendSelfNoData, Title: pb.ErrorCode_FriendSelfNoData.ToString(), } return } if self.RefreshNum >= this.module.ModuleTools.GetGlobalConf().FriendHelpHeroRefreshNum { return } self.RefreshNum++ if err = this.module.modelFriend.Change(session.GetUserId(), map[string]interface{}{ "refreshNum": self.RefreshNum, }); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_FriendApplyError, Title: pb.ErrorCode_FriendApplyError.ToString(), } return } 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(randomIndex)).SetLimit(12)) //.skip(1).limit(1) for cur.Next(context.TODO()) { tmp := &pb.DBFriend{} if err = cur.Decode(tmp); err == nil { ahero = append(ahero, &pb.AssistHero{ Name: tmp.Info.Name, Hero: tmp.Hero, }) } } session.SendMsg(string(this.module.GetType()), "refreshassisthero", &pb.FriendRefreshAssistHeroResp{ Hero: ahero, }) return }