nizongfeng před 3 roky
rodič
revize
9780a623af
2 změnil soubory, kde provedl 42 přidání a 3 odebrání
  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 Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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;
}
}
}

Načítá se…
Zrušit
Uložit