go_dreamfactory/modules/sociaty/api_cross_quit.go
2023-06-06 14:36:57 +08:00

83 lines
2.2 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
)
// 退出公会
func (this *apiComp) QuitCheck(session comm.IUserSession, req *pb.SociatyQuitReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) Quit(session comm.IUserSession, req *pb.SociatyQuitReq) (errdata *pb.ErrorData) {
uid := session.GetUserId()
sociaty := this.module.modelSociaty.getUserSociaty(uid)
if sociaty == nil {
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
return
}
// 会长不允许退公会
if this.module.modelSociaty.isRight(uid, sociaty,
pb.SociatyJob_PRESIDENT) {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_SociatyQuitNoAllowed,
Title: pb.ErrorCode_SociatyQuitNoAllowed.ToString(),
}
return
}
// 退出公会
if err := this.module.modelSociaty.quit(uid, sociaty); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_SociatyQuit,
Title: pb.ErrorCode_SociatyQuit.ToString(),
}
this.module.Errorf("退出公会", log.Fields{"uid": uid, "sociatyId": sociaty.Id, "err": err.Error()})
return
}
//更新玩家sociatyId
update := map[string]interface{}{
"sociatyId": "", //玩家公会ID置空
"sociatyCd": utils.AddHour(int(this.module.globalConf.GuildRejoinCd)).Unix(),
}
if err := this.module.ModuleUser.ChangeUserExpand(uid, 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: "sociatyId", Value: sociaty.Id},
log.Field{Key: "err", Value: err.Error()},
)
return
}
// 添加退出公会日志
if err := this.module.modelSociatyLog.addLog(Log_Quit, sociaty.Id, uid); err != nil {
this.module.Error("踢出公会日志",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "sociatyId", Value: sociaty.Id},
log.Field{Key: "日志模板", Value: Log_Quit},
log.Field{Key: "err", Value: err.Error()},
)
}
rsp := &pb.SociatyQuitResp{
Uid: uid,
SociatyId: sociaty.Id,
}
session.SendMsg(string(this.module.GetType()), SociatySubTypeQuit, rsp)
return
}