go_dreamfactory/modules/sociaty/api_cross_agree.go

80 lines
2.3 KiB
Go

package sociaty
import (
"errors"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 公会申请-同意
func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.SociatyAgreeReq) (code pb.ErrorCode) {
if req.Uid == "" {
code = pb.ErrorCode_ReqParameterError
this.module.Error("公会申请-同意参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
}
return
}
func (this *apiComp) Agree(session comm.IUserSession, req *pb.SociatyAgreeReq) (code pb.ErrorCode, data proto.Message) {
if code = this.AgreeCheck(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,
pb.SociatyJob_ADMIN) {
code = pb.ErrorCode_SociatyNoRight
return
}
if err := this.module.modelSociaty.agree(req.Uid, 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, "申请人": req.Uid, "sociatyId": sociaty.Id})
return
}
// 触发任务条件
this.module.ModuleRtask.SendToRtask(session, comm.Rtype109, 1)
// 发邮件
if err := this.module.modelSociaty.sendMail("GuildApproved", []string{sociaty.Name}, []string{req.Uid}); err != nil {
this.module.Error("发送邮件 模板ID:GuildApproved", log.Fields{"uid": uid, "申请人": req.Uid, "sociatyId": sociaty.Id})
}
rsp := &pb.SociatyAgreeResp{
Uid: req.Uid,
SociatyId: sociaty.Id,
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeAgree, rsp); err != nil {
code = pb.ErrorCode_SystemError
return
}
//审核通过推送给申请人
if err := this.module.SendMsgToUser(string(this.module.GetType()), "pagree", &pb.SociatyPAgreePush{
Uid: uid,
SociatyId: sociaty.Id,
}, req.Uid); err != nil {
this.module.Error("审核通过推送", log.Fields{"uid": uid, "申请人": req.Uid, "sociatyId": sociaty.Id})
}
return
}