package sociaty import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" ) // 设置职位 func (this *apiComp) SettingJobCheck(session comm.IUserSession, req *pb.SociatySettingJobReq) (code pb.ErrorCode) { if req.TargetId == "" || req.Job == 0 { code = pb.ErrorCode_ReqParameterError this.module.Error("公会设置职位参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()}) } return } func (this *apiComp) SettingJob(session comm.IUserSession, req *pb.SociatySettingJobReq) (code pb.ErrorCode, data *pb.ErrorData) { if code = this.SettingJobCheck(session, req); code != pb.ErrorCode_Success { return } uid := session.GetUserId() sociaty := this.module.modelSociaty.getUserSociaty(uid) if sociaty == nil { code = pb.ErrorCode_SociatyNoFound this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid}) return } // 权限校验 if !this.module.modelSociaty.isRight(uid, sociaty, pb.SociatyJob_PRESIDENT) { code = pb.ErrorCode_SociatyNoRight return } // 不能设置自己 if uid == req.TargetId { code = pb.ErrorCode_SociatySelfSetting return } // 判断职位人数 globalConf := this.module.globalConf jobCount := this.module.modelSociaty.getJobCount(req.Job, sociaty) if req.Job == pb.SociatyJob_VICEPRESIDENT && jobCount >= int(globalConf.GuildViceAllianceLeaderMaxNum) || req.Job == pb.SociatyJob_ADMIN && jobCount >= int(globalConf.GuildAdministratorsMaxNum) { code = pb.ErrorCode_SociatyMemberCountLimit return } // 设置职位 if err := this.module.modelSociaty.settingJob(req.TargetId, req.Job, sociaty); err != nil { code = pb.ErrorCode_SociatySettingJob this.module.Errorf("设置公会职位", log.Fields{"uid": uid, "sociatyId": sociaty.Id, "params": req, "err": err.Error()}) return } rsp := &pb.SociatySettingJobResp{ TargetId: req.TargetId, SociatyId: sociaty.Id, Job: req.Job, } if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeSettingJob, rsp); err != nil { code = pb.ErrorCode_SystemError } return }