feat: 发布智能体版

This commit is contained in:
augushong
2026-03-26 20:22:34 +08:00
parent 7ee9e102a5
commit 8cc08bcb8c
138 changed files with 7964 additions and 660 deletions

View File

@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace base\common\command\admin\permission;
use app\common\console\Command;
use think\console\Input;
use think\console\Input\Option;
use think\console\Output;
use app\admin\service\NodeService;
/**
* admin:permission:nodes command - 查看权限节点
*/
class AdminPermissionNodesBase extends Command
{
/**
* 配置命令参数
*/
protected function configure()
{
parent::configure();
// 指令配置
$this->setName('admin:permission:nodes')
->setDescription('查看权限节点')
->addOption('level', null, Option::VALUE_OPTIONAL, '按级别过滤 (1=控制器, 2=方法)')
->addOption('module', null, Option::VALUE_OPTIONAL, '按模块过滤');
}
/**
* 执行命令
*
* @param Input $input
* @param Output $output
* @return int
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \ReflectionException
*/
protected function execute(Input $input, Output $output)
{
try {
// 获取所有权限节点
$nodeService = new NodeService();
$nodeList = $nodeService->getNodelist();
// 过滤条件
$filterLevel = $input->getOption('level');
$filterModule = $input->getOption('module');
// 应用过滤
$filteredNodes = $nodeList;
if ($filterLevel !== null) {
$level = (int)$filterLevel;
$filteredNodes = array_filter($filteredNodes, function ($node) use ($level) {
return isset($node['type']) && $node['type'] === $level;
});
}
if ($filterModule !== null) {
$filteredNodes = array_filter($filteredNodes, function ($node) use ($filterModule) {
return isset($node['module']) && $node['module'] === $filterModule;
});
}
// 重新索引数组
$filteredNodes = array_values($filteredNodes);
// 输出表头
$output->info('权限节点列表');
$output->writeln('================================');
if (empty($filteredNodes)) {
$output->comment('没有找到符合条件的权限节点');
return 0;
}
// 输出权限节点信息
foreach ($filteredNodes as $node) {
$levelText = $node['type'] == 1 ? '控制器' : '方法';
$authText = isset($node['auth']) && $node['auth'] ? '是' : '否';
$output->info('节点: ' . ($node['node'] ?? ''));
$output->comment(' 标题: ' . ($node['title'] ?? ''));
$output->comment(' 级别: ' . $levelText . ' (' . ($node['type'] ?? 0) . ')');
$output->comment(' 模块: ' . ($node['module'] ?? ''));
$output->comment(' 需要授权: ' . $authText);
$output->writeln('--------------------------------');
}
$output->info('总计: ' . count($filteredNodes) . ' 个权限节点');
} catch (\Exception $e) {
$output->error('获取权限节点失败: ' . $e->getMessage());
return 1;
}
}
}

View File

@@ -0,0 +1,95 @@
<?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;
}
}