go_dreamfactory/modules/sociaty/api_cross_agree.go
2023-06-06 09:56:12 +08:00

101 lines
2.9 KiB
Go

package sociaty
import (
"errors"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
)
// 公会申请-同意
func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.SociatyAgreeReq) (errdata *pb.ErrorData) {
if req.Uid == "" {
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) Agree(session comm.IUserSession, req *pb.SociatyAgreeReq) (errdata *pb.ErrorData) {
if code = this.AgreeCheck(session, req); code != pb.ErrorCode_Success {
return
}
data = &pb.ErrorData{}
uid := session.GetUserId()
sociaty := this.module.modelSociaty.getUserSociaty(uid)
if sociaty == nil {
code = pb.ErrorCode_SociatyNoFound
data.Title = code.ToString()
data.Datastring = uid
data.Message = SociatyNoFound
return
}
// 校验权限
if !this.module.modelSociaty.isRight(uid, sociaty,
pb.SociatyJob_PRESIDENT,
pb.SociatyJob_VICEPRESIDENT,
pb.SociatyJob_ADMIN) {
code = pb.ErrorCode_SociatyNoRight
data.Title = code.ToString()
data.Message = 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
}
data.Title = code.ToString()
data.Message = err.Error()
this.module.Error("公会审核-同意",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "申请人", Value: req.Uid},
log.Field{Key: "sociatyId", Value: sociaty.Id},
)
return
}
// 触发任务条件
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype109, 1)
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype109, 1))
// 发邮件
if err := this.module.modelSociaty.sendMail("GuildApproved", []string{sociaty.Name}, []string{req.Uid}); err != nil {
this.module.Error("发送邮件 模板ID:GuildApproved",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "申请人", Value: req.Uid},
log.Field{Key: "sociatyId", Value: 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.Field{Key: "uid", Value: uid},
log.Field{Key: "申请人", Value: req.Uid},
log.Field{Key: "sociatyId", Value: sociaty.Id},
)
}
return
}