nizongfeng 3 年之前
父節點
當前提交
9780a623af
共有 2 個檔案被更改,包括 42 行新增3 行删除
  1. +18
    -3
      application/admin/controller/auth/Admin.php
  2. +24
    -0
      application/admin/dao/GroupDao.php

+ 18
- 3
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]);


+ 24
- 0
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;
}
}
}

Loading…
取消
儲存