diff --git a/application/admin/controller/auth/Admin.php b/application/admin/controller/auth/Admin.php index ea3e269..ab7ce5a 100755 --- a/application/admin/controller/auth/Admin.php +++ b/application/admin/controller/auth/Admin.php @@ -2,6 +2,7 @@ namespace app\admin\controller\auth; +use app\admin\dao\GroupDao; use app\admin\model\AuthGroup; use app\admin\model\AuthGroupAccess; use app\common\controller\Backend; @@ -300,12 +301,26 @@ class Admin extends Backend $name=$this->request->post('name'); $keyValue=$this->request->post('keyValue'); $this->model->field('id,nickname as name'); + $groupDao = new GroupDao(); + $groupIds = $groupDao->getSubGroup($this->auth->getGroupId()); + //获取用户ID + $accModel = new AuthGroupAccess(); + $accList = $accModel->where(["group_id" => ["in",$groupIds]])->select(); + if ($accList == null) { + return json(['list' => []]); + } + $accList = $accList->toArray(); + $ids = []; + foreach ($accList as $acc) { + $ids[] = $acc['uid']; + } + $where = ["id"=>["in",$ids]]; if($keyValue){ - $this->model->where(['id'=>$keyValue]); + $where = ['id'=>$keyValue]; }elseif($name){ - $this->model->where(['nickname'=>['like','%'.$name.'%']]); + $where = ['nickname'=>['like','%'.$name.'%'],"id"=>["in",$ids]]; } - $result= $this->model->select(); + $result= $this->model->where($where)->select(); // print_r($result); if($keyValue){ return json(['list' => $result]); diff --git a/application/admin/dao/GroupDao.php b/application/admin/dao/GroupDao.php index 8039142..270ec7b 100644 --- a/application/admin/dao/GroupDao.php +++ b/application/admin/dao/GroupDao.php @@ -39,4 +39,28 @@ class GroupDao return $id; } } + + /** + * 获取所有子节点的ID + * @param $id + * @return array + */ + public function getSubGroup($id){ + try { + $idArr = [$id]; + $model = new AuthGroup(); + $result = $model->where(["pid" => $id])->select(); + if ($result == null) { + return $idArr; + } + $list = $result->toArray(); + foreach ($list as $info) { + $subIdArr = $this->getSubGroup($info['id']); + $idArr = array_merge($idArr, $subIdArr); + } + return $idArr; + } catch (Exception $e) { + return $idArr; + } + } } \ No newline at end of file