go_dreamfactory/modules/sociaty/api_cross_setting.go
2023-06-06 09:56:12 +08:00

70 lines
1.9 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
)
// 公会设置
func (this *apiComp) SettingCheck(session comm.IUserSession, req *pb.SociatySettingReq) (errdata *pb.ErrorData) {
if len(req.Notice) > 150 || req.ApplyLv == 0 || req.Icon == "" {
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) Setting(session comm.IUserSession, req *pb.SociatySettingReq) (errdata *pb.ErrorData) {
if code = this.SettingCheck(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, pb.SociatyJob_VICEPRESIDENT) {
code = pb.ErrorCode_SociatyNoRight
return
}
sociaty.Icon = req.Icon
sociaty.Notice = req.Notice
sociaty.IsApplyCheck = req.IsApplyCheck
sociaty.ApplyLv = req.ApplyLv
// 更新设置
if err := this.module.modelSociaty.setting(sociaty); err != nil {
code = pb.ErrorCode_SociatySetting
data.Title = code.ToString()
data.Message = err.Error()
this.module.Error("公会修改",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "sociatyId", Value: sociaty.Id},
log.Field{Key: "params", Value: req},
log.Field{Key: "err", Value: err.Error()},
)
return
}
rsp := &pb.SociatySettingResp{
SociatyId: sociaty.Id,
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeSetting, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}