From e17919c9f62314e8e379f4b554d686e4eeedb68f Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Wed, 21 Feb 2024 18:02:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E4=BB=A3=E7=90=86=E4=BA=BA=E5=91=98=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E6=97=B6=E7=9C=81=E5=85=AC=E5=8F=B8=E5=8F=91=E8=B5=B7=E4=BA=BA?= =?UTF-8?q?=E3=80=81=E7=9C=81=E5=85=AC=E5=8F=B8=E5=A4=96=E5=8B=A4=E3=80=81?= =?UTF-8?q?=E7=9C=81=E5=85=AC=E5=8F=B8=E5=86=85=E5=8B=A4=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E9=80=89=E6=8B=A9=E5=9C=B0=E5=8C=BA=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E4=BB=A3=E7=90=86=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=8F=8A=E5=AE=A1=E6=A0=B8=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=97=B6=E5=88=A4=E6=96=AD=E4=B8=8A=E7=BA=A7=E7=9A=84=E6=8B=9B?= =?UTF-8?q?=E5=8B=9F=E5=90=8D=E9=A2=9D=E6=98=AF=E5=90=A6=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E8=BE=BE=E5=88=B0=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marketing/AgentApplyRepository.php | 77 ++++++++++++++++++- app/controller/api/Agent.php | 74 +++++++++++++++++- 2 files changed, 144 insertions(+), 7 deletions(-) diff --git a/app/common/repositories/marketing/AgentApplyRepository.php b/app/common/repositories/marketing/AgentApplyRepository.php index a9f1bc0..92a1385 100644 --- a/app/common/repositories/marketing/AgentApplyRepository.php +++ b/app/common/repositories/marketing/AgentApplyRepository.php @@ -12,6 +12,7 @@ use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\service\StoreServiceRepository; use app\common\repositories\system\merchant\MerchantRepository; use crmeb\services\LockService; +use think\exception\ValidateException; use think\facade\Db; class AgentApplyRepository extends BaseRepository{ @@ -144,11 +145,81 @@ class AgentApplyRepository extends BaseRepository{ * @return mixed */ public function toExaminePass($params){ - return Db::transaction(function() use ($params){ + // 判断:上级邀请人员是否已经达到限制 类型:1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤 + $config = app()->make(AgentRepository::class)->getConfig(); + $inviteLimit = $config['invite_limit'] ?? []; + $applyInfo = $this->getSearchModel(['id'=>$params['id']])->findOrEmpty()->toArray(); + switch($applyInfo['agent_type']){ + case 2: + // 判断:当前上级招募 [省公司发起人] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>2])->count(); + if(($inviteLimit['invite_9_2'] ?? 0) < $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_9_2'] ?? 0).' 人'); + } + break; + case 3: + // 判断:当前上级招募 [省公司外勤] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>3])->count(); + if(($inviteLimit['invite_2_3'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_2_3'] ?? 0).' 人'); + } + break; + case 4: + // 判断:当前上级招募 [省公司内勤] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>4])->count(); + if(($inviteLimit['invite_2_4'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_2_4'] ?? 0).' 人'); + } + break; + case 5: + // 判断:当前上级招募 [区县运营商] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>5])->count(); + if(($inviteLimit['invite_3_5'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_3_5'] ?? 0).' 人'); + } + break; + case 6: + // 判断:当前上级招募 [区县合伙人] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>6])->count(); + if(($inviteLimit['invite_5_6'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_5_6'] ?? 0).' 人'); + } + break; + case 7: + // 判断:当前上级招募 [餐厅] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>7])->count(); + if(($inviteLimit['invite_6_7'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_6_7'] ?? 0).' 家餐厅'); + } + break; + case 8: + // 判断:当前上级招募 [配送商] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>8])->count(); + if(($inviteLimit['invite_6_8'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_6_8'] ?? 0).' 家配送商'); + } + break; + case 9: + // 判断:当前上级招募 [总部外勤] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>9])->count(); + if(($inviteLimit['invite_1_9'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_1_9'] ?? 0).' 人'); + } + break; + case 10: + // 判断:当前上级招募 [总部内勤] 数量是否超出限制 + $hasCount = app()->make(AgentRepository::class)->getSearchModel(['pid'=>$applyInfo['pid'],'agent_type'=>10])->count(); + if(($inviteLimit['invite_1_10'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_1_10'] ?? 0).' 人'); + } + break; + } + // 通过处理 + return Db::transaction(function() use ($params, $applyInfo){ // 修改状态 $this->dao->update($params['id'],['status'=>$params['status']]); // 生成代理信息 - $applyInfo = $this->getSearchModel(['id'=>$params['id']])->findOrEmpty()->toArray(); + // $applyInfo = $this->getSearchModel(['id'=>$params['id']])->findOrEmpty()->toArray(); $keys = array_flip((array)[ "uid", "pid", @@ -213,6 +284,4 @@ class AgentApplyRepository extends BaseRepository{ - - } diff --git a/app/controller/api/Agent.php b/app/controller/api/Agent.php index 8e2536b..6cbd779 100644 --- a/app/controller/api/Agent.php +++ b/app/controller/api/Agent.php @@ -122,7 +122,7 @@ class Agent extends BaseController{ if(!in_array((int)$data['agent_type'], [2,3,4,5,6,7,8,9,10])) throw new ValidateException('非法请求,代理类型错误!'); if(empty($data['contact_name'])) throw new ValidateException('请输入联系人姓名!'); if(empty($data['contact_phone'])) throw new ValidateException('请输入联系人电话!'); - if(!in_array((int)$data['agent_type'], [9,10]) && (int)$data['province_id'] <= 0) throw new ValidateException('请选择地区!'); + if(!in_array((int)$data['agent_type'], [2,3,4,9,10]) && (int)$data['province_id'] <= 0) throw new ValidateException('请选择地区!'); if(in_array((int)$data['agent_type'], [5,6,7])){ if((int)$data['city_id'] <= 0) throw new ValidateException('请选择地区!'); if((int)$data['area_id'] <= 0) throw new ValidateException('请选择地区!'); @@ -147,6 +147,74 @@ class Agent extends BaseController{ ->count(); if($isHas > 0) throw new ValidateException('商户已经存在,请勿重复申请!'); } + // 判断:上级邀请人员是否已经达到限制 类型:1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤 + $config = $this->repository->getConfig(); + $inviteLimit = $config['invite_limit'] ?? []; + switch($data['agent_type']){ + case 2: + // 判断:当前上级招募 [省公司发起人] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>2])->count(); + if(($inviteLimit['invite_9_2'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_9_2'] ?? 0).' 人'); + } + break; + case 3: + // 判断:当前上级招募 [省公司外勤] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>3])->count(); + if(($inviteLimit['invite_2_3'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_2_3'] ?? 0).' 人'); + } + break; + case 4: + // 判断:当前上级招募 [省公司内勤] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>4])->count(); + if(($inviteLimit['invite_2_4'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_2_4'] ?? 0).' 人'); + } + break; + case 5: + // 判断:当前上级招募 [区县运营商] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>5])->count(); + if(($inviteLimit['invite_3_5'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_3_5'] ?? 0).' 人'); + } + break; + case 6: + // 判断:当前上级招募 [区县合伙人] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>6])->count(); + if(($inviteLimit['invite_5_6'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_5_6'] ?? 0).' 人'); + } + break; + case 7: + // 判断:当前上级招募 [餐厅] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>7])->count(); + if(($inviteLimit['invite_6_7'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_6_7'] ?? 0).' 家餐厅'); + } + break; + case 8: + // 判断:当前上级招募 [配送商] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>8])->count(); + if(($inviteLimit['invite_6_8'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_6_8'] ?? 0).' 家配送商'); + } + break; + case 9: + // 判断:当前上级招募 [总部外勤] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>9])->count(); + if(($inviteLimit['invite_1_9'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_1_9'] ?? 0).' 人'); + } + break; + case 10: + // 判断:当前上级招募 [总部内勤] 数量是否超出限制 + $hasCount = $this->repository->getSearchModel(['pid'=>$data['pid'],'agent_type'=>10])->count(); + if(($inviteLimit['invite_1_10'] ?? 0) <= $hasCount) { + throw new ValidateException('邀请人招募数量超出限制!仅允许招募 '.($inviteLimit['invite_1_10'] ?? 0).' 人'); + } + break; + } // 信息是否重复 $isHas = (int)app()->make(AgentApplyRepository::class) ->getSearchModel(['contact_phone'=>$data['contact_phone']]) @@ -165,11 +233,11 @@ class Agent extends BaseController{ if($isHas > 0) throw new ValidateException('代理身份信息已经存在!'); $isHas = (int)app()->make(AgentApplyRepository::class) ->getSearchModel(['agent_type'=>$data['agent_type'],'uid'=>$data['uid']]) + ->where('status','<>', 1) ->when($agentApplyId > 0,function($query) use ($agentApplyId){ $query->where('id','<>',$agentApplyId); })->count(); - if($isHas > 0) throw new ValidateException('代理身份信息已经存在,请勿重复申请!'); - + if($isHas > 0) throw new ValidateException('已存在有效申请记录,请勿重复申请!'); return compact("agentApplyId", "data"); }