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();
|
||
|
|
}
|
||
|
|
}
|