feat: 升级权限管理模式

This commit is contained in:
augushong
2025-03-20 16:57:05 +08:00
parent 1887733b32
commit d3e85fa552
50 changed files with 330 additions and 1125 deletions

View File

@@ -2,7 +2,10 @@
namespace base\common\service;
use app\admin\model\SystemAuthNode;
use app\admin\service\NodeService;
use app\common\constants\AdminConstant;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Db;
@@ -26,7 +29,6 @@ class AuthServiceBase
'auth_on' => true, // 权限开关
'system_admin' => 'system_admin', // 用户表
'system_auth' => 'system_auth', // 权限表
'system_node' => 'system_node', // 节点表
'system_auth_node' => 'system_auth_node', // 权限-节点表
];
@@ -48,6 +50,8 @@ class AuthServiceBase
*/
protected $adminNode;
protected $nodeService;
/***
* 构造方法
* AuthService constructor.
@@ -58,6 +62,8 @@ class AuthServiceBase
*/
public function __construct($adminId = null)
{
$this->nodeService = new NodeService();
$this->adminId = $adminId;
$this->adminInfo = $this->getAdminInfo();
$this->nodeList = $this->getNodeList();
@@ -66,7 +72,7 @@ class AuthServiceBase
return $this;
}
public function isSuperAdmin()
public function isSuperAdmin()
{
return $this->adminId == AdminConstant::SUPER_ADMIN_ID;
}
@@ -100,7 +106,7 @@ class AuthServiceBase
return Config::get('admin.default_auth_check');
}
$nodeInfo = $this->nodeList[$node];
if ($nodeInfo['is_auth'] == 0) {
if (!$nodeInfo['auth']) {
return true;
}
// 用户验证,优先获取缓存信息
@@ -143,20 +149,7 @@ class AuthServiceBase
}
if (!empty($adminInfo) && !empty($adminInfo['auth_ids'])) {
$buildAuthSql = Db::name($this->config['system_auth'])
->distinct(true)
->whereIn('id', $adminInfo['auth_ids'])
->field('id')
->buildSql(true);
$buildAuthNodeSql = Db::name($this->config['system_auth_node'])
->distinct(true)
->where("auth_id IN {$buildAuthSql}")
->field('node_id')
->buildSql(true);
$nodeList = Db::name($this->config['system_node'])
->distinct(true)
->where("id IN {$buildAuthNodeSql}")
->column('node');
$nodeList = SystemAuthNode::where('auth_id', 'in', $adminInfo['auth_ids'])->cache(60)->column('node');
}
return $nodeList;
@@ -170,9 +163,15 @@ class AuthServiceBase
*/
public function getNodeList()
{
return Db::name($this->config['system_node'])
->autoCache(null, null, 'table')
->column('id,node,title,type,is_auth', 'node');
$cache_key = 'node_paris';
$node_list = Cache::get($cache_key);
if (!$node_list) {
$node_list = $this->nodeService->getNodeParis();
Cache::set($cache_key, $node_list, 60);
}
return $node_list;
}
/**