添加:部分代理角色招募下级数量限制

修复:配送商关联商户错误,配送商城删除后已关联的商户未解除绑定,导致不能重新绑定配送商
修改:省公司发起人、省公司外勤、省公司内勤取消省地区选择
修复:配送商不能添加或者不能删除的问题
This commit is contained in:
wuhui_zzw 2024-02-21 16:44:22 +08:00
parent 34e9c8f788
commit e17d1f699b
4 changed files with 130 additions and 49 deletions

View File

@ -8,6 +8,7 @@ namespace app\common\model\system\merchant;
use app\common\dao\store\product\ProductDao; use app\common\dao\store\product\ProductDao;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\marketing\Agent;
use app\common\model\store\coupon\StoreCouponProduct; use app\common\model\store\coupon\StoreCouponProduct;
use app\common\model\store\coupon\StoreCouponUser; use app\common\model\store\coupon\StoreCouponUser;
use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrder;
@ -281,6 +282,10 @@ class Merchant extends BaseModel
public function merShop(){ public function merShop(){
return $this->hasOne(self::class,'mer_id', 'shop_mer_id'); return $this->hasOne(self::class,'mer_id', 'shop_mer_id');
} }
// 代理信息
public function agent(){
return $this->hasOne(Agent::class,'id', 'agent_id')->where('is_del', 0);
}
public function brand(){ public function brand(){
return $this->hasOne(MerchantBrand::class,'id', 'brand_id'); return $this->hasOne(MerchantBrand::class,'id', 'brand_id');

View File

@ -173,8 +173,7 @@ class AgentRepository extends BaseRepository{
"address", "address",
"lat", "lat",
"lng", "lng",
"mer_id", "mer_id"
'is_headquarters'
]); ]);
$updateInfo = array_intersect_key($data, $keys); $updateInfo = array_intersect_key($data, $keys);
Agent::update($updateInfo,['id'=>$agentId]); Agent::update($updateInfo,['id'=>$agentId]);
@ -214,9 +213,9 @@ class AgentRepository extends BaseRepository{
"address", "address",
"lat", "lat",
"lng", "lng",
"mer_id", "mer_id"
'is_headquarters'
]); ]);
$eightUpdateIds = [];
// 循环:区分对应的操作 // 循环:区分对应的操作
foreach($childrenList as $childrenItem){ foreach($childrenList as $childrenItem){
unset($childrenItem['user']); unset($childrenItem['user']);
@ -235,6 +234,8 @@ class AgentRepository extends BaseRepository{
'agent_id' => $childrenItemId 'agent_id' => $childrenItemId
]; ];
} }
// 记录配送商ID
$eightUpdateIds[] = (int)$childrenItemId;
}else{ }else{
// 判断:应该修改还是编辑 // 判断:应该修改还是编辑
if((int)$childrenItemId > 0) $updateData[] = $handleData; if((int)$childrenItemId > 0) $updateData[] = $handleData;
@ -244,7 +245,7 @@ class AgentRepository extends BaseRepository{
// 获取需要删除的数据的id 删除思路:先获取总数据、对修改数据比较、删除缺少的项 // 获取需要删除的数据的id 删除思路:先获取总数据、对修改数据比较、删除缺少的项
$allIds = $this->dao->searchList([])->where('pid',$agentId)->column('id'); $allIds = $this->dao->searchList([])->where('pid',$agentId)->column('id');
$updateIds = array_column($updateData,'id'); $updateIds = array_column($updateData,'id');
$delIds = array_diff($allIds,$updateIds); $delIds = array_diff($allIds, array_merge($eightUpdateIds,$updateIds));
// 处理结果 进行对应的操作;必须按照先删除、在修改、最后添加的顺序进行 // 处理结果 进行对应的操作;必须按照先删除、在修改、最后添加的顺序进行
if(count($delIds) > 0) Agent::whereIn('id',$delIds)->update(['is_del'=>1]); if(count($delIds) > 0) Agent::whereIn('id',$delIds)->update(['is_del'=>1]);
@ -359,6 +360,8 @@ class AgentRepository extends BaseRepository{
'external_personnel_process', 'external_personnel_process',
'external_personnel_money_platform', 'external_personnel_money_platform',
'external_personnel_money_initiator', 'external_personnel_money_initiator',
// 邀请限制
'invite_limit'
]); ]);
$config['delivery_process'] = (int)$config['delivery_process']; $config['delivery_process'] = (int)$config['delivery_process'];
$config['field_staff_process'] = (int)$config['field_staff_process']; $config['field_staff_process'] = (int)$config['field_staff_process'];
@ -369,6 +372,7 @@ class AgentRepository extends BaseRepository{
$config['province_process'] = (int)$config['province_process']; $config['province_process'] = (int)$config['province_process'];
$config['field_personnel_process'] = (int)$config['field_personnel_process']; $config['field_personnel_process'] = (int)$config['field_personnel_process'];
$config['external_personnel_process'] = (int)$config['external_personnel_process']; $config['external_personnel_process'] = (int)$config['external_personnel_process'];
$config['invite_limit'] = $config['invite_limit'] ? (array)$config['invite_limit'] : [];
return $config; return $config;
} }

View File

@ -94,8 +94,11 @@ class MerchantRepository extends BaseRepository
'brand' => function ($query) { 'brand' => function ($query) {
$query->field('id,title'); $query->field('id,title');
}, },
'agent'=>function($query){
$query->field('id,contact_name,agent_type');
}
]) ])
->field('sort,mer_id,mer_name,real_name,mer_phone,mer_address,mark,status,create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,ot_margin,mer_avatar,margin_remind_time,shop_mer_id,brand_id')->select(); ->field('merchant_type,sort,mer_id,mer_name,real_name,mer_phone,mer_address,mark,status,create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,ot_margin,mer_avatar,margin_remind_time,agent_id,shop_mer_id,brand_id')->select();
return compact('count', 'list'); return compact('count', 'list');
} }

View File

@ -63,8 +63,7 @@ class Agent extends BaseController{
'lat', 'lat',
'lng', 'lng',
['mer_id', 0], ['mer_id', 0],
['mer_id_list', []], ['mer_id_list', []]
['is_headquarters', 0]
]); ]);
$agentId = (int)$this->request->param('id'); $agentId = (int)$this->request->param('id');
$childrenList = $this->request->param('children_list'); $childrenList = $this->request->param('children_list');
@ -74,40 +73,101 @@ class Agent extends BaseController{
$agentStock = (float)array_sum(array_column($childrenList,'agent_stock')); $agentStock = (float)array_sum(array_column($childrenList,'agent_stock'));
if($agentStock != 100) throw new ValidateException('所有发起人的股份总和必须等于100'); if($agentStock != 100) throw new ValidateException('所有发起人的股份总和必须等于100');
} }
// 循环判断:$childrenList 的数据是否完善 类型1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商 // 验证下级信息类型1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤
foreach($childrenList as $childrenItem){ if(count($childrenList) > 0){
if(empty($childrenItem['contact_name'])) throw new ValidateException('请输入联系人姓名!'); // 下级数据信息是否完善
if(empty($childrenItem['contact_phone'])) throw new ValidateException('请输入联系人电话!'); foreach($childrenList as $childrenItem){
if(isPhone($childrenItem['contact_phone'])) throw new ValidateException('请输入正确的联系人电话!'); if(empty($childrenItem['contact_name'])) throw new ValidateException('请输入联系人姓名!');
// 判断:根据当前角色判断 数据 if(empty($childrenItem['contact_phone'])) throw new ValidateException('请输入联系人电话!');
switch((int)$childrenItem['agent_type']){ if(isPhone($childrenItem['contact_phone'])) throw new ValidateException('请输入正确的联系人电话!');
// 判断:根据当前角色判断 数据
switch((int)$childrenItem['agent_type']){
case 1:
// if((float)$childrenItem['agent_stock'] <= 0) throw new ValidateException('发起人的股份必须大于0');
break;
case 2:
case 3:
case 4:
// if((float)$childrenItem['province_id'] <= 0) throw new ValidateException('请完善地区信息!');
break;
case 5:
case 6:
if((float)$childrenItem['province_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$childrenItem['city_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$childrenItem['area_id'] <= 0) throw new ValidateException('请完善地区信息!');
break;
case 7:
if((float)$childrenItem['province_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$childrenItem['city_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$childrenItem['area_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$childrenItem['street_id'] <= 0) throw new ValidateException('请完善地区信息!');
if(empty($childrenItem['address'])) throw new ValidateException('请完善地区信息!');
if(((float)$childrenItem['lat'] <= 0 || (float)$childrenItem['lng'] <= 0)) throw new ValidateException('请选择定位信息!');
if((float)$childrenItem['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!');
break;
case 8:
if(count($childrenItem['mer_id_list']) <= 0) throw new ValidateException('配送商至少关联一个商户!');
break;
}
}
// 判断:下级数量是否达到限制
$config = app()->make(AgentRepository::class)->getConfig();
$inviteLimit = $config['invite_limit'] ?? [];
$statisticNumber = (array)array_count_values(array_column($childrenList,'agent_type'));
switch($data['agent_type']){
case 1: case 1:
// if((float)$childrenItem['agent_stock'] <= 0) throw new ValidateException('发起人的股份必须大于0'); // 判断:[总部发起人] 邀请 [总部外勤]是否超出限制
if(($inviteLimit['invite_1_9'] ?? 0) < ($statisticNumber[9] ?? 0)) {
throw new ValidateException('【总部外勤】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_1_9'] ?? 0).' 人');
}
// 判断:[总部发起人] 邀请 [总部内勤]是否超出限制
if(($inviteLimit['invite_1_10'] ?? 0) < ($statisticNumber[10] ?? 0)) {
throw new ValidateException('【总部内勤】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_1_10'] ?? 0).' 人');
}
break; break;
case 2: case 2:
// 判断:[省公司发起人] 邀请 [省公司外勤]是否超出限制
if(($inviteLimit['invite_2_3'] ?? 0) < ($statisticNumber[3] ?? 0)) {
throw new ValidateException('【省公司外勤】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_2_3'] ?? 0).' 人');
}
// 判断:[省公司发起人] 邀请 [省公司内勤]是否超出限制
if(($inviteLimit['invite_2_4'] ?? 0) < ($statisticNumber[4] ?? 0)) {
throw new ValidateException('【省公司内勤】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_2_4'] ?? 0).' 人');
}
break;
case 3: case 3:
case 4: // 判断:[省公司外勤] 邀请 [区县运营商]是否超出限制
if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(($inviteLimit['invite_3_5'] ?? 0) < ($statisticNumber[5] ?? 0)) {
throw new ValidateException('【区县运营商】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_3_5'] ?? 0).' 人');
}
break; break;
case 4: break;
case 5: case 5:
// 判断:[区县运营商] 邀请 [区县合伙人]是否超出限制
if(($inviteLimit['invite_5_6'] ?? 0) < ($statisticNumber[6] ?? 0)) {
throw new ValidateException('【区县合伙人】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_5_6'] ?? 0).' 人');
}
break;
case 6: case 6:
if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); // 判断:[区县合伙人] 邀请 [餐厅]是否超出限制
if((float)$childrenItem['city_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(($inviteLimit['invite_6_7'] ?? 0) < ($statisticNumber[7] ?? 0)) {
if((float)$childrenItem['area_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); throw new ValidateException('【餐厅】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_6_7'] ?? 0).' 人');
}
// 判断:[区县合伙人] 邀请 [配送商]是否超出限制
if(($inviteLimit['invite_6_8'] ?? 0) < ($statisticNumber[8] ?? 0)) {
throw new ValidateException('【配送商】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_6_8'] ?? 0).' 人');
}
break; break;
case 7: // case 7: break;
if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); // case 8: break;
if((float)$childrenItem['city_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); case 9:
if((float)$childrenItem['area_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); // 判断:[总部外勤] 邀请 [省公司发起人]是否超出限制
if((float)$childrenItem['street_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(($inviteLimit['invite_9_2'] ?? 0) < ($statisticNumber[2] ?? 0)) {
if(empty($childrenItem['address']) && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); throw new ValidateException('【省公司发起人】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_9_2'] ?? 0).' 人');
if(((float)$childrenItem['lat'] <= 0 || (float)$childrenItem['lng'] <= 0) && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请选择定位信息!'); }
if((float)$childrenItem['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!');
break; break;
case 8: // case 10: break;
if(count($childrenItem['mer_id_list']) <= 0) throw new ValidateException('配送商至少关联一个商户!'); };
break;
}
} }
// 判断:餐厅关联的商户是否重复 // 判断:餐厅关联的商户是否重复
$merIds = array_filter(array_column($childrenList,'mer_id')); $merIds = array_filter(array_column($childrenList,'mer_id'));
@ -117,7 +177,7 @@ class Agent extends BaseController{
// 判断:当前关联商户中,是否存在其他已经被关联的商户 // 判断:当前关联商户中,是否存在其他已经被关联的商户
$ids = array_filter(array_column($childrenList,'id')); $ids = array_filter(array_column($childrenList,'id'));
$isHas = (int)app()->make(AgentRepository::class) $isHas = (int)app()->make(AgentRepository::class)
->getSearch([]) ->getSearchModel([])
->whereNotIn('id',$ids) ->whereNotIn('id',$ids)
->whereIn('mer_id',$merIds) ->whereIn('mer_id',$merIds)
->count(); ->count();
@ -133,9 +193,13 @@ class Agent extends BaseController{
$ids = array_filter(array_column($childrenList,'id')); $ids = array_filter(array_column($childrenList,'id'));
$isHas = (int)app()->make(MerchantRepository::class) $isHas = (int)app()->make(MerchantRepository::class)
->getSearch([]) ->getSearch([])
->whereNotIn('agent_id',$ids) ->hasWhere('agent', function ($query) {
->whereIn('mer_id',$newMerIdList) $query->where('is_del', 0);
})
->whereNotIn('Merchant.agent_id',$ids)
->whereIn('Merchant.mer_id',$newMerIdList)
->count(); ->count();
if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!');
} }
// 判断agentId 大于0验证data的信息 // 判断agentId 大于0验证data的信息
@ -148,21 +212,21 @@ class Agent extends BaseController{
case 2: case 2:
case 3: case 3:
case 4: case 4:
if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); // if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!');
break; break;
case 5: case 5:
case 6: case 6:
if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['city_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['area_id'] <= 0) throw new ValidateException('请完善地区信息!');
break; break;
case 7: case 7:
if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['city_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['area_id'] <= 0) throw new ValidateException('请完善地区信息!');
if((float)$data['street_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['street_id'] <= 0) throw new ValidateException('请完善地区信息!');
if(empty($data['address']) && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(empty($data['address'])) throw new ValidateException('请完善地区信息!');
if(((float)$data['lat'] <= 0 || (float)$data['lng'] <= 0) && $data['is_headquarters'] == 0) throw new ValidateException('请选择定位信息!'); if(((float)$data['lat'] <= 0 || (float)$data['lng'] <= 0)) throw new ValidateException('请选择定位信息!');
if((float)$data['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!'); if((float)$data['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!');
break; break;
case 8: case 8:
@ -173,7 +237,7 @@ class Agent extends BaseController{
if((int)$data['mer_id'] > 0){ if((int)$data['mer_id'] > 0){
// 判断:当前关联商户中,是否存在其他已经被关联的商户 // 判断:当前关联商户中,是否存在其他已经被关联的商户
$isHas = (int)app()->make(AgentRepository::class) $isHas = (int)app()->make(AgentRepository::class)
->getSearch([]) ->getSearchModel([])
->where('id','<>',$agentId) ->where('id','<>',$agentId)
->where('mer_id',(int)$data['mer_id']) ->where('mer_id',(int)$data['mer_id'])
->count(); ->count();
@ -185,13 +249,17 @@ class Agent extends BaseController{
// 判断:当前关联商户中,是否存在其他已经被关联的商户 // 判断:当前关联商户中,是否存在其他已经被关联的商户
$isHas = (int)app()->make(MerchantRepository::class) $isHas = (int)app()->make(MerchantRepository::class)
->getSearch([]) ->getSearch([])
->where('agent_id','<>',$agentId) ->hasWhere('agent', function ($query) {
->whereIn('mer_id',$data['mer_id_list']) $query->where('is_del', 0);
})
->where('Merchant.agent_id','<>',$agentId)
->whereIn('Merchant.mer_id',$data['mer_id_list'])
->count(); ->count();
if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!');
} }
} }
return compact("data", "agentId", "childrenList"); return compact("data", "agentId", "childrenList");
} }
/** /**
@ -310,6 +378,7 @@ class Agent extends BaseController{
['external_personnel_process',0], ['external_personnel_process',0],
['external_personnel_money_platform',0], ['external_personnel_money_platform',0],
['external_personnel_money_initiator',0], ['external_personnel_money_initiator',0],
['invite_limit',[]],
]); ]);
// 保存信息 // 保存信息
$cid = app()->make(ConfigClassifyRepository::class)->getConfigClassifyKeyById('agent_config', '代理中心配置'); $cid = app()->make(ConfigClassifyRepository::class)->getConfigClassifyKeyById('agent_config', '代理中心配置');