package sociaty import ( "errors" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "google.golang.org/protobuf/proto" ) // 踢出公会 func (this *apiComp) DischargeCheck(session comm.IUserSession, req *pb.SociatyDischargeReq) (code pb.ErrorCode) { if req.TargetId == "" { code = pb.ErrorCode_ReqParameterError this.module.Error("踢出公会参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) } return } func (this *apiComp) Discharge(session comm.IUserSession, req *pb.SociatyDischargeReq) (code pb.ErrorCode, data proto.Message) { if code = this.DischargeCheck(session, req); code != pb.ErrorCode_Success { return } uid := session.GetUserId() sociaty := this.module.modelSociaty.getUserSociaty(uid) if sociaty != nil && sociaty.Id == "" { code = pb.ErrorCode_SociatyNoFound this.module.Error("当前玩家所在的公会未找到", log.Fields{"uid": uid}) return } // 校验权限 if !this.module.modelSociaty.isRight(uid, sociaty, pb.SociatyJob_PRESIDENT, pb.SociatyJob_VICEPRESIDENT) { code = pb.ErrorCode_SociatyNoRight 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 } else { code = pb.ErrorCode_DBError } this.module.Error("踢出公会", log.Fields{"uid": uid, "sociatyId": sociaty.Id, "被踢人": req.TargetId, "err": 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.Fields{"uid": uid, "被踢人": req.TargetId, "sociatyId": sociaty.Id}) } //清除玩家sociatyId update := map[string]interface{}{ "sociatyId": "", //公会ID置空 } if err := this.module.ModuleUser.ChangeUserExpand(req.TargetId, update); err != nil { code = pb.ErrorCode_DBError this.module.Error("更新玩家公会ID", log.Fields{"uid": uid, "被踢人": req.TargetId, "err": err.Error()}) return } // 添加日志 if err := this.module.modelSociatyLog.addLog(Log_Discharge, sociaty.Id, uid, req.TargetId); err != nil { this.module.Error("踢出公会日志", log.Fields{"uid": uid, "sociatyId": sociaty.Id, "targetId": req.TargetId, "日志模板": Log_Discharge, "err": err.Error()}) } rsp := &pb.SociatyDischargeResp{ TargetId: req.TargetId, SociatyId: sociaty.Id, } if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeDischarge, rsp); err != nil { code = pb.ErrorCode_SystemError } return }