127 lines
3.6 KiB
Go
127 lines
3.6 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 踢出公会
|
|
|
|
func (this *apiComp) DischargeCheck(session comm.IUserSession, req *pb.SociatyDischargeReq) (errdata *pb.ErrorData) {
|
|
if req.TargetId == "" {
|
|
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) Discharge(session comm.IUserSession, req *pb.SociatyDischargeReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.DischargeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
sociaty := this.module.modelSociaty.getUserSociaty(uid)
|
|
if sociaty == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyNoFound,
|
|
Title: pb.ErrorCode_SociatyNoFound.ToString(),
|
|
}
|
|
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
|
|
return
|
|
}
|
|
|
|
// 校验权限
|
|
if !this.module.modelSociaty.isRight(uid, sociaty,
|
|
pb.SociatyJob_PRESIDENT,
|
|
pb.SociatyJob_VICEPRESIDENT) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyNoRight,
|
|
Title: pb.ErrorCode_SociatyNoRight.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 踢人
|
|
if err := this.module.modelSociaty.discharge(req.TargetId, sociaty); err != nil {
|
|
var customError = new(comm.CustomError)
|
|
|
|
if errors.As(err, &customError) {
|
|
code := customError.Code
|
|
errdata = &pb.ErrorData{
|
|
Code: code,
|
|
Title: code.ToString(),
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
|
|
this.module.Error("踢出公会",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "sociatyId", Value: sociaty.Id},
|
|
log.Field{Key: "被踢人", Value: req.TargetId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
// 发邮件
|
|
receiver := this.module.modelSociaty.getMemberIds(sociaty)
|
|
if err := this.module.modelSociaty.sendMail("GuildExpel", []string{sociaty.Name}, receiver); err != nil {
|
|
this.module.Error("发送邮件 模板ID:GuildExpel",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "被踢人", Value: req.TargetId},
|
|
log.Field{Key: "sociatyId", Value: sociaty.Id},
|
|
)
|
|
}
|
|
|
|
//清除玩家sociatyId
|
|
update := map[string]interface{}{
|
|
"sociatyId": "", //公会ID置空
|
|
}
|
|
|
|
if err := this.module.ModuleUser.ChangeUserExpand(req.TargetId, update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Error("更新玩家公会ID",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "被踢人", Value: req.TargetId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
// 添加日志
|
|
if err := this.module.modelSociatyLog.addLog(Log_Discharge, sociaty.Id, uid, req.TargetId); err != nil {
|
|
this.module.Error("踢出公会日志",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "sociatyId", Value: sociaty.Id},
|
|
log.Field{Key: "targetId", Value: req.TargetId},
|
|
log.Field{Key: "日志模板", Value: Log_Discharge},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
}
|
|
|
|
rsp := &pb.SociatyDischargeResp{
|
|
TargetId: req.TargetId,
|
|
SociatyId: sociaty.Id,
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), SociatySubTypeDischarge, rsp)
|
|
|
|
this.module.SendMsgToUser(string(this.module.GetType()), "pdischange", &pb.SociatyPDischangePush{Uid: req.TargetId, SociatyId: sociaty.Id}, req.TargetId)
|
|
return
|
|
}
|