go_dreamfactory/modules/sociaty/api_cross_settingjob.go
2022-11-14 15:55:50 +08:00

71 lines
1.8 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 设置职位
func (this *apiComp) SettingJobCheck(session comm.IUserSession, req *pb.SociatySettingJobReq) (code pb.ErrorCode) {
if req.TargetId == "" || req.Job == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) SettingJob(session comm.IUserSession, req *pb.SociatySettingJobReq) (code pb.ErrorCode, data proto.Message) {
if code = this.SettingJobCheck(session, req); code != pb.ErrorCode_Success {
return
}
uid := session.GetUserId()
sociaty := this.module.modelSociaty.getUserSociaty(uid)
if sociaty.Id == "" {
code = pb.ErrorCode_SociatyNoFound
this.module.Errorf("uid:%s not in sociaty", uid)
return
}
// 权限校验
if !this.module.modelSociaty.isRight(uid, sociaty,
pb.SociatyJob_PRESIDENT) {
code = pb.ErrorCode_SociatyNoRight
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 uid == req.TargetId {
code = pb.ErrorCode_SociatySelfSetting
return
}
// 设置职位
if err := this.module.modelSociaty.settingJob(req.TargetId, req.Job, sociaty); err != nil {
code = pb.ErrorCode_SociatySettingJob
this.module.Errorf("设置职位失败:%v", err)
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
}