From 3d215d57aa20876f1238d16c8ec8ef3d102f1773 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Sat, 24 Jul 2021 15:11:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BC=9A=E9=95=BF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=88=96=E8=80=85=E6=8D=A2=E7=BB=91=E5=BC=95=E8=B5=B7?= =?UTF-8?q?=E7=9A=84=E5=B8=82=E5=9C=BA=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/OldCountController.class.php | 9 ++- .../PromoteCompanyController.class.php | 7 +-- Application/Admin/Event/MarketEvent.class.php | 62 ++++++++++++++++++- .../Base/Service/MarketService.class.php | 12 ++-- .../Service/PromoteCompanyService.class.php | 8 +-- .../Base/Service/PromoteService.class.php | 2 - 6 files changed, 78 insertions(+), 22 deletions(-) diff --git a/Application/Admin/Controller/OldCountController.class.php b/Application/Admin/Controller/OldCountController.class.php index 60df464d3..770c0875e 100644 --- a/Application/Admin/Controller/OldCountController.class.php +++ b/Application/Admin/Controller/OldCountController.class.php @@ -763,10 +763,15 @@ class OldCountController extends \Think\Controller } return $time_arr; } - public function eventTest($event,$action) + public function eventTest($event,$action,$arg = false) { $Event = A($event,"Event"); - $res = $Event->$action(); + if(!$arg){ + $res = $Event->$action(); + }else{ + $res = call_user_func_array(array($Event, $action), explode(":",$arg)); + } + dd($res); } diff --git a/Application/Admin/Controller/PromoteCompanyController.class.php b/Application/Admin/Controller/PromoteCompanyController.class.php index b38df25ba..01f3cb1b3 100644 --- a/Application/Admin/Controller/PromoteCompanyController.class.php +++ b/Application/Admin/Controller/PromoteCompanyController.class.php @@ -1436,15 +1436,12 @@ class PromoteCompanyController extends ThinkController M("Promote","tab_")->where("company_id = '{$company_id}'")->save($savedata); // 权限跟随 if($is_change_belong){ - $authGroup = M('auth_group',"sys_")->where(['title'=>'市场总监'])->find(); $subPromoteIds = M('promote', 'tab_')->where(['level' => 1, 'company_id' => $company_id])->getField('id', true); - $dataPresident = explode(',', $authGroup['data_president']); if ($save['company_belong'] == 1 || $save['company_belong'] == 2) { - $dataPresident = array_unique(array_merge($dataPresident, $subPromoteIds)); + A("Market","Event")->pushPresident($subPromoteIds); } else { - $dataPresident = array_diff($dataPresident, $subPromoteIds); + A("Market","Event")->removePresident($subPromoteIds); } - M('auth_group',"sys_")->where(['title'=>'市场总监'])->save(['data_president'=>implode(',', $dataPresident)]); resetUserAuth(); } } diff --git a/Application/Admin/Event/MarketEvent.class.php b/Application/Admin/Event/MarketEvent.class.php index fc4af54c4..a37235944 100644 --- a/Application/Admin/Event/MarketEvent.class.php +++ b/Application/Admin/Event/MarketEvent.class.php @@ -78,6 +78,9 @@ class MarketEvent extends Controller { return $this->$key; } + /** + * 获取等级名称 + */ public function getLevelName($level) { return $this->LevelConfig[$level]; @@ -112,7 +115,64 @@ class MarketEvent extends Controller return true; } $info = M('auth_group','sys_')->where(['id'=>$leader_group])->find(); - return M('auth_group','sys_')->where(['id'=>$leader_group])->save(['data_president'=>$info['data_president'].",".$promote_id]); + $dataPresident = explode(',', $info['data_president']); + $dataPresident = array_unique(array_merge($dataPresident, array($promote_id))); + return $this->saveLeaderPresident($leader_group,$dataPresident);; + } + + /** + * 移除原有权限 + * @param [array] $promoteIds + * @return void + */ + public function removePresident($promoteIds) + { + if(!is_array($promoteIds)){ + $promoteIds = explode(",",$promoteIds); + }; + $leaderPresident = $this->getLeaderPresident(); + foreach ($leaderPresident as $k => $v) { + $dataPresident = explode(',', $v); + $dataPresident = array_diff($dataPresident, $promoteIds); + $this->saveLeaderPresident($k,$dataPresident); + } + } + + /** + * 添加原有权限,设计重复问题 + * @param [array] $promoteIds + * @return void + */ + public function pushPresident($promoteIds) + { + if(!is_array($promoteIds)){ + $promoteIds = explode(",",$promoteIds); + }; + foreach ($promoteIds as $k => $v) { + $admin_id = M("Promote","tab_")->where("id = {$v}")->getField("admin_id"); + $this->addPresident($admin_id,$v); + } + return true; + } + + private function getLeaderPresident() + { + $where = [ + "department_id"=>['in',$this->MarketDepartmentId], + "department_level"=>['eq',$this->DirectorLevel] + ]; + return M('auth_group','sys_')->where($where)->getField("id,data_president",true); + } + private function saveLeaderPresident($gid,$data_president) + { + if(is_array($data_president)){ + $data_president = implode(",",$data_president); + }; + $savedata = [ + "id"=>$gid, + "data_president"=>$data_president + ]; + return M('auth_group','sys_')->save($savedata); } public function getDepartmentUserId($department_id) diff --git a/Application/Base/Service/MarketService.class.php b/Application/Base/Service/MarketService.class.php index 522064a5f..e8b979143 100644 --- a/Application/Base/Service/MarketService.class.php +++ b/Application/Base/Service/MarketService.class.php @@ -42,13 +42,11 @@ class MarketService $map['admin_id'] = $fromId; M('promote', 'tab_')->where($map)->save(['admin_id' => $toId]); M('promote', 'tab_')->where(['chain' => ['like', $promote['chain'] . $promote['id'] . '/%']])->save(['admin_id' => $toId]); - - $authGroup = M('auth_group', 'sys_')->where(['title'=>'市场总监'])->find(); - $dataPresident = explode(',', $authGroup['data_president']); - if (!in_array($promote['id'], $dataPresident)) { - M('auth_group', 'sys_')->where(['title'=>'市场总监'])->save(['data_president' => $authGroup['data_president'] . ',' . $promote['id']]); - resetUserAuth(); - } + + $marketEvent = A("Market","Event"); + $marketEvent->removePresident($promote['id']); + $marketEvent->addPresident($toId,$promote['id']); + resetUserAuth(); } public function shiftSpend($promoteIds, $fromId, $toId, $time = null) diff --git a/Application/Base/Service/PromoteCompanyService.class.php b/Application/Base/Service/PromoteCompanyService.class.php index d72917a04..e4b46b431 100644 --- a/Application/Base/Service/PromoteCompanyService.class.php +++ b/Application/Base/Service/PromoteCompanyService.class.php @@ -272,15 +272,13 @@ class PromoteCompanyService // 权限跟随 if($isChangeBelong){ - $authGroup = M('auth_group', 'sys_')->where(['title'=>'市场总监'])->find(); + $subPromoteIds = M('promote', 'tab_')->where(['level' => 1, 'company_id' => $companyId])->getField('id', true); - $dataPresident = explode(',', $authGroup['data_president']); if ($companyInfo['company_belong'] == 1 || $companyInfo['company_belong'] == 2) { - $dataPresident = array_unique(array_merge($dataPresident, $subPromoteIds)); + A("Market","Event")->pushPresident($subPromoteIds); } else { - $dataPresident = array_diff($dataPresident, $subPromoteIds); + A("Market","Event")->removePresident($subPromoteIds); } - M('auth_group', 'sys_')->where(['title' => '市场总监'])->save(['data_president' => implode(',', $dataPresident)]); resetUserAuth(); } } diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index d41e7e4c1..48a018520 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -1124,8 +1124,6 @@ class PromoteService { if ($data['level'] == 1 && in_array($data['company_belong'], [1, 2])) { $id = M('promote', 'tab_')->getLastInsID(); A('Market','Event')->addPresident($data['admin_id'],$id); - // $info = M('sys_auth_group')->where(['title'=>'市场总监'])->find(); - // M('sys_auth_group')->where(['title'=>'市场总监'])->save(['data_president'=>$info['data_president'].",".$id]); resetUserAuth(); }