76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\controller;
|
|
|
|
use app\adminapi\model\AuthRule;
|
|
use app\common\controller\AdminApi;
|
|
|
|
use app\adminapi\model\AuthGroup;
|
|
use app\adminapi\model\AuthGroupAccess;
|
|
|
|
use fast\Tree;
|
|
use think\Db;
|
|
use think\Exception;
|
|
|
|
|
|
/**
|
|
* api角色组
|
|
*
|
|
* @icon fa fa-group
|
|
* @remark 角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别下级的角色组或管理员
|
|
*/
|
|
class Group extends AdminApi
|
|
{
|
|
protected $model = null;
|
|
|
|
//无需要权限判断的方法
|
|
protected $noNeedRight = ['roletree'];
|
|
//当前登录管理员所有子组别
|
|
protected $childrenGroupIds = [];
|
|
//当前组别列表数据
|
|
protected $grouplist = [];
|
|
protected $groupdata = [];
|
|
|
|
|
|
/**
|
|
* 初始化操作
|
|
* @access protected
|
|
*/
|
|
public function _initialize()
|
|
{
|
|
$this->model = new AuthGroup;
|
|
parent::_initialize();
|
|
|
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds(true);
|
|
|
|
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
|
|
|
|
Tree::instance()->init($groupList);
|
|
$groupList = [];
|
|
if ($this->auth->isSuperAdmin()) {
|
|
$groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
|
|
} else {
|
|
$groups = $this->auth->getGroups();
|
|
$groupIds = [];
|
|
foreach ($groups as $m => $n) {
|
|
if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) {
|
|
continue;
|
|
}
|
|
$groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid'])));
|
|
foreach ($groupList as $index => $item) {
|
|
$groupIds[] = $item['id'];
|
|
}
|
|
}
|
|
}
|
|
$groupName = [];
|
|
foreach ($groupList as $k => $v) {
|
|
$groupName[$v['id']] = $v['name'];
|
|
}
|
|
|
|
$this->grouplist = $groupList;
|
|
$this->groupdata = $groupName;
|
|
|
|
|
|
}
|
|
|
|
} |