5bbed98cf0
新增功能: 1. 创建 feishu_message_log 表,记录消息发送和更新操作 2. FeishuMessageLog 模型:管理消息日志 3. DebugController:提供调试接口查看日志 使用方式: - GET /debug/message-logs?limit=50 - 查看最近50条日志 - GET /debug/message-logs?order_id=123 - 查看指定订单的日志 - POST /debug/clear-logs - 清空日志 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.0 KiB
PHP
82 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace app\model;
|
|
|
|
use support\Model;
|
|
|
|
/**
|
|
* 飞书消息日志模型
|
|
*/
|
|
class FeishuMessageLog extends Model
|
|
{
|
|
protected $table = 'feishu_message_log';
|
|
|
|
protected $fillable = [
|
|
'order_id',
|
|
'node_id',
|
|
'user_id',
|
|
'message_id',
|
|
'action',
|
|
'status',
|
|
'request_data',
|
|
'response_data',
|
|
'error_message',
|
|
];
|
|
|
|
const ACTION_SEND = 'send'; // 发送消息
|
|
const ACTION_UPDATE = 'update'; // 更新消息
|
|
const ACTION_UPDATE_CARD = 'update_card'; // 更新卡片
|
|
|
|
const STATUS_SUCCESS = 'success';
|
|
const STATUS_FAILED = 'failed';
|
|
|
|
/**
|
|
* 记录日志
|
|
*/
|
|
public static function log(
|
|
string $action,
|
|
int $orderId,
|
|
?int $nodeId,
|
|
?int $userId,
|
|
?string $messageId,
|
|
string $status,
|
|
?array $requestData = null,
|
|
?array $responseData = null,
|
|
?string $errorMessage = null
|
|
): self {
|
|
return self::create([
|
|
'action' => $action,
|
|
'order_id' => $orderId,
|
|
'node_id' => $nodeId,
|
|
'user_id' => $userId,
|
|
'message_id' => $messageId,
|
|
'status' => $status,
|
|
'request_data' => $requestData ? json_encode($requestData, JSON_UNESCAPED_UNICODE) : null,
|
|
'response_data' => $responseData ? json_encode($responseData, JSON_UNESCAPED_UNICODE) : null,
|
|
'error_message' => $errorMessage,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 获取最近的日志
|
|
*/
|
|
public static function getRecentLogs(int $limit = 50): array
|
|
{
|
|
return self::orderBy('created_at', 'desc')
|
|
->limit($limit)
|
|
->get()
|
|
->toArray();
|
|
}
|
|
|
|
/**
|
|
* 根据订单获取日志
|
|
*/
|
|
public static function getLogsByOrder(int $orderId): array
|
|
{
|
|
return self::where('order_id', $orderId)
|
|
->orderBy('created_at', 'desc')
|
|
->get()
|
|
->toArray();
|
|
}
|
|
}
|