优化:移动端代理人员申请时省公司发起人、省公司外勤、省公司内勤不在需要选择地区

添加:代理人员申请及审核通过时判断上级的招募名额是否已经达到上限
This commit is contained in:
wuhui_zzw 2024-02-21 18:02:10 +08:00
parent e17d1f699b
commit e17919c9f6
2 changed files with 144 additions and 7 deletions

View File

@ -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{
}

View File

@ -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");
}