| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Module\Mex\Services;
- use App\Module\Mex\Logic\MexMatchLogLogic;
- use App\Module\Mex\Enums\MatchType;
- /**
- * 农贸市场撮合日志服务
- *
- * 提供撮合日志相关的对外服务接口
- */
- class MexMatchLogService
- {
- /**
- * 记录撮合日志
- *
- * @param MatchType $matchType 撮合类型
- * @param int $itemId 商品ID
- * @param int $batchSize 批处理大小
- * @param array $result 撮合结果
- * @param int|null $executionTimeMs 执行时间(毫秒)
- * @param string|null $errorMessage 错误消息
- * @return array 日志记录结果
- */
- public static function logMatch(
- MatchType $matchType,
- int $itemId,
- int $batchSize,
- array $result,
- ?int $executionTimeMs = null,
- ?string $errorMessage = null
- ): array {
- try {
- $log = MexMatchLogLogic::logMatch(
- $matchType,
- $itemId,
- $batchSize,
- $result,
- $executionTimeMs,
- $errorMessage
- );
- return [
- 'success' => true,
- 'log_id' => $log->id,
- 'message' => '撮合日志记录成功'
- ];
- } catch (\Exception $e) {
- return [
- 'success' => false,
- 'message' => '撮合日志记录失败:' . $e->getMessage()
- ];
- }
- }
- /**
- * 获取最后撮合时间信息
- *
- * @return array 最后撮合时间信息
- */
- public static function getLastMatchTimes(): array
- {
- return MexMatchLogLogic::getLastMatchTimes();
- }
- /**
- * 获取撮合统计信息
- *
- * @param int $days 统计天数
- * @return array 统计信息
- */
- public static function getMatchStats(int $days = 7): array
- {
- return MexMatchLogLogic::getMatchStats($days);
- }
- /**
- * 获取商品撮合历史
- *
- * @param int $itemId 商品ID
- * @param int $limit 限制数量
- * @return array 撮合历史
- */
- public static function getItemMatchHistory(int $itemId, int $limit = 20): array
- {
- return MexMatchLogLogic::getItemMatchHistory($itemId, $limit);
- }
- }
|