From b2cb400165fcc2f044e0ebb7068cc4b9784ceb79 Mon Sep 17 00:00:00 2001 From: liwei <2211068034@qq.com> Date: Wed, 26 Jul 2023 15:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=B7=A5=E4=BC=9A=E6=88=98?= =?UTF-8?q?=E6=96=97=E6=8E=92=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 6 ++- modules/guildgve/api_challengefinish.go | 1 + modules/guildgve/api_friendsrecord.go | 18 ++++++- modules/guildgve/modelUnionRoulette.go | 2 +- modules/guildgve/modelbattlerank.go | 67 +++++++++++++++++++++++++ modules/guildgve/modelrank.go | 2 +- modules/guildgve/module.go | 2 + pb/guildgve_msg.pb.go | 34 ++++++++----- 8 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 modules/guildgve/modelbattlerank.go diff --git a/comm/const.go b/comm/const.go index bb6cf91f2..f62c123a4 100644 --- a/comm/const.go +++ b/comm/const.go @@ -300,9 +300,11 @@ const ( TableGuildMember = "guildmember" ///工会轮盘 - TableUnionroulette = "unionroulette" + TableGuildroulette = "guildoulette" ///工会排行榜 - TableUnionrank = "unionrank" + TableGuildGverank = "guildgverank" + ///工会战斗排行排行榜 + TableGuildGvebattlerank = "guildgvebattlerank" //全局表 TableGlobal = "global" diff --git a/modules/guildgve/api_challengefinish.go b/modules/guildgve/api_challengefinish.go index 0cfac7fbf..50754a6c5 100644 --- a/modules/guildgve/api_challengefinish.go +++ b/modules/guildgve/api_challengefinish.go @@ -111,6 +111,7 @@ func (this *apiComp) ChallengeFinish(session comm.IUserSession, req *pb.GuildGve Harm: req.Report.Harm, } member.Record[req.Boosid] = record + go this.module.modelbattlerank.updateRank(req.Boosid, req.Report.Harm, record.User.Uid) for i, v := range req.Report.Info.Redflist[0].Team { if int32(i) == req.Report.Info.Redflist[0].Leadpos && v != nil { record.CaptainHeroId = v.HeroID diff --git a/modules/guildgve/api_friendsrecord.go b/modules/guildgve/api_friendsrecord.go index 831b021e8..b796aa4f9 100644 --- a/modules/guildgve/api_friendsrecord.go +++ b/modules/guildgve/api_friendsrecord.go @@ -7,7 +7,7 @@ import ( // 参数校验 func (this *apiComp) FriendsRecordCheck(session comm.IUserSession, req *pb.GuildGveFriendsRecordReq) (errdata *pb.ErrorData) { - if len(req.Friends) == 0 || len(req.Friends) > 50 { + if req.QueryType == 1 && (len(req.Friends) == 0 || len(req.Friends) > 50) { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), @@ -21,6 +21,7 @@ func (this *apiComp) FriendsRecordCheck(session comm.IUserSession, req *pb.Guild func (this *apiComp) FriendsRecord(session comm.IUserSession, req *pb.GuildGveFriendsRecordReq) (errdata *pb.ErrorData) { var ( member []*pb.DBGuildMember + uids []string record []*pb.DBGveRecord err error ) @@ -28,7 +29,20 @@ func (this *apiComp) FriendsRecord(session comm.IUserSession, req *pb.GuildGveFr return } - if member, err = this.module.modelGuildMember.inquireGuildMembers(req.Friends); err != nil { + if req.QueryType == 0 { + if uids, err = this.module.modelbattlerank.queryRankUser(req.Boosid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + } else { + uids = req.Friends + } + + if member, err = this.module.modelGuildMember.inquireGuildMembers(uids); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), diff --git a/modules/guildgve/modelUnionRoulette.go b/modules/guildgve/modelUnionRoulette.go index 66e7c0902..9a81cb7bc 100644 --- a/modules/guildgve/modelUnionRoulette.go +++ b/modules/guildgve/modelUnionRoulette.go @@ -21,7 +21,7 @@ type ModelUnionroulette struct { func (this *ModelUnionroulette) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompModel.Init(service, module, comp, options) - this.TableName = comm.TableUnionroulette + this.TableName = comm.TableGuildroulette this.module = module.(*GuildGve) return } diff --git a/modules/guildgve/modelbattlerank.go b/modules/guildgve/modelbattlerank.go new file mode 100644 index 000000000..fcb90b42c --- /dev/null +++ b/modules/guildgve/modelbattlerank.go @@ -0,0 +1,67 @@ +package guildgve + +import ( + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + "sync" + + "github.com/go-redis/redis/v8" +) + +type Modelbattlerank struct { + modules.MCompModel + module *GuildGve + conflock sync.RWMutex + bossconf *pb.DBGuildGveBossConf +} + +func (this *Modelbattlerank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.MCompModel.Init(service, module, comp, options) + this.TableName = comm.TableGuildGvebattlerank + this.module = module.(*GuildGve) + return +} + +func (this *Modelbattlerank) Start() (err error) { + err = this.MCompModel.Start() + return +} + +func (this *Modelbattlerank) key(boos int32) string { + return fmt.Sprintf("%s:%d", this.TableName, boos) +} + +// 获取排行榜前50的用户名单 +func (this *Modelbattlerank) queryRankUser(boos int32) (ranks []string, err error) { + var ( + key string + result []string + ) + key = this.key(boos) + if result, err = this.DBModel.Redis.ZRevRange(key, 0, 50).Result(); err != nil { + this.module.Errorln(err) + return + } + ranks = make([]string, 0) + for i := 0; i < len(result); i += 1 { + ranks = append(ranks, result[i]) + } + return +} + +// 更新排名 +func (this *Modelbattlerank) updateRank(boos int32, score int32, member string) (err error) { + var ( + key string + menbers *redis.Z + ) + key = this.key(boos) + menbers = &redis.Z{Score: float64(score), Member: member} + if err = this.Redis.ZAdd(key, menbers); err != nil { + this.module.Errorln(err) + } + return +} diff --git a/modules/guildgve/modelrank.go b/modules/guildgve/modelrank.go index f20b4be27..e9d096a59 100644 --- a/modules/guildgve/modelrank.go +++ b/modules/guildgve/modelrank.go @@ -25,7 +25,7 @@ type modelRank struct { func (this *modelRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompModel.Init(service, module, comp, options) - this.TableName = comm.TableUnionrank + this.TableName = comm.TableGuildGverank this.module = module.(*GuildGve) return } diff --git a/modules/guildgve/module.go b/modules/guildgve/module.go index b06432c2b..e52d79b1f 100644 --- a/modules/guildgve/module.go +++ b/modules/guildgve/module.go @@ -23,6 +23,7 @@ type GuildGve struct { modelGuildGve *ModelUniongve modelUnionroulette *ModelUnionroulette modelGuildMember *ModelGuildMember + modelbattlerank *Modelbattlerank modelRank *modelRank configure *MCompConfigure } @@ -64,6 +65,7 @@ func (this *GuildGve) OnInstallComp() { this.configure = this.RegisterComp(new(MCompConfigure)).(*MCompConfigure) this.modelGuildGve = this.RegisterComp(new(ModelUniongve)).(*ModelUniongve) this.modelGuildMember = this.RegisterComp(new(ModelGuildMember)).(*ModelGuildMember) + this.modelbattlerank = this.RegisterComp(new(Modelbattlerank)).(*Modelbattlerank) this.modelUnionroulette = this.RegisterComp(new(ModelUnionroulette)).(*ModelUnionroulette) this.modelRank = this.RegisterComp(new(modelRank)).(*modelRank) } diff --git a/pb/guildgve_msg.pb.go b/pb/guildgve_msg.pb.go index 87c694754..c3626fc95 100644 --- a/pb/guildgve_msg.pb.go +++ b/pb/guildgve_msg.pb.go @@ -976,8 +976,9 @@ type GuildGveFriendsRecordReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Boosid int32 `protobuf:"varint,1,opt,name=boosid,proto3" json:"boosid"` - Friends []string `protobuf:"bytes,2,rep,name=friends,proto3" json:"friends"` //奖励 + Boosid int32 `protobuf:"varint,1,opt,name=boosid,proto3" json:"boosid"` + QueryType int32 `protobuf:"varint,2,opt,name=queryType,proto3" json:"queryType"` // 0 全服排行榜 1 好友推荐 + Friends []string `protobuf:"bytes,3,rep,name=friends,proto3" json:"friends"` //好友id } func (x *GuildGveFriendsRecordReq) Reset() { @@ -1019,6 +1020,13 @@ func (x *GuildGveFriendsRecordReq) GetBoosid() int32 { return 0 } +func (x *GuildGveFriendsRecordReq) GetQueryType() int32 { + if x != nil { + return x.QueryType + } + return 0 +} + func (x *GuildGveFriendsRecordReq) GetFriends() []string { if x != nil { return x.Friends @@ -1178,18 +1186,20 @@ var file_guildgve_guildgve_msg_proto_rawDesc = []byte{ 0x50, 0x75, 0x73, 0x68, 0x12, 0x2e, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x44, 0x42, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x6f, 0x75, 0x6c, 0x65, 0x74, 0x74, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x22, 0x4c, 0x0a, 0x18, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x47, 0x76, 0x65, + 0x63, 0x6f, 0x72, 0x64, 0x22, 0x6a, 0x0a, 0x18, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x47, 0x76, 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, - 0x6e, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, - 0x64, 0x73, 0x22, 0x59, 0x0a, 0x19, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x47, 0x76, 0x65, 0x46, 0x72, - 0x69, 0x65, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, - 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x24, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, - 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x47, 0x76, 0x65, 0x52, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x71, 0x75, 0x65, 0x72, + 0x79, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x71, 0x75, 0x65, + 0x72, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, + 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, + 0x22, 0x59, 0x0a, 0x19, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x47, 0x76, 0x65, 0x46, 0x72, 0x69, 0x65, + 0x6e, 0x64, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, + 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, + 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x24, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x47, 0x76, 0x65, 0x52, 0x65, 0x63, + 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (