74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 设置职位
|
|
func (this *apiComp) SettingJobCheck(session comm.IUserSession, req *pb.SociatySettingJobReq) (errdata *pb.ErrorData) {
|
|
if req.TargetId == "" || req.Job == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
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) (errdata *pb.ErrorData) {
|
|
if code = this.SettingJobCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
data = &pb.ErrorData{}
|
|
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
|
|
}
|