From e5b093449f83d6468839bc58cad986f46a7509af Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 20 Feb 2024 11:55:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BA=AB=E4=BB=BD=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/marketing/AgentDao.php | 2 +- app/common/model/marketing/Agent.php | 28 ++++++++++++-- .../marketing/AgentRepository.php | 37 ++++++++++++++++++- app/controller/api/Agent.php | 32 +++++++++++++--- route/api.php | 9 +---- 5 files changed, 90 insertions(+), 18 deletions(-) diff --git a/app/common/dao/marketing/AgentDao.php b/app/common/dao/marketing/AgentDao.php index 92941bc..4223334 100644 --- a/app/common/dao/marketing/AgentDao.php +++ b/app/common/dao/marketing/AgentDao.php @@ -79,7 +79,7 @@ class AgentDao extends BaseDao{ }, ]) ->order('create_time DESC,id DESC') - ->append(['only_key','mer_id_list','children_count']); + ->append(['only_key','mer_id_list','children_count','agent_type_text']); } diff --git a/app/common/model/marketing/Agent.php b/app/common/model/marketing/Agent.php index 9b86414..5fe9c07 100644 --- a/app/common/model/marketing/Agent.php +++ b/app/common/model/marketing/Agent.php @@ -59,6 +59,31 @@ class Agent extends BaseModel{ } return 0; } + /** + * Common: 获取角色类型 + * Author: wu-hui + * Time: 2024/02/20 10:44 + * @return string + */ + public function getAgentTypeTextAttr():string{ + // 类型:1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤 + $agentType = $this->agent_type ?? -1; + switch($agentType){ + case 1: return '总部发起人';break; + case 2: return '省公司发起人';break; + case 3: return '省公司外勤';break; + case 4: return '省公司内勤';break; + case 5: return '区县运营商';break; + case 6: return '区县合伙人';break; + case 7: return '餐厅';break; + case 8: return '配送商';break; + case 9: return '总部外勤';break; + case 10: return '总部内勤';break; + } + + return ''; + } + public function user(){ return $this->hasOne(User::class, 'uid', 'uid'); @@ -66,9 +91,6 @@ class Agent extends BaseModel{ public function parent(){ return $this->hasOne(self::class, 'id', 'pid'); } - - - public function province(){ return $this->hasOne(CityArea::class, 'id', 'province_id'); } diff --git a/app/common/repositories/marketing/AgentRepository.php b/app/common/repositories/marketing/AgentRepository.php index 3bd9927..8af09a2 100644 --- a/app/common/repositories/marketing/AgentRepository.php +++ b/app/common/repositories/marketing/AgentRepository.php @@ -96,6 +96,41 @@ class AgentRepository extends BaseRepository{ throw new ValidateException('小程序码生成失败!'); } + /** + * Common: 获取用户指定身份列表 + * Author: wu-hui + * Time: 2024/02/19 17:47 + * @param int $uid + * @param string $type + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getIdentityList(int $uid,string $type = 'headquarters'):array{ + // 根据身份类型,获取代理中心角色类型数组:headquarters=总部,province=省公司,county=区县 + // 类型:1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤 + switch($type){ + case 'headquarters': + $agentType = [1,9,10]; + break; + case 'province': + $agentType = [2,3,4]; + break; + case 'county': + $agentType = [5,6,7,8]; + break; + default: + throw new ValidateException('身份查询失败!'); + } + // 获取对应的角色身份列表 + return $this->dao->searchList(['uid'=>$uid]) + ->whereIn('agent_type', $agentType) + ->whereNotIn('agent_type', [4,7,8,10])// 忽略无管理菜单的角色 + ->field(['id','uid','agent_type','province_id','city_id','area_id','street_id','address','mer_id','contact_name']) + ->select() + ->toArray(); + } /** @@ -212,7 +247,7 @@ class AgentRepository extends BaseRepository{ $delIds = array_diff($allIds,$updateIds); // 处理结果 进行对应的操作;必须按照先删除、在修改、最后添加的顺序进行 - if(count($delIds) > 0) Agent::whereIn('id',$delIds)->where('agent_type','<>',8)->update(['is_del'=>1]); + if(count($delIds) > 0) Agent::whereIn('id',$delIds)->update(['is_del'=>1]); if(count($updateData) > 0) Agent::batchUpdate(array_values($updateData)); if(count($insertData) > 0) $this->dao->insertAll($insertData); if(count($merUpdateData) > 0) { diff --git a/app/controller/api/Agent.php b/app/controller/api/Agent.php index 9e0ff36..162cb8d 100644 --- a/app/controller/api/Agent.php +++ b/app/controller/api/Agent.php @@ -23,16 +23,14 @@ class Agent extends BaseController{ * Common: 获取代理列表 * Author: wu-hui * Time: 2024/01/29 16:00 - * @return mixed */ public function agentList(){ // 参数处理 [$page, $limit] = $this->getPage(); - $params = $this->request->params(['is_get_self','not_page','pid']); - if((int)$params['is_get_self'] > 0) $params['uid'] = $this->request->uid(); + $params = $this->request->params(['uid','not_page','pid', 'id']); // 信息列表获取 - if((int)$params['not_page'] > 0) $data = app()->make(AgentRepository::class)->getAllList((array)$params); - else $data = app()->make(AgentRepository::class)->getList((array)$params,(int)$page,(int)$limit); + if((int)$params['not_page'] > 0) $data = $this->repository->getAllList((array)$params); + else $data = $this->repository->getList((array)$params,(int)$page,(int)$limit); return app('json')->success($data); } @@ -68,7 +66,7 @@ class Agent extends BaseController{ * @return mixed */ public function getConfig(){ - $config = app()->make(AgentRepository::class)->getConfig(); + $config = $this->repository->getConfig(); return app('json')->success($config); } @@ -214,6 +212,28 @@ class Agent extends BaseController{ return app('json')->success($data); } + /** + * Common: 获取用户身份信息列表 + * Author: wu-hui + * Time: 2024/02/19 17:47 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getIdentityList(){ + $uid = $this->request->uid(); + // headquarters=总部,province=省公司,county=区县 + $headquartersList = (array)$this->repository->getIdentityList($uid); + $provinceList = (array)$this->repository->getIdentityList($uid,'province'); + $countyList = (array)$this->repository->getIdentityList($uid,'county'); + + return app('json')->success([ + 'headquarters_list' => $headquartersList, + 'province_list' => $provinceList, + 'county_list' => $countyList, + ]); + } } diff --git a/route/api.php b/route/api.php index f7fa774..c6a28e8 100644 --- a/route/api.php +++ b/route/api.php @@ -395,6 +395,8 @@ Route::group('api/', function () { Route::post('apply_record', 'applyRecord');// 申请记录 Route::get('apply_info', 'applyInfo');// 申请信息 Route::get('commission_list', 'commissionList');// 佣金明细 + Route::get('identity_list', 'getIdentityList');// 某个身份是否有效 + })->prefix('api.Agent/'); @@ -403,16 +405,9 @@ Route::group('api/', function () { Route::post('apply', 'applyJoin');// 申请成为供应商 Route::post('apply_record', 'applyRecord');// 申请记录 Route::get('apply_info', 'applyInfo');// 申请信息详情 - - - })->prefix('api.Supplier/'); - - - - })->middleware(UserTokenMiddleware::class, true); //非强制登录 Route::group(function () {