From e17d1f699b2def8cc74b33effd1f466686e35d13 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Wed, 21 Feb 2024 16:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E8=A7=92=E8=89=B2=E6=8B=9B=E5=8B=9F=E4=B8=8B?= =?UTF-8?q?=E7=BA=A7=E6=95=B0=E9=87=8F=E9=99=90=E5=88=B6=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=9A=E9=85=8D=E9=80=81=E5=95=86=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=95=86=E6=88=B7=E9=94=99=E8=AF=AF=EF=BC=8C=E9=85=8D=E9=80=81?= =?UTF-8?q?=E5=95=86=E5=9F=8E=E5=88=A0=E9=99=A4=E5=90=8E=E5=B7=B2=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=9A=84=E5=95=86=E6=88=B7=E6=9C=AA=E8=A7=A3=E9=99=A4?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=EF=BC=8C=E5=AF=BC=E8=87=B4=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=BB=91=E5=AE=9A=E9=85=8D=E9=80=81=E5=95=86?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=EF=BC=9A=E7=9C=81=E5=85=AC=E5=8F=B8?= =?UTF-8?q?=E5=8F=91=E8=B5=B7=E4=BA=BA=E3=80=81=E7=9C=81=E5=85=AC=E5=8F=B8?= =?UTF-8?q?=E5=A4=96=E5=8B=A4=E3=80=81=E7=9C=81=E5=85=AC=E5=8F=B8=E5=86=85?= =?UTF-8?q?=E5=8B=A4=E5=8F=96=E6=B6=88=E7=9C=81=E5=9C=B0=E5=8C=BA=E9=80=89?= =?UTF-8?q?=E6=8B=A9=20=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=85=8D=E9=80=81?= =?UTF-8?q?=E5=95=86=E4=B8=8D=E8=83=BD=E6=B7=BB=E5=8A=A0=E6=88=96=E8=80=85?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=88=A0=E9=99=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/system/merchant/Merchant.php | 5 + .../marketing/AgentRepository.php | 14 +- .../system/merchant/MerchantRepository.php | 5 +- app/controller/admin/marketing/Agent.php | 155 +++++++++++++----- 4 files changed, 130 insertions(+), 49 deletions(-) diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index 7983a8b..3241890 100644 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -8,6 +8,7 @@ namespace app\common\model\system\merchant; use app\common\dao\store\product\ProductDao; use app\common\model\BaseModel; +use app\common\model\marketing\Agent; use app\common\model\store\coupon\StoreCouponProduct; use app\common\model\store\coupon\StoreCouponUser; use app\common\model\store\order\StoreOrder; @@ -281,6 +282,10 @@ class Merchant extends BaseModel public function merShop(){ 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(){ return $this->hasOne(MerchantBrand::class,'id', 'brand_id'); diff --git a/app/common/repositories/marketing/AgentRepository.php b/app/common/repositories/marketing/AgentRepository.php index bb5ab7a..b4083b1 100644 --- a/app/common/repositories/marketing/AgentRepository.php +++ b/app/common/repositories/marketing/AgentRepository.php @@ -173,8 +173,7 @@ class AgentRepository extends BaseRepository{ "address", "lat", "lng", - "mer_id", - 'is_headquarters' + "mer_id" ]); $updateInfo = array_intersect_key($data, $keys); Agent::update($updateInfo,['id'=>$agentId]); @@ -214,9 +213,9 @@ class AgentRepository extends BaseRepository{ "address", "lat", "lng", - "mer_id", - 'is_headquarters' + "mer_id" ]); + $eightUpdateIds = []; // 循环:区分对应的操作 foreach($childrenList as $childrenItem){ unset($childrenItem['user']); @@ -235,6 +234,8 @@ class AgentRepository extends BaseRepository{ 'agent_id' => $childrenItemId ]; } + // 记录配送商ID + $eightUpdateIds[] = (int)$childrenItemId; }else{ // 判断:应该修改还是编辑 if((int)$childrenItemId > 0) $updateData[] = $handleData; @@ -244,7 +245,7 @@ class AgentRepository extends BaseRepository{ // 获取需要删除的数据的id 删除思路:先获取总数据、对修改数据比较、删除缺少的项 $allIds = $this->dao->searchList([])->where('pid',$agentId)->column('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]); @@ -359,6 +360,8 @@ class AgentRepository extends BaseRepository{ 'external_personnel_process', 'external_personnel_money_platform', 'external_personnel_money_initiator', + // 邀请限制 + 'invite_limit' ]); $config['delivery_process'] = (int)$config['delivery_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['field_personnel_process'] = (int)$config['field_personnel_process']; $config['external_personnel_process'] = (int)$config['external_personnel_process']; + $config['invite_limit'] = $config['invite_limit'] ? (array)$config['invite_limit'] : []; return $config; } diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 876d9c6..a194f29 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -94,8 +94,11 @@ class MerchantRepository extends BaseRepository 'brand' => function ($query) { $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'); } diff --git a/app/controller/admin/marketing/Agent.php b/app/controller/admin/marketing/Agent.php index af94e45..709ead8 100644 --- a/app/controller/admin/marketing/Agent.php +++ b/app/controller/admin/marketing/Agent.php @@ -63,8 +63,7 @@ class Agent extends BaseController{ 'lat', 'lng', ['mer_id', 0], - ['mer_id_list', []], - ['is_headquarters', 0] + ['mer_id_list', []] ]); $agentId = (int)$this->request->param('id'); $childrenList = $this->request->param('children_list'); @@ -74,40 +73,101 @@ class Agent extends BaseController{ $agentStock = (float)array_sum(array_column($childrenList,'agent_stock')); if($agentStock != 100) throw new ValidateException('所有发起人的股份总和必须等于100!'); } - // 循环判断:$childrenList 的数据是否完善 类型:1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商 - foreach($childrenList as $childrenItem){ - if(empty($childrenItem['contact_name'])) throw new ValidateException('请输入联系人姓名!'); - if(empty($childrenItem['contact_phone'])) throw new ValidateException('请输入联系人电话!'); - if(isPhone($childrenItem['contact_phone'])) throw new ValidateException('请输入正确的联系人电话!'); - // 判断:根据当前角色判断 数据 - switch((int)$childrenItem['agent_type']){ + // 验证下级信息;类型:1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤 + if(count($childrenList) > 0){ + // 下级数据信息是否完善 + foreach($childrenList as $childrenItem){ + if(empty($childrenItem['contact_name'])) throw new ValidateException('请输入联系人姓名!'); + if(empty($childrenItem['contact_phone'])) throw new ValidateException('请输入联系人电话!'); + 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: - // 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; 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 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; + case 4: break; case 5: + // 判断:[区县运营商] 邀请 [区县合伙人]是否超出限制 + if(($inviteLimit['invite_5_6'] ?? 0) < ($statisticNumber[6] ?? 0)) { + throw new ValidateException('【区县合伙人】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_5_6'] ?? 0).' 人'); + } + break; 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((float)$childrenItem['area_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + // 判断:[区县合伙人] 邀请 [餐厅]是否超出限制 + if(($inviteLimit['invite_6_7'] ?? 0) < ($statisticNumber[7] ?? 0)) { + 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; - case 7: - 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((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(empty($childrenItem['address']) && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - 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('餐厅必须关联商户!'); + // case 7: break; + // case 8: break; + case 9: + // 判断:[总部外勤] 邀请 [省公司发起人]是否超出限制 + if(($inviteLimit['invite_9_2'] ?? 0) < ($statisticNumber[2] ?? 0)) { + throw new ValidateException('【省公司发起人】招募数量超出限制!仅允许招募 '.($inviteLimit['invite_9_2'] ?? 0).' 人'); + } break; - case 8: - if(count($childrenItem['mer_id_list']) <= 0) throw new ValidateException('配送商至少关联一个商户!'); - break; - } + // case 10: break; + }; } // 判断:餐厅关联的商户是否重复 $merIds = array_filter(array_column($childrenList,'mer_id')); @@ -117,7 +177,7 @@ class Agent extends BaseController{ // 判断:当前关联商户中,是否存在其他已经被关联的商户 $ids = array_filter(array_column($childrenList,'id')); $isHas = (int)app()->make(AgentRepository::class) - ->getSearch([]) + ->getSearchModel([]) ->whereNotIn('id',$ids) ->whereIn('mer_id',$merIds) ->count(); @@ -133,9 +193,13 @@ class Agent extends BaseController{ $ids = array_filter(array_column($childrenList,'id')); $isHas = (int)app()->make(MerchantRepository::class) ->getSearch([]) - ->whereNotIn('agent_id',$ids) - ->whereIn('mer_id',$newMerIdList) + ->hasWhere('agent', function ($query) { + $query->where('is_del', 0); + }) + ->whereNotIn('Merchant.agent_id',$ids) + ->whereIn('Merchant.mer_id',$newMerIdList) ->count(); + if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); } // 判断:agentId 大于0,验证data的信息 @@ -148,21 +212,21 @@ class Agent extends BaseController{ case 2: case 3: 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; case 5: case 6: - if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['city_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['area_id'] <= 0) throw new ValidateException('请完善地区信息!'); break; case 7: - if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['street_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - if(empty($data['address']) && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); - if(((float)$data['lat'] <= 0 || (float)$data['lng'] <= 0) && $data['is_headquarters'] == 0) throw new ValidateException('请选择定位信息!'); + if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['city_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['area_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['street_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if(empty($data['address'])) throw new ValidateException('请完善地区信息!'); + if(((float)$data['lat'] <= 0 || (float)$data['lng'] <= 0)) throw new ValidateException('请选择定位信息!'); if((float)$data['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!'); break; case 8: @@ -173,7 +237,7 @@ class Agent extends BaseController{ if((int)$data['mer_id'] > 0){ // 判断:当前关联商户中,是否存在其他已经被关联的商户 $isHas = (int)app()->make(AgentRepository::class) - ->getSearch([]) + ->getSearchModel([]) ->where('id','<>',$agentId) ->where('mer_id',(int)$data['mer_id']) ->count(); @@ -185,13 +249,17 @@ class Agent extends BaseController{ // 判断:当前关联商户中,是否存在其他已经被关联的商户 $isHas = (int)app()->make(MerchantRepository::class) ->getSearch([]) - ->where('agent_id','<>',$agentId) - ->whereIn('mer_id',$data['mer_id_list']) + ->hasWhere('agent', function ($query) { + $query->where('is_del', 0); + }) + ->where('Merchant.agent_id','<>',$agentId) + ->whereIn('Merchant.mer_id',$data['mer_id_list']) ->count(); if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); } } + return compact("data", "agentId", "childrenList"); } /** @@ -310,6 +378,7 @@ class Agent extends BaseController{ ['external_personnel_process',0], ['external_personnel_money_platform',0], ['external_personnel_money_initiator',0], + ['invite_limit',[]], ]); // 保存信息 $cid = app()->make(ConfigClassifyRepository::class)->getConfigClassifyKeyById('agent_config', '代理中心配置');