go_dreamfactory/modules/sociaty/api_cross_agree.go
2022-11-08 14:49:00 +08:00

66 lines
1.7 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"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
}
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.Id == "" {
code = pb.ErrorCode_SociatyNoFound
this.module.Errorf("uid:%s not in sociaty", 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 {
code = pb.ErrorCode_SociatyAgree
this.module.Errorf("申请同意失败:%v", err)
return
}
// 发邮件
if err := this.module.modelSociaty.sendMail("GuildApproved", []string{sociaty.Name}, []string{req.Uid}); err != nil {
this.module.Errorf("发送邮件id:GuildApproved uid:%v 失败 err:%v", uid, err)
}
//审核通过推送
this.module.SendMsgToUser(string(this.module.GetType()), "pagree", &pb.SociatyPAgreePush{
Uid: uid,
SociatyId: sociaty.Id,
}, req.Uid)
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
}