From 7bfc8433f6b51ca93a33eebc0f950747ba2cbecd Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 22 Mar 2024 11:14:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E9=A4=90=E5=8E=85?= =?UTF-8?q?=E3=80=81=E9=85=92=E9=81=93=E9=A6=86=E3=80=81=E7=83=9F=E9=85=92?= =?UTF-8?q?=E5=BA=97=E7=BB=91=E5=AE=9A=E5=95=86=E6=88=B7=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/marketing/Agent.php | 2 +- .../marketing/AgentRepository.php | 62 ++++++++++++++----- app/controller/admin/marketing/Agent.php | 4 +- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/app/common/model/marketing/Agent.php b/app/common/model/marketing/Agent.php index 460c3ea..896999d 100644 --- a/app/common/model/marketing/Agent.php +++ b/app/common/model/marketing/Agent.php @@ -32,7 +32,7 @@ class Agent extends BaseModel{ * @return array|string */ public function getMerIdListAttr(){ - if(($this->agent_type ?? 0) == 8 && ($this->id ?? 0) > 0){ + if(($this->id ?? 0) > 0){ return Merchant::where('agent_id',$this->id)->column('mer_id'); } diff --git a/app/common/repositories/marketing/AgentRepository.php b/app/common/repositories/marketing/AgentRepository.php index ec02e97..ec6fde1 100644 --- a/app/common/repositories/marketing/AgentRepository.php +++ b/app/common/repositories/marketing/AgentRepository.php @@ -181,12 +181,10 @@ class AgentRepository extends BaseRepository{ Agent::update($updateInfo,['id'=>$agentId]); // 修改配送商 - 商户关联信息 $merIdList = is_array($data['mer_id_list']) ? $data['mer_id_list'] : []; - if(count($merIdList) > 0){ - // 删除已经存在的关联信息 - Merchant::update(['agent_id' => null],['agent_id'=>$agentId]); - // 建立新的关联信息 - Merchant::whereIn('mer_id',$data['mer_id_list'])->update(['agent_id' => $agentId]); - } + // 删除已经存在的关联信息 + Merchant::update(['agent_id' => null],['agent_id'=>$agentId]); + // 建立新的关联信息 + if(count($merIdList) > 0) Merchant::whereIn('mer_id',$merIdList)->update(['agent_id' => $agentId]); } /** * Common: 代理添加/编辑 —— 处理子类信息 @@ -225,8 +223,8 @@ class AgentRepository extends BaseRepository{ $childrenItemId = $childrenItem['id'] ?? 0; $handleData = array_intersect_key($childrenItem, $keys); $handleData['pid'] = $agentId; - // 判断:如果为配送商 处理商户关联信息 - if($childrenItem['agent_type'] == 8){ + // 判断:如果为配送商、烟酒馆 处理商户关联信息 + if(in_array($childrenItem['agent_type'],[8,11])){ // 判断:应该修改还是编辑 if((int)$childrenItemId > 0) $this->dao->update($childrenItemId,$handleData); else $childrenItemId = Agent::insertGetId($handleData); @@ -273,26 +271,62 @@ class AgentRepository extends BaseRepository{ */ public function getEditInfo($params){ // 获取当前信息 编辑类型:0=发起人管理,1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商 + $info = []; if((int)$params['agent_id'] > 0) { // 非发起人管理:存在info及children_list $info = $this->dao->searchList(['id' => $params['agent_id']])->findOrEmpty(); - $childrenList = $this->dao + $children_list = $this->dao ->searchList(['pid' => $params['agent_id']]) ->select() ->toArray(); } else{ // 发起人管理:仅存在children_list - $childrenList = $this->dao + $children_list = $this->dao ->searchList(['pid' => 0,'agent_type' => 1]) ->select() ->toArray(); } + // 获取已被酒道馆绑定的商户 + $shop_mer = $this->getMerchant(0); + // 获取已被烟酒店绑定的商户 + $wine = $this->getMerchant(3); + // 获取已被餐厅绑定的商户 + $mer = Agent::hasWhere('mer',function($query){ + $query->where('is_del',0); + },'Agent.mer_id,Agent.id as agent_id,Agent.contact_name') + ->where('Agent.mer_id','>',0) + ->where('Agent.is_del',0) + ->select() + ->toArray(); - return [ - 'info' => $info ?? [], - 'children_list' => $childrenList - ]; + + return compact('info','children_list','shop_mer','wine','mer'); + } + /** + * Common: 获取对应类型已绑定的 酒道馆 || 烟酒馆 + * Author: wu-hui + * Time: 2024/03/22 10:38 + * @param $merchantType + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + private function getMerchant($merchantType){ + return Merchant::hasWhere('agent',function($query){ + $query->where('is_del',0); + },'Merchant.mer_id,Merchant.agent_id,Merchant.merchant_type') + ->where('agent_id','>',0) + ->where('merchant_type',$merchantType) + ->with([ + 'agent' => function($query){ + $query->field(['id','contact_name']) + ->bind(['contact_name']); + } + ]) + ->select() + ->toArray(); } /** * Common: 获取配置 diff --git a/app/controller/admin/marketing/Agent.php b/app/controller/admin/marketing/Agent.php index 86576db..42c131f 100644 --- a/app/controller/admin/marketing/Agent.php +++ b/app/controller/admin/marketing/Agent.php @@ -230,7 +230,9 @@ class Agent extends BaseController{ if(count($merIdList) > 0){ // 判断:是否存在重复 $newMerIdList = call_user_func_array('array_merge', $merIdList); - if(count($newMerIdList) != count(array_unique($newMerIdList))) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); + if(count($newMerIdList) != count(array_unique($newMerIdList))) { + throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); + } // 判断:当前关联商户中,是否存在其他已经被关联的商户 $ids = array_filter(array_column($childrenList,'id')); $isHas = (int)app()->make(MerchantRepository::class)