65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\controller;
|
||
|
|
|
||
|
|
use support\Request;
|
||
|
|
use support\Response;
|
||
|
|
use app\model\FeishuMessageLog;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 调试控制器 - 仅用于开发调试
|
||
|
|
*/
|
||
|
|
class DebugController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* 获取消息日志列表
|
||
|
|
*/
|
||
|
|
public function messageLogs(Request $request): Response
|
||
|
|
{
|
||
|
|
// 仅允许在开发环境访问
|
||
|
|
if (config('app.app_env') !== 'dev' && !$request->get('debug')) {
|
||
|
|
return json(['code' => 403, 'msg' => 'Forbidden']);
|
||
|
|
}
|
||
|
|
|
||
|
|
$limit = (int) $request->get('limit', 50);
|
||
|
|
$orderId = $request->get('order_id');
|
||
|
|
|
||
|
|
$query = FeishuMessageLog::orderBy('created_at', 'desc');
|
||
|
|
|
||
|
|
if ($orderId) {
|
||
|
|
$query->where('order_id', $orderId);
|
||
|
|
}
|
||
|
|
|
||
|
|
$logs = $query->limit($limit)->get()->toArray();
|
||
|
|
|
||
|
|
// 解析 JSON 字段
|
||
|
|
foreach ($logs as &$log) {
|
||
|
|
$log['request_data'] = $log['request_data'] ? json_decode($log['request_data'], true) : null;
|
||
|
|
$log['response_data'] = $log['response_data'] ? json_decode($log['response_data'], true) : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return json([
|
||
|
|
'code' => 0,
|
||
|
|
'msg' => 'success',
|
||
|
|
'data' => $logs,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 清空消息日志
|
||
|
|
*/
|
||
|
|
public function clearLogs(Request $request): Response
|
||
|
|
{
|
||
|
|
if (config('app.app_env') !== 'dev' && !$request->get('debug')) {
|
||
|
|
return json(['code' => 403, 'msg' => 'Forbidden']);
|
||
|
|
}
|
||
|
|
|
||
|
|
FeishuMessageLog::query()->delete();
|
||
|
|
|
||
|
|
return json([
|
||
|
|
'code' => 0,
|
||
|
|
'msg' => 'Logs cleared',
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|