package sociaty import ( "errors" "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/utils" ) // 公会申请-同意 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) { var ( uids []string tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0) ) if errdata = this.AgreeCheck(session, req); errdata != nil { return } // userex userEx, err := this.module.ModuleUser.GetUserExpand(req.Uid) if err != nil { this.module.Error("GetRemoteUserExpand", log.Field{Key: "uid", Value: req.Uid}, log.Field{Key: "err", Value: err.Error()}) errdata = &pb.ErrorData{ Code: pb.ErrorCode_UserNofound, Title: pb.ErrorCode_UserNofound.ToString(), } return } if utils.IsInCDHour(userEx.SociatyCd) { errdata = &pb.ErrorData{ Code: pb.ErrorCode_SociatyCDLimit, Title: pb.ErrorCode_SociatyCDLimit.ToString(), Message: fmt.Sprintf("CD内[%v]不允许申请", userEx.SociatyCd), } 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 } for _, v := range sociaty.Members { uids = append(uids, v.Uid) } // 校验权限 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 } // 触发任务条件 tasks = append(tasks, 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) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { //审核通过推送给申请人 if err := this.module.SendMsgToUser(string(this.module.GetType()), "pagree", &pb.SociatyPAgreePush{ Uid: req.Uid, SociatyId: sociaty.Id, }, req.Uid); err != nil { this.module.Errorln(err) } this.module.ModuleBuried.TriggerBuried(session, tasks...) this.module.maincity.AddMainCityFriends(req.Uid, uids) }) return }