Files
ulthon_admin/extend/base/admin/controller/system/McpLogBase.php
2026-08-16 20:55:03 +08:00

87 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace base\admin\controller\system;
use app\admin\model\SystemMcpKey;
use app\admin\model\SystemMcpLog;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnotation;
use app\common\controller\AdminController;
use think\App;
/**
* MCP调用日志只读列表.
* 日志仅由系统写入,不提供 add/edit/read/modify
* 保留 delete 供清理旧日志。
*
* @ControllerAnnotation(title="MCP调用日志")
*/
class McpLogBase extends AdminController
{
protected $relationSearch = true;
protected $sort = [
'id' => 'desc',
];
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new SystemMcpLog();
// 密钥下拉搜索用SystemMcpKey 软删自动排除
$this->assign('select_list_mcp_key', SystemMcpKey::select(), true);
}
/**
* @NodeAnotation(title="列表")
*/
public function index()
{
if ($this->request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
list($page, $limit, $where) = $this->buildTableParames();
$count = $this->model
->withJoin('mcpKey', 'LEFT')
->where($where)
->count();
$list = $this->model
->withJoin('mcpKey', 'LEFT')
->where($where)
->page($page, $limit)
->order($this->sort)
->select();
$data = [
'code' => 0,
'msg' => '',
'count' => $count,
'data' => $list,
];
return json($data);
}
return $this->fetch();
}
/**
* @NodeAnotation(title="删除")
*/
public function delete($id)
{
$this->checkPostRequest();
$row = $this->model->whereIn('id', $id)->select();
$row->isEmpty() && $this->error('数据不存在');
try {
// 仅删除日志记录,不级联影响密钥表
$save = $row->delete();
} catch (\Exception $e) {
$this->error('删除失败:' . $e->getMessage());
}
$save ? $this->success('删除成功') : $this->error('删除失败');
}
}