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 errdata = this.AgreeCheck(session, req); errdata != nil { return } uid := session.GetUserId() sociaty := this.module.modelSociaty.getUserSociaty(uid) if sociaty == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_SociatyNoFound, Title: pb.ErrorCode_SociatyNoFound.ToString(), } return } // 校验权限 if !this.module.modelSociaty.isRight(uid, sociaty, pb.SociatyJob_PRESIDENT, pb.SociatyJob_VICEPRESIDENT, pb.SociatyJob_ADMIN) { errdata = &pb.ErrorData{ Code: pb.ErrorCode_SociatyNoRight, Title: pb.ErrorCode_SociatyNoRight.ToString(), } 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 errdata = &pb.ErrorData{ Code: code, Title: code.ToString(), Message: err.Error(), } } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), 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, } session.SendMsg(string(this.module.GetType()), SociatySubTypeAgree, rsp) //审核通过推送给申请人 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 }