diff --git a/comm/const.go b/comm/const.go index 60746ee7e..1fdb581dd 100644 --- a/comm/const.go +++ b/comm/const.go @@ -295,6 +295,8 @@ const ( TableUniongve = "uniongve" ///工会轮盘 TableUnionroulette = "unionroulette" + ///工会排行榜 + TableUnionrank = "unionrank" //全局表 TableGlobal = "global" ) diff --git a/comm/imodule.go b/comm/imodule.go index 1d05c8c71..839185093 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -370,7 +370,7 @@ type ( // 获取我的公会成员 MembersByUid(uid string) (list []*pb.SociatyMemberInfo) // 获取公会成员 - MembersBySociatyId(sociatyId string) (list []*pb.SociatyMemberInfo) + MembersBySociatyId(sociatyId string) (list []*pb.SociatyMemberInfo, errdata *pb.ErrorData) // 设置工会经验 BingoSetExp(session IUserSession, exp int32) error // 设置工会活跃度 diff --git a/modules/chat/modelChat.go b/modules/chat/modelChat.go index 3df07c5ce..4f704b182 100644 --- a/modules/chat/modelChat.go +++ b/modules/chat/modelChat.go @@ -20,13 +20,13 @@ var unionchatkey = "chat:union" var crosschatkey = "chat:cross" var systemchatkey = "chat:system" -///论坛 数据组件 +// /论坛 数据组件 type modelChatComp struct { modules.MCompModel module *Chat } -//组件初始化接口 +// 组件初始化接口 func (this *modelChatComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { this.TableName = comm.TableChat this.MCompModel.Init(service, module, comp, opt) @@ -38,7 +38,7 @@ func (this *modelChatComp) Init(service core.IService, module core.IModule, comp return } -//查询用户未读消息 +// 查询用户未读消息 func (this *modelChatComp) queryUserMsg(uid string) (result []*pb.DBChat, err error) { var ( c *mongo.Cursor @@ -62,7 +62,7 @@ func (this *modelChatComp) queryUserMsg(uid string) (result []*pb.DBChat, err er return } -//查询用户未读消息 +// 查询用户未读消息 func (this *modelChatComp) getChatQueue(channel pb.ChatChannel, stag, union string, area int32) (result []*pb.DBChat, err error) { var ( key string @@ -123,7 +123,7 @@ func (this *modelChatComp) getChatQueue(channel pb.ChatChannel, stag, union stri return } -//添加跨服频道成员 +// 添加跨服频道成员 func (this *modelChatComp) addCrossChannelMember(session comm.IUserSession) (channel int32, err error) { udata := &pb.CacheUser{ Uid: session.GetUserId(), @@ -159,7 +159,7 @@ func (this *modelChatComp) addCrossChannelMember(session comm.IUserSession) (cha return } -//切换跨服频道 +// 切换跨服频道 func (this *modelChatComp) chanageChannel(session comm.IUserSession, channel int32) (err error, ok bool) { udata := &pb.CacheUser{ Uid: session.GetUserId(), @@ -190,7 +190,7 @@ func (this *modelChatComp) chanageChannel(session comm.IUserSession, channel int return } -//读取跨服聊天频道下成员 +// 读取跨服聊天频道下成员 func (this *modelChatComp) getCrossChannelMember(channel int32) (result []*pb.CacheUser, err error) { key := fmt.Sprintf("%s-%d-member", crosschatkey, channel) temp := make(map[string]*pb.CacheUser, 0) @@ -207,7 +207,7 @@ func (this *modelChatComp) getCrossChannelMember(channel int32) (result []*pb.Ca return } -//移除频道成员 +// 移除频道成员 func (this *modelChatComp) removeCrossChannelMember(uid string) (err error) { var ( result *pb.DBUserExpand @@ -225,7 +225,7 @@ func (this *modelChatComp) removeCrossChannelMember(uid string) (err error) { return } -//保存用户聊天消息 +// 保存用户聊天消息 func (this *modelChatComp) saveUserMsg(msg *pb.DBChat) (err error) { if _, err = this.DB.InsertOne(core.SqlTable(this.TableName), msg); err != nil { this.module.Errorf("err:%v", err) @@ -320,7 +320,7 @@ func (this *modelChatComp) addChatMsg(key string, count int64, msgs ...*pb.DBCha return } -//发送聊天消息到世界频道 +// 发送聊天消息到世界频道 func (this *modelChatComp) sendChatToWorld(chat *pb.DBChat, queuecount int32) (err error) { if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", worldchatkey, chat.Stag), int64(queuecount), chat); err != nil { this.module.Errorln(err) @@ -333,20 +333,28 @@ func (this *modelChatComp) sendChatToWorld(chat *pb.DBChat, queuecount int32) (e return } -//发送聊天消息到工会频道 -func (this *modelChatComp) sendChatToUnion(chat *pb.DBChat, queuecount int32) (err error) { +// 发送聊天消息到工会频道 +func (this *modelChatComp) sendChatToUnion(chat *pb.DBChat, queuecount int32) (errdata *pb.ErrorData) { + var ( + err error + ) if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", unionchatkey, chat.UnionId), int64(queuecount), chat); err != nil { this.module.Errorln(err) + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } return } - if err = this.module.pushChatToUnion(chat); err != nil { - this.module.Errorln(err) + if errdata = this.module.pushChatToUnion(chat); errdata != nil { + this.module.Errorln(errdata) return } return } -//发送聊天消息到工会频道 +// 发送聊天消息到工会频道 func (this *modelChatComp) sendChatToCrossServer(chat *pb.DBChat, queuecount int32) (err error) { if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, chat.ChannelId), int64(queuecount), chat); err != nil { this.module.Errorln(err) @@ -358,7 +366,7 @@ func (this *modelChatComp) sendChatToCrossServer(chat *pb.DBChat, queuecount int return } -//发送聊天消息到私聊频道 +// 发送聊天消息到私聊频道 func (this *modelChatComp) sendChatToSystem(chat *pb.DBChat) (err error) { if err = this.module.pushChatToSystem(chat); err != nil { this.module.Errorln(err) @@ -367,7 +375,7 @@ func (this *modelChatComp) sendChatToSystem(chat *pb.DBChat) (err error) { return } -//发送聊天消息到私聊频道 +// 发送聊天消息到私聊频道 func (this *modelChatComp) sendChatToPrivate(chat *pb.DBChat) (err error) { if err = this.module.pushChatToPrivate(chat); err != nil { this.module.Errorln(err) diff --git a/modules/chat/module.go b/modules/chat/module.go index 1920143ec..cc706dc27 100644 --- a/modules/chat/module.go +++ b/modules/chat/module.go @@ -2,6 +2,7 @@ package chat import ( "context" + "errors" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" @@ -93,6 +94,7 @@ func (this *Chat) EventUserOffline(uid, sessionid string) { func (this *Chat) Rpc_ModuleChatPushChat(ctx context.Context, args *pb.DBChat, reply *pb.EmptyResp) (err error) { var ( max_chat int32 + errdata *pb.ErrorData ) if max_chat, err = this.configure.GetChannelRecordMax(); err != nil { this.Errorln(err) @@ -106,7 +108,8 @@ func (this *Chat) Rpc_ModuleChatPushChat(ctx context.Context, args *pb.DBChat, r } break case pb.ChatChannel_Union: - if err = this.modelChat.sendChatToUnion(args, max_chat); err != nil { + if errdata = this.modelChat.sendChatToUnion(args, max_chat); errdata != nil { + err = errors.New(errdata.Message) this.Errorln(err) return } @@ -189,8 +192,8 @@ func (this *Chat) SendUnionChat(msg *pb.DBChat) (errdata *pb.ErrorData) { return } if this.IsCross() { - if err = this.modelChat.sendChatToUnion(msg, max_chat); err != nil { - this.Errorln(err) + if errdata = this.modelChat.sendChatToUnion(msg, max_chat); errdata != nil { + this.Errorln(errdata) return } } else { @@ -353,8 +356,11 @@ func (this *Chat) pushChatToWorld(msg *pb.DBChat) (err error) { } // 推送消息到工会 -func (this *Chat) pushChatToUnion(msg *pb.DBChat) (err error) { - if members := this.sociaty.MembersBySociatyId(msg.UnionId); members != nil { +func (this *Chat) pushChatToUnion(msg *pb.DBChat) (errdata *pb.ErrorData) { + var ( + members []*pb.SociatyMemberInfo + ) + if members, errdata = this.sociaty.MembersBySociatyId(msg.UnionId); members != nil { users := make([]string, 0, len(members)) for _, v := range members { if v.OfflineTime == 0 { //离线时间为0 表示在线 diff --git a/modules/comp_model.go b/modules/comp_model.go index f3d0e54e8..a859fdcf7 100644 --- a/modules/comp_model.go +++ b/modules/comp_model.go @@ -113,6 +113,11 @@ func (this *MCompModel) Get(id string, data interface{}, opt ...db.DBOption) (er return this.DBModel.Get(id, data, opt...) } +// 读取全部数据 +func (this *MCompModel) GetByID(id string, data interface{}, opt ...db.DBOption) (err error) { + return this.DBModel.GetByID(id, data, opt...) +} + // 读取多个数据对象 func (this *MCompModel) Gets(ids []string, data interface{}, opt ...db.DBOption) (onfound []string, err error) { return this.DBModel.Gets(ids, data, opt...) diff --git a/modules/passon/module.go b/modules/passon/module.go index 5afcc11d0..adeef5033 100644 --- a/modules/passon/module.go +++ b/modules/passon/module.go @@ -83,7 +83,7 @@ func (this *Passon) HeroUpLv(session comm.IUserSession, heroid string, lv int32) return heros[i].Lv > heros[j].Lv } else { conf_i, _ := this.ModuleTools.GetHeroConfig(heros[i].HeroID) - conf_j, _ := this.ModuleTools.GetHeroConfig(heros[i].HeroID) + conf_j, _ := this.ModuleTools.GetHeroConfig(heros[j].HeroID) return conf_i.Color > conf_j.Color } }) diff --git a/modules/sociaty/api_cross_apply.go b/modules/sociaty/api_cross_apply.go index ac51a97e8..e5261b2fb 100644 --- a/modules/sociaty/api_cross_apply.go +++ b/modules/sociaty/api_cross_apply.go @@ -23,17 +23,22 @@ func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.SociatyApplyR } func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) (errdata *pb.ErrorData) { + var ( + sociaty *pb.DBSociaty + err error + ) + if errdata = this.ApplyCheck(session, req); errdata != nil { return } uid := session.GetUserId() - sociaty := this.module.modelSociaty.getSociaty(req.SociatyId) - if sociaty == nil { + if sociaty, err = this.module.modelSociaty.getSociaty(req.SociatyId); err != nil { errdata = &pb.ErrorData{ - Code: pb.ErrorCode_SociatyNoFound, - Title: pb.ErrorCode_SociatyNoFound.ToString(), + Code: pb.ErrorCode_SociatyNoFound, + Title: pb.ErrorCode_SociatyNoFound.ToString(), + Message: err.Error(), } return } diff --git a/modules/sociaty/api_cross_applycancel.go b/modules/sociaty/api_cross_applycancel.go index 2b81bc904..e79130eb0 100644 --- a/modules/sociaty/api_cross_applycancel.go +++ b/modules/sociaty/api_cross_applycancel.go @@ -20,17 +20,22 @@ func (this *apiComp) ApplyCancelCheck(session comm.IUserSession, req *pb.Sociaty } func (this *apiComp) ApplyCancel(session comm.IUserSession, req *pb.SociatyApplyCancelReq) (errdata *pb.ErrorData) { + var ( + uid string + sociaty *pb.DBSociaty + + err error + ) + if errdata = this.ApplyCancelCheck(session, req); errdata != nil { return } - - uid := session.GetUserId() - - sociaty := this.module.modelSociaty.getSociaty(req.SociatyId) - if sociaty != nil && sociaty.Id == "" { + uid = session.GetUserId() + if sociaty, err = this.module.modelSociaty.getSociaty(req.SociatyId); err != nil { errdata = &pb.ErrorData{ - Code: pb.ErrorCode_SociatyNoFound, - Title: pb.ErrorCode_SociatyNoFound.ToString(), + Code: pb.ErrorCode_SociatyNoFound, + Title: pb.ErrorCode_SociatyNoFound.ToString(), + Message: err.Error(), } return } diff --git a/modules/sociaty/api_cross_applylist.go b/modules/sociaty/api_cross_applylist.go index 4c83d36a7..77a8a1f53 100644 --- a/modules/sociaty/api_cross_applylist.go +++ b/modules/sociaty/api_cross_applylist.go @@ -20,16 +20,22 @@ func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.SociatyAp } func (this *apiComp) ApplyList(session comm.IUserSession, req *pb.SociatyApplyListReq) (errdata *pb.ErrorData) { + var ( + uid string + sociaty *pb.DBSociaty + + err error + ) + if errdata = this.ApplyListCheck(session, req); errdata != nil { return } - - uid := session.GetUserId() - sociaty := this.module.modelSociaty.getSociaty(req.SociatyId) - if sociaty == nil { + uid = session.GetUserId() + if sociaty, err = this.module.modelSociaty.getSociaty(req.SociatyId); err != nil { errdata = &pb.ErrorData{ - Code: pb.ErrorCode_SociatyNoFound, - Title: pb.ErrorCode_SociatyNoFound.ToString(), + Code: pb.ErrorCode_SociatyNoFound, + Title: pb.ErrorCode_SociatyNoFound.ToString(), + Message: err.Error(), } return } diff --git a/modules/sociaty/api_cross_create.go b/modules/sociaty/api_cross_create.go index a77c2bbd6..c4697bc25 100644 --- a/modules/sociaty/api_cross_create.go +++ b/modules/sociaty/api_cross_create.go @@ -62,9 +62,13 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.SociatyCreateReq) user := this.module.ModuleUser.GetUser(uid) if user == nil { this.module.Error("GetRmoteUser not found", log.Field{Key: "uid", Value: uid}) + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: fmt.Sprintf("not found user: %s", uid), + } return } - userExpand, err := this.module.ModuleUser.GetUserExpand(uid) if err != nil { errdata = &pb.ErrorData{ diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index c5bbe55a0..4fe2935dc 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -167,14 +167,11 @@ func (this *ModelSociaty) findByName(name string) *pb.DBSociaty { } // 获取公会 -func (this *ModelSociaty) getSociaty(sociatyId string) (sociaty *pb.DBSociaty) { +func (this *ModelSociaty) getSociaty(sociatyId string) (sociaty *pb.DBSociaty, err error) { sociaty = &pb.DBSociaty{} - if err := this.GetListObj(comm.RDS_EMPTY, sociatyId, sociaty); err != nil { - log.Error("GetListObj", log.Field{Key: "sociatyId", Value: sociatyId}) - return nil - } - if sociaty.Id == "" { - return nil + if err = this.GetListObj(comm.RDS_EMPTY, sociatyId, sociaty); err != nil { + this.module.Error("获取工会信息 失败", log.Field{Key: "sociatyId", Value: sociatyId}, log.Field{Key: "err", Value: err.Error()}) + return } return } @@ -217,7 +214,7 @@ func (this *ModelSociaty) getUserSociaty(uid string) (sociaty *pb.DBSociaty) { return } if userEx.SociatyId != "" { - sociaty = this.getSociaty(userEx.SociatyId) + sociaty, _ = this.getSociaty(userEx.SociatyId) if sociaty != nil { //验证是否解散 if this.isDismiss(sociaty) { diff --git a/modules/sociaty/module.go b/modules/sociaty/module.go index 0b3259146..80b948f5c 100644 --- a/modules/sociaty/module.go +++ b/modules/sociaty/module.go @@ -115,7 +115,7 @@ func (this *Sociaty) ProcessAccuse(uid, sociatyId string) { if t == 0 { return } - sociaty := this.modelSociaty.getSociaty(sociatyId) + sociaty, _ := this.modelSociaty.getSociaty(sociatyId) if sociaty != nil { if sociaty.AccuseTime > 0 { now := configure.Now().Unix() @@ -142,9 +142,20 @@ func (this *Sociaty) MembersByUid(uid string) (list []*pb.SociatyMemberInfo) { } // 获取公会成员 -func (this *Sociaty) MembersBySociatyId(sociatyId string) (list []*pb.SociatyMemberInfo) { - sociaty := this.modelSociaty.getSociaty(sociatyId) - return this.modelSociaty.members(sociaty) +func (this *Sociaty) MembersBySociatyId(sociatyId string) (list []*pb.SociatyMemberInfo, errdata *pb.ErrorData) { + var ( + sociaty *pb.DBSociaty + err error + ) + if sociaty, err = this.modelSociaty.getSociaty(sociatyId); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + return this.modelSociaty.members(sociaty), nil } // 批量获取公户信息 @@ -212,7 +223,11 @@ func (this *Sociaty) Reddot(session comm.IUserSession, rid ...comm.ReddotType) ( // 跨服获取公会 func (this *Sociaty) RpcGetSociaty(ctx context.Context, req *pb.RPCGeneralReqA1, reply *pb.DBSociaty) error { this.Debug("Rpc_ModuleSociaty", log.Field{Key: "req", Value: req.String()}) - sociaty := this.modelSociaty.getSociaty(req.Param1) + var ( + sociaty *pb.DBSociaty + err error + ) + sociaty, err = this.modelSociaty.getSociaty(req.Param1) reply.Id = sociaty.Id reply.Lv = sociaty.Lv reply.Exp = sociaty.Exp @@ -229,7 +244,7 @@ func (this *Sociaty) RpcGetSociaty(ctx context.Context, req *pb.RPCGeneralReqA1, reply.Activity = sociaty.Activity reply.AccuseTime = sociaty.AccuseTime reply.ApplyRecord = sociaty.ApplyRecord - return nil + return err } type SociatyUpdateParam struct { diff --git a/modules/timer/module.go b/modules/timer/module.go index 54d0eab8b..171dc8ea5 100644 --- a/modules/timer/module.go +++ b/modules/timer/module.go @@ -29,11 +29,12 @@ type Timer struct { //season *SeasonPagoda forum *ForumComp arena *ArenaComp + sociaty *SociatyComp parkour *ParkourComp caravan *CaravanRank } -//模块名 +// 模块名 func (this *Timer) GetType() core.M_Modules { return comm.ModuleTimer } @@ -43,7 +44,7 @@ func (this *Timer) NewOptions() (options core.IModuleOptions) { return new(Options) } -//模块初始化接口 注册用户创建角色事件 +// 模块初始化接口 注册用户创建角色事件 func (this *Timer) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) @@ -62,11 +63,12 @@ func (this *Timer) OnInstallComp() { this.chat = this.RegisterComp(new(ChatComp)).(*ChatComp) //this.season = this.RegisterComp(new(SeasonPagoda)).(*SeasonPagoda) this.arena = this.RegisterComp(new(ArenaComp)).(*ArenaComp) + this.sociaty = this.RegisterComp(new(SociatyComp)).(*SociatyComp) this.parkour = this.RegisterComp(new(ParkourComp)).(*ParkourComp) this.caravan = this.RegisterComp(new(CaravanRank)).(*CaravanRank) } -//跨服对象获取数据操作对象 +// 跨服对象获取数据操作对象 func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, err error) { var ( stag string @@ -88,7 +90,7 @@ func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, er return } -//日志 +// 日志 func (this *Timer) Enabled(lvl log.Loglevel) bool { return this.options.GetLog().Enabled(lvl) } @@ -96,7 +98,7 @@ func (this *Timer) SetName(name string) { this.options.GetLog().SetName(name) } -//日志接口 +// 日志接口 func (this *Timer) Debug(msg string, args ...log.Field) { this.options.GetLog().Debug(msg, args...) } diff --git a/modules/timer/sociaty.go b/modules/timer/sociaty.go new file mode 100644 index 000000000..166b38ef6 --- /dev/null +++ b/modules/timer/sociaty.go @@ -0,0 +1,54 @@ +package timer + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" + + "go_dreamfactory/lego/base" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/cron" +) + +/* +工会结算计时器 +*/ +type SociatyComp struct { + modules.MCompConfigure + service base.IRPCXService + module *Timer + takes []cron.EntryID +} + +// 组件初始化接口 +func (this *SociatyComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MCompConfigure.Init(service, module, comp, options) + this.service = service.(base.IRPCXService) + this.module = module.(*Timer) + this.takes = make([]cron.EntryID, 0) + return +} + +// 自由跨服环境下开启此功能 +func (this *SociatyComp) Start() (err error) { + err = this.MCompConfigure.Start() + if db.IsCross() { + if _, err = cron.AddFunc("0 0 1 ? * 1", this.timer); err != nil { + this.module.Errorf("cron.AddFunc err:%v", err) + } + } + return +} + +func (this *SociatyComp) timer() { + if _, err := this.service.RpcGo(context.Background(), + comm.Service_Worker, + string(comm.Rpc_ModuleGuildBossSettlement), + pb.EmptyReq{}, + nil, + ); err != nil { + this.module.Errorln(err) + } +} diff --git a/modules/tools/modelGlobal.go b/modules/tools/modelGlobal.go index bd6220fef..902b49c7f 100644 --- a/modules/tools/modelGlobal.go +++ b/modules/tools/modelGlobal.go @@ -33,7 +33,7 @@ func (this *modelGlobal) GetGlobalData(key string, v interface{}) (err error) { // 更新全局配置 func (this *modelGlobal) UpdateGlobalData(key string, v interface{}) (err error) { - if _, err = this.DBModel.DB.UpdateOne(core.SqlTable(this.TableName), bson.M{"_id": key}, v, options.Update().SetUpsert(true)); err != nil { + if _, err = this.DBModel.DB.UpdateOne(core.SqlTable(this.TableName), bson.M{"_id": key}, bson.M{"$set": v}, options.Update().SetUpsert(true)); err != nil { this.module.Error("GetGlobalData err", log.Field{Key: "key", Value: key}, log.Field{Key: "err", Value: err.Error()}) } return diff --git a/modules/uniongve/api_challengefinish.go b/modules/uniongve/api_challengefinish.go index 7a3a1e0f5..2c4c75f28 100644 --- a/modules/uniongve/api_challengefinish.go +++ b/modules/uniongve/api_challengefinish.go @@ -10,13 +10,13 @@ import ( ) // 参数校验 -func (this *apiComp) ChallengeFinishCheck(session comm.IUserSession, req *pb.UniongveChallengeFinishRep) (errdata *pb.ErrorData) { +func (this *apiComp) ChallengeFinishCheck(session comm.IUserSession, req *pb.UniongveChallengeFinishReq) (errdata *pb.ErrorData) { return } // 获取工会boos战信息 -func (this *apiComp) ChallengeFinish(session comm.IUserSession, req *pb.UniongveChallengeFinishRep) (errdata *pb.ErrorData) { +func (this *apiComp) ChallengeFinish(session comm.IUserSession, req *pb.UniongveChallengeFinishReq) (errdata *pb.ErrorData) { var ( conf *cfg.GameGuildBossData score *cfg.GameGuildBossScoreData diff --git a/modules/uniongve/api_roulette.go b/modules/uniongve/api_roulette.go index 55d70f422..3aab57e34 100644 --- a/modules/uniongve/api_roulette.go +++ b/modules/uniongve/api_roulette.go @@ -58,7 +58,7 @@ func (this *apiComp) Roulette(session comm.IUserSession, req *pb.UniongveRoulett } if confs[index].Push == 1 { //推送通知 - go this.module.modelUnionroulette.roulettechangePush(session.GetUserId(), req.Unionid, award) + go this.module.modelUnionroulette.roulettechangePush(req.Unionid, session.GetUserId(), award) } session.SendMsg(string(this.module.GetType()), "roulette", &pb.UniongveRouletteResp{Cid: confs[index].Id, Award: award}) diff --git a/modules/uniongve/modelUnionRoulette.go b/modules/uniongve/modelUnionRoulette.go index c75103749..0bdfd0145 100644 --- a/modules/uniongve/modelUnionRoulette.go +++ b/modules/uniongve/modelUnionRoulette.go @@ -60,7 +60,7 @@ func (this *ModelUnionroulette) updateUnionRoulette(data *pb.DBUnionRouletteReco // 分布式锁 func (this *ModelUnionroulette) userlock(id string) (result *redis.RedisMutex, err error) { - return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("unionroulette:%s", id)) + return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("lockunionroulette:%s", id)) } // boos 信息变化推送 @@ -69,11 +69,11 @@ func (this *ModelUnionroulette) roulettechangePush(unionid string, uid string, a info *pb.DBUnionRouletteRecord members []*pb.SociatyMemberInfo users []string = make([]string, 0) + errdata *pb.ErrorData err error ) - members = this.module.sociaty.MembersBySociatyId(unionid) - if members == nil || len(members) == 0 { - this.module.Error("MembersBySociatyId is nil !") + if members, errdata = this.module.sociaty.MembersBySociatyId(unionid); errdata != nil { + this.module.Debug("获取工会成员列表!", log.Field{Key: "errdata", Value: errdata}) return } for _, v := range members { @@ -98,5 +98,5 @@ func (this *ModelUnionroulette) roulettechangePush(unionid string, uid string, a this.module.SendMsgToUsers(string(this.module.GetType()), "roulettechange", &pb.UniongveRouletteChangePush{ Record: info, - }) + }, users...) } diff --git a/modules/uniongve/modelUniongve.go b/modules/uniongve/modelUniongve.go index f7f8eecb5..01ac99550 100644 --- a/modules/uniongve/modelUniongve.go +++ b/modules/uniongve/modelUniongve.go @@ -46,8 +46,10 @@ func (this *ModelUniongve) getUnionGve(unionid string) (results *pb.DBUnionGve, confs *pb.DBUnionGveBossConf conf *cfg.GameGuildBossData ) - results = &pb.DBUnionGve{} - if err = this.Get(unionid, results); err != nil && err != mgo.MongodbNil { + results = &pb.DBUnionGve{ + Boos: make([]*pb.DBUnionGveBoss, 0), + } + if err = this.GetByID(unionid, results); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) return } @@ -120,12 +122,16 @@ func (this *ModelUniongve) getGlobalBoos() (conf *pb.DBUnionGveBossConf, err err ) this.conflock.RLock() bossconf = this.bossconf - this.conflock.Unlock() + this.conflock.RUnlock() if bossconf == nil || !utils.IsSameWeek(bossconf.Rtime) { if bossconf, err = this.refreshGlobalBoos(); err != nil { return } + this.conflock.Lock() + this.bossconf = bossconf + this.conflock.Unlock() } + conf = bossconf return } @@ -154,13 +160,16 @@ func (this *ModelUniongve) refreshGlobalBoos() (conf *pb.DBUnionGveBossConf, err this.conflock.Lock() this.bossconf = conf this.conflock.Unlock() - this.module.ModuleTools.UpdateGlobalData(UnionGveBoosCoonfKey, conf) + this.module.ModuleTools.UpdateGlobalData(UnionGveBoosCoonfKey, map[string]interface{}{ + "rtime": conf.Rtime, + "boos": conf.Boos, + }) return } // 分布式锁 func (this *ModelUniongve) userlock(id string) (result *redis.RedisMutex, err error) { - return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("uniongve:%s", id)) + return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("lockuniongve:%s", id)) } // boos 血量变化推送 @@ -168,10 +177,10 @@ func (this *ModelUniongve) booshpchangepush(unionid string, info *pb.DBUnionGve) var ( members []*pb.SociatyMemberInfo users []string = make([]string, 0) + errdata *pb.ErrorData ) - members = this.module.sociaty.MembersBySociatyId(unionid) - if members == nil || len(members) == 0 { - this.module.Error("MembersBySociatyId is nil !") + if members, errdata = this.module.sociaty.MembersBySociatyId(unionid); errdata != nil { + this.module.Debug("获取工会成员列表!", log.Field{Key: "errdata", Value: errdata}) return } for _, v := range members { @@ -180,7 +189,7 @@ func (this *ModelUniongve) booshpchangepush(unionid string, info *pb.DBUnionGve) } this.module.SendMsgToUsers(string(this.module.GetType()), "booschange", &pb.UniongveBoosChangePush{ Info: info, - }) + }, users...) } // 击杀boos @@ -189,15 +198,15 @@ func (this *ModelUniongve) booskill(unionid string, boosid int32, info *pb.DBUni conf *cfg.GameGuildBossData members []*pb.SociatyMemberInfo users []string = make([]string, 0) + errdata *pb.ErrorData err error ) if conf, err = this.module.configure.getguildbossByid(boosid); err != nil { this.module.Errorln(err) return } - members = this.module.sociaty.MembersBySociatyId(unionid) - if members == nil || len(members) == 0 { - this.module.Error("MembersBySociatyId is nil !") + if members, errdata = this.module.sociaty.MembersBySociatyId(unionid); errdata != nil { + this.module.Debug("获取工会成员列表!", log.Field{Key: "errdata", Value: errdata}) return } for _, v := range members { @@ -238,7 +247,7 @@ func (this *ModelUniongve) booskill(unionid string, boosid int32, info *pb.DBUni } this.module.SendMsgToUsers(string(this.module.GetType()), "stagechange", &pb.UniongveStageChangePush{ Info: info, - }) + }, users...) } // boos 信息变化推送 @@ -246,10 +255,10 @@ func (this *ModelUniongve) infochangepush(unionid string, info *pb.DBUnionGve) { var ( members []*pb.SociatyMemberInfo users []string = make([]string, 0) + errdata *pb.ErrorData ) - members = this.module.sociaty.MembersBySociatyId(unionid) - if members == nil || len(members) == 0 { - this.module.Error("MembersBySociatyId is nil !") + if members, errdata = this.module.sociaty.MembersBySociatyId(unionid); errdata != nil { + this.module.Debug("获取工会成员列表!", log.Field{Key: "errdata", Value: errdata}) return } for _, v := range members { @@ -258,5 +267,5 @@ func (this *ModelUniongve) infochangepush(unionid string, info *pb.DBUnionGve) { } this.module.SendMsgToUsers(string(this.module.GetType()), "infochange", &pb.UniongveInfoChangePush{ Info: info, - }) + }, users...) } diff --git a/modules/uniongve/modelrank.go b/modules/uniongve/modelrank.go index 45cb54206..efc8b8c61 100644 --- a/modules/uniongve/modelrank.go +++ b/modules/uniongve/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.TableUnionroulette + this.TableName = comm.TableUnionrank this.module = module.(*UnionGve) return } @@ -116,17 +116,18 @@ func (this *modelRank) raceSettlement() { } -// boos 血量变化推送 +// boos 奖励推送 func (this *modelRank) rankRewardPush(unionid string, reward []*cfg.Gameatn) { var ( members []*pb.SociatyMemberInfo users []string = make([]string, 0) + errdata *pb.ErrorData ) - members = this.module.sociaty.MembersBySociatyId(unionid) - if members == nil || len(members) == 0 { - this.module.Error("MembersBySociatyId is nil !") + if members, errdata = this.module.sociaty.MembersBySociatyId(unionid); errdata != nil { + this.module.Debug("获取工会成员列表!", log.Field{Key: "errdata", Value: errdata}) return } + for _, v := range members { users = append(users, v.Uid) } diff --git a/pb/uniongve_db.pb.go b/pb/uniongve_db.pb.go index a6a3c587c..c5144b331 100644 --- a/pb/uniongve_db.pb.go +++ b/pb/uniongve_db.pb.go @@ -26,7 +26,7 @@ type DBUnionGveBossConf struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key" bson:"_id"` //刷新时间 //唯一ID + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key" bson:"_id"` //唯一ID Rtime int64 `protobuf:"varint,2,opt,name=rtime,proto3" json:"rtime"` //刷新时间 Boos []int32 `protobuf:"varint,3,rep,packed,name=boos,proto3" json:"boos"` //boosid } @@ -90,7 +90,7 @@ type DBUnionGve struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Unionid string `protobuf:"bytes,1,opt,name=unionid,proto3" json:"unionid"` //工会id + Unionid string `protobuf:"bytes,1,opt,name=unionid,proto3" json:"unionid" bson:"_id"` // 背包格子Id Notice string `protobuf:"bytes,2,opt,name=notice,proto3" json:"notice"` //公告 Fire int32 `protobuf:"varint,3,opt,name=fire,proto3" json:"fire"` //火力 Currstage int32 `protobuf:"varint,4,opt,name=currstage,proto3" json:"currstage"` //当前第几阶段 diff --git a/pb/uniongve_msg.pb.go b/pb/uniongve_msg.pb.go index cabc7a445..80e7617c5 100644 --- a/pb/uniongve_msg.pb.go +++ b/pb/uniongve_msg.pb.go @@ -611,7 +611,7 @@ func (x *UniongveChallengeResp) GetInfo() *BattleInfo { } //战斗 完成请求 -type UniongveChallengeFinishRep struct { +type UniongveChallengeFinishReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -621,8 +621,8 @@ type UniongveChallengeFinishRep struct { Report *BattleReport `protobuf:"bytes,3,opt,name=report,proto3" json:"report"` //战报 } -func (x *UniongveChallengeFinishRep) Reset() { - *x = UniongveChallengeFinishRep{} +func (x *UniongveChallengeFinishReq) Reset() { + *x = UniongveChallengeFinishReq{} if protoimpl.UnsafeEnabled { mi := &file_uniongve_uniongve_msg_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -630,13 +630,13 @@ func (x *UniongveChallengeFinishRep) Reset() { } } -func (x *UniongveChallengeFinishRep) String() string { +func (x *UniongveChallengeFinishReq) String() string { return protoimpl.X.MessageStringOf(x) } -func (*UniongveChallengeFinishRep) ProtoMessage() {} +func (*UniongveChallengeFinishReq) ProtoMessage() {} -func (x *UniongveChallengeFinishRep) ProtoReflect() protoreflect.Message { +func (x *UniongveChallengeFinishReq) ProtoReflect() protoreflect.Message { mi := &file_uniongve_uniongve_msg_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -648,26 +648,26 @@ func (x *UniongveChallengeFinishRep) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use UniongveChallengeFinishRep.ProtoReflect.Descriptor instead. -func (*UniongveChallengeFinishRep) Descriptor() ([]byte, []int) { +// Deprecated: Use UniongveChallengeFinishReq.ProtoReflect.Descriptor instead. +func (*UniongveChallengeFinishReq) Descriptor() ([]byte, []int) { return file_uniongve_uniongve_msg_proto_rawDescGZIP(), []int{11} } -func (x *UniongveChallengeFinishRep) GetUnionid() string { +func (x *UniongveChallengeFinishReq) GetUnionid() string { if x != nil { return x.Unionid } return "" } -func (x *UniongveChallengeFinishRep) GetBoosid() int32 { +func (x *UniongveChallengeFinishReq) GetBoosid() int32 { if x != nil { return x.Boosid } return 0 } -func (x *UniongveChallengeFinishRep) GetReport() *BattleReport { +func (x *UniongveChallengeFinishReq) GetReport() *BattleReport { if x != nil { return x.Report } @@ -996,7 +996,7 @@ var file_uniongve_uniongve_msg_proto_rawDesc = []byte{ 0x32, 0x0b, 0x2e, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x75, 0x0a, 0x1a, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x52, 0x65, - 0x70, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x71, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x25, 0x0a, 0x06, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, @@ -1055,7 +1055,7 @@ var file_uniongve_uniongve_msg_proto_goTypes = []interface{}{ (*UniongveRouletteResp)(nil), // 8: UniongveRouletteResp (*UniongveChallengeReq)(nil), // 9: UniongveChallengeReq (*UniongveChallengeResp)(nil), // 10: UniongveChallengeResp - (*UniongveChallengeFinishRep)(nil), // 11: UniongveChallengeFinishRep + (*UniongveChallengeFinishReq)(nil), // 11: UniongveChallengeFinishReq (*UniongveChallengeFinishResp)(nil), // 12: UniongveChallengeFinishResp (*UniongveInfoChangePush)(nil), // 13: UniongveInfoChangePush (*UniongveStageChangePush)(nil), // 14: UniongveStageChangePush @@ -1074,7 +1074,7 @@ var file_uniongve_uniongve_msg_proto_depIdxs = []int32{ 18, // 2: UniongveRouletteResp.award:type_name -> UserAssets 19, // 3: UniongveChallengeReq.battle:type_name -> BattleFormation 20, // 4: UniongveChallengeResp.info:type_name -> BattleInfo - 21, // 5: UniongveChallengeFinishRep.report:type_name -> BattleReport + 21, // 5: UniongveChallengeFinishReq.report:type_name -> BattleReport 18, // 6: UniongveChallengeFinishResp.award:type_name -> UserAssets 17, // 7: UniongveInfoChangePush.info:type_name -> DBUnionGve 17, // 8: UniongveStageChangePush.info:type_name -> DBUnionGve @@ -1229,7 +1229,7 @@ func file_uniongve_uniongve_msg_proto_init() { } } file_uniongve_uniongve_msg_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UniongveChallengeFinishRep); i { + switch v := v.(*UniongveChallengeFinishReq); i { case 0: return &v.state case 1: diff --git a/sys/db/dbmodel.go b/sys/db/dbmodel.go index df2a04b6a..38a87f483 100644 --- a/sys/db/dbmodel.go +++ b/sys/db/dbmodel.go @@ -386,6 +386,27 @@ func (this *DBModel) Get(uid string, data interface{}, opt ...DBOption) (err err return } +// 读取全部数据 +func (this *DBModel) GetByID(id string, data interface{}, opt ...DBOption) (err error) { + //defer log.Debug("DBModel Get", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "data", Value: data}) + if err = this.Redis.HGetAll(this.ukey(id), data); err != nil && err != lgredis.RedisNil { + log.Error("HGetAll 错误!", log.Field{Key: "ukey", Value: this.ukey(id)}, log.Field{Key: "err", Value: err.Error()}) + return + } + if err == lgredis.RedisNil { + if err = this.DB.FindOne(core.SqlTable(this.TableName), bson.M{"_id": id}).Decode(data); err != nil { + return + } + err = this.Redis.HMSet(this.ukey(id), data) + } + // option := newDBOption(opt...) + if this.Expired > 0 { + // this.Redis.Expire(this.ukey(uid), option.Expire) + this.conn.UpDateModelExpired(this.ukey(id), nil, this.Expired) + } + return +} + // 读取多个数据对象 func (this *DBModel) Gets(ids []string, data interface{}, opt ...DBOption) (onfound []string, err error) { //defer log.Debug("DBModel GetListObjs", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "ids", Value: ids}, log.Field{Key: "data", Value: data})