// package // 公会 // 赵长远 package sociaty import ( "context" "errors" "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "go.mongodb.org/mongo-driver/bson" ) var _ comm.ISociaty = (*Sociaty)(nil) type Sociaty struct { modules.ModuleBase api *apiComp service base.IRPCXService modelSociaty *ModelSociaty modelSociatyTask *ModelSociatyTask modelSociatyLog *ModelSociatyLog configure *configureComp globalConf *cfg.GameGlobalData sociatyActivityConf *cfg.GameGuildActivity sociatyTaskConf *cfg.GameGuildTask sociatySignConf *cfg.GameGuildSign rtaskCondConf *cfg.GameRdtaskCondi } func NewModule() core.IModule { return &Sociaty{} } func (this *Sociaty) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) return } func (this *Sociaty) GetType() core.M_Modules { return comm.ModuleSociaty } func (this *Sociaty) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelSociaty = this.RegisterComp(new(ModelSociaty)).(*ModelSociaty) this.modelSociatyTask = this.RegisterComp(new(ModelSociatyTask)).(*ModelSociatyTask) this.modelSociatyLog = this.RegisterComp(new(ModelSociatyLog)).(*ModelSociatyLog) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } func (this *Sociaty) Start() (err error) { err = this.ModuleBase.Start() this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociaty), this.RpcGetSociaty) this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociatyUpdate), this.RpcUpdateSociaty) this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociatyTask), this.RpcUpdateUserTask) this.globalConf = this.configure.GetGlobalConf() if this.globalConf == nil { err = errors.New("global config not found") return } if this.sociatyActivityConf, err = this.configure.getSociatyActivityCfg(); err != nil { return err } if this.sociatyTaskConf, err = this.configure.getSociatyTaskCfg(); err != nil { return err } if this.rtaskCondConf, err = this.configure.getRtaskCondiCfg(); err != nil { return err } if this.sociatySignConf, err = this.configure.getSociatySignCfg(); err != nil { return err } return } // 会长弹劾处理 // Deprecated func (this *Sociaty) ProcessAccuse(uid, sociatyId string) { t := this.globalConf.GuildImpeachmentCountDown if t == 0 { return } sociaty := this.modelSociaty.getSociaty(sociatyId) if sociaty != nil { if sociaty.AccuseTime > 0 { now := configure.Now().Unix() if now-sociaty.AccuseTime >= int64(3600*t) { //TODO 选新会长 } else { //结束弹劾 update := map[string]interface{}{ "accuseTime": 0, } if err := this.modelSociaty.updateSociaty(sociatyId, update); err != nil { this.Errorf("弹劾时间更新失败 %v", err) } } } } } // 获取我的公会成员 func (this *Sociaty) MembersByUid(uid string) (list []*pb.SociatyMemberInfo) { sociaty := this.modelSociaty.getUserSociaty(uid) return this.modelSociaty.members(sociaty) } // 获取公会成员 func (this *Sociaty) MembersBySociatyId(sociatyId string) (list []*pb.SociatyMemberInfo) { sociaty := this.modelSociaty.getSociaty(sociatyId) return this.modelSociaty.members(sociaty) } //公会 func (this *Sociaty) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) { reddot = make(map[comm.ReddotType]bool) sociaty := this.modelSociaty.getUserSociaty(session.GetUserId()) if sociaty == nil || sociaty.Id == "" { log.Warn("公会红点未获得公会信息", log.Field{Key: "uid", Value: session.GetUserId()}) for _, v := range rid { reddot[v] = false } } else { var applyReddot bool if this.modelSociaty.isRight(session.GetUserId(), sociaty, pb.SociatyJob_PRESIDENT, pb.SociatyJob_VICEPRESIDENT, pb.SociatyJob_ADMIN) { if len(sociaty.ApplyRecord) > 0 { applyReddot = true } } for _, v := range rid { switch v { case comm.Reddot3: tf := this.modelSociaty.IsSign(session.GetUserId(), sociaty) reddot[comm.Reddot3] = !tf case comm.Reddot29: reddot[comm.Reddot29] = applyReddot } } } return } // 跨服获取公会 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) reply.Id = sociaty.Id reply.Lv = sociaty.Lv reply.Exp = sociaty.Exp reply.Members = sociaty.Members reply.DismissCD = sociaty.DismissCD reply.Name = sociaty.Name reply.Icon = sociaty.Icon reply.Notice = sociaty.Notice reply.DismissTime = sociaty.DismissTime reply.IsApplyCheck = sociaty.IsApplyCheck reply.SignIds = sociaty.SignIds reply.LastSignCount = sociaty.LastSignCount reply.ApplyLv = sociaty.ApplyLv reply.Activity = sociaty.Activity reply.AccuseTime = sociaty.AccuseTime reply.ApplyRecord = sociaty.ApplyRecord return nil } type SociatyUpdateParam struct { SociatyId string Update map[string]interface{} } //跨服更新数据 func (this *Sociaty) RpcUpdateSociaty(ctx context.Context, req *SociatyUpdateParam, reply *pb.DBSociaty) error { return this.modelSociaty.ChangeList(comm.RDS_EMPTY, req.SociatyId, req.Update) } // 设置工会经验 func (this *Sociaty) BingoSetExp(session comm.IUserSession, exp int32) error { sociaty := this.modelSociaty.getUserSociaty(session.GetUserId()) if sociaty == nil || sociaty.Id == "" { log.Warn("未获得公会信息", log.Field{Key: "uid", Value: session.GetUserId()}) return comm.NewCustomError(pb.ErrorCode_SociatyNoFound) } sociaty.Exp += exp update := map[string]interface{}{ "exp": sociaty.Exp, } err := this.modelSociaty.updateSociaty(sociaty.Id, update) if err != nil { return err } return this.modelSociaty.changeLv(sociaty) } // 设置工会活跃度 func (this *Sociaty) BingoSetActivity(session comm.IUserSession, activity int32) error { sociaty := this.modelSociaty.getUserSociaty(session.GetUserId()) if sociaty == nil || sociaty.Id == "" { log.Warn("未获得公会信息", log.Field{Key: "uid", Value: session.GetUserId()}) return comm.NewCustomError(pb.ErrorCode_SociatyNoFound) } activity += sociaty.Activity update := map[string]interface{}{ "activity": activity, } return this.modelSociaty.updateSociaty(sociaty.Id, update) } type TaskParams struct { SociatyId string Uid string Data interface{} } // 任务条件达成通知 func (this *Sociaty) TaskcondNotify(uid, sociatyId string, condId int32) error { log.Debug("公会任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "sociatyId", Value: sociatyId}, log.Field{Key: "condId", Value: condId}) dt := this.modelSociatyTask.getUserTask(uid, sociatyId) var flag bool for _, v := range dt.TaskList { if v.TaskId == condId { v.Status = 1 flag = true break } } if !flag { return nil } update := map[string]interface{}{ "taskList": dt.TaskList, "lastUpdateTime": configure.Now().Unix(), } err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(), comm.Service_Worker, string(comm.Rpc_ModuleSociatyTask), &TaskParams{SociatyId: sociatyId, Uid: uid, Data: update}, &pb.EmptyResp{}) if err != nil { return err } return nil } func (this *Sociaty) RpcUpdateUserTask(ctx context.Context, p *TaskParams, reply *pb.EmptyResp) error { conn, err := db.Local() if err != nil { return err } model := db.NewDBModel(comm.TableSociatyTask, 0, conn) if err := model.Redis.HMSet(fmt.Sprintf("%s:%s-%s", this.modelSociatyTask.TableName, p.SociatyId, p.Uid), p.Data); err != nil { log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err.Error()}) return err } if err := model.UpdateModelLogs(this.modelSociatyTask.TableName, p.Uid, bson.M{"sociatyid": p.SociatyId, "uid": p.Uid}, p.Data); err != nil { return err } // task := &pb.DBSociatyTask{} // if err := model.GetListObj(p.Param1, p.Param2, task); err != nil { // return err // } // reply.TaskList = task.TaskList // reply.Uid = task.Uid // reply.ActivityList = task.ActivityList // reply.SociatyId = task.SociatyId // reply.LastUpdateTime = task.LastUpdateTime return nil }