mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace base\common\command\admin\permission;
|
|
|
|
use app\admin\model\SystemAdmin;
|
|
use app\admin\model\SystemAuth;
|
|
use app\admin\model\SystemAuthNode;
|
|
use app\admin\service\NodeService;
|
|
use app\common\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Argument;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
|
|
class AdminPermissionUserBase extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
parent::configure();
|
|
|
|
$this->setName('admin:permission:user')
|
|
->addOption('user-id', 'u', Option::VALUE_OPTIONAL, '用户ID', null)
|
|
->setDescription('查看用户权限');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$userId = $input->getOption('user-id');
|
|
|
|
// 验证用户ID参数
|
|
if (empty($userId)) {
|
|
$output->error('缺少必要参数 --user-id');
|
|
return;
|
|
}
|
|
|
|
// 查询用户
|
|
$user = SystemAdmin::find($userId);
|
|
|
|
if (empty($user)) {
|
|
$output->error('用户不存在');
|
|
return;
|
|
}
|
|
|
|
// 查询用户角色
|
|
$roles = [];
|
|
$authIds = $user->auth_ids;
|
|
$authIdArray = [];
|
|
|
|
if (!empty($authIds)) {
|
|
$authIdArray = array_filter(explode(',', $authIds));
|
|
|
|
if (!empty($authIdArray)) {
|
|
$roles = SystemAuth::whereIn('id', $authIdArray)
|
|
->where('delete_time', 0)
|
|
->field('id,title')
|
|
->select()
|
|
->toArray();
|
|
}
|
|
}
|
|
|
|
// 查询用户权限节点
|
|
$nodes = [];
|
|
if (!empty($authIdArray)) {
|
|
$nodes = SystemAuthNode::whereIn('auth_id', $authIdArray)
|
|
->column('node');
|
|
}
|
|
|
|
// 输出结果
|
|
$output->info('用户权限信息');
|
|
$output->info('用户ID: ' . $user->id);
|
|
$output->info('用户名: ' . $user->username);
|
|
|
|
if (!empty($roles)) {
|
|
$output->info('角色列表:');
|
|
foreach ($roles as $role) {
|
|
$output->comment(' - ID: ' . $role['id'] . ', 标题: ' . $role['title']);
|
|
}
|
|
} else {
|
|
$output->comment('用户没有分配任何角色');
|
|
}
|
|
|
|
if (!empty($nodes)) {
|
|
$output->info('权限节点列表:');
|
|
foreach ($nodes as $node) {
|
|
$output->comment(' - ' . $node);
|
|
}
|
|
} else {
|
|
$output->comment('用户没有分配任何权限节点');
|
|
}
|
|
|
|
return;
|
|
}
|
|
} |