go_dreamfactory/modules/sociaty/api_cross_refuse.go
2022-12-19 16:25:22 +08:00

68 lines
1.8 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 公会申请审核-拒绝
func (this *apiComp) RefuseCheck(session comm.IUserSession, req *pb.SociatyRefuseReq) (code pb.ErrorCode) {
if req.Uid == "" {
code = pb.ErrorCode_ReqParameterError
this.module.Error("公会申请审核-拒绝参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
}
return
}
func (this *apiComp) Refuse(session comm.IUserSession, req *pb.SociatyRefuseReq) (code pb.ErrorCode, data proto.Message) {
if code = this.RefuseCheck(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.Field{Key: "uid", Value: uid})
return
}
// 校验权限
if !this.module.modelSociaty.isRight(uid, sociaty,
pb.SociatyJob_PRESIDENT,
pb.SociatyJob_VICEPRESIDENT,
pb.SociatyJob_ADMIN) {
code = pb.ErrorCode_SociatyNoRight
return
}
// 已是公会成员
if this.module.modelSociaty.isMember(uid, sociaty) {
code = pb.ErrorCode_SociatyAdded
return
}
// 拒绝公会申请
if err := this.module.modelSociaty.refuse(req.Uid, sociaty); err != nil {
code = pb.ErrorCode_SociatyRefuse
this.module.Error("申请拒绝",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "拒绝目标人", Value: req.Uid},
log.Field{Key: "err", Value: err.Error()},
)
return
}
rsp := &pb.SociatyRefuseResp{
Uid: req.Uid,
SociatyId: sociaty.Id,
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeRefuse, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}