| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /**
- * Mex模块撮合日志测试
- *
- * 测试撮合命令是否正确记录日志,包括没有待撮合订单的情况
- */
- require_once __DIR__ . '/../../../../vendor/autoload.php';
- use App\Module\Mex\Logic\MexMatchLogic;
- use App\Module\Mex\Models\MexMatchLog;
- use App\Module\Mex\Enums\MatchType;
- echo "=== Mex模块撮合日志测试 ===\n\n";
- // 记录测试开始前的日志数量
- $initialLogCount = MexMatchLog::count();
- echo "测试开始前日志总数: {$initialLogCount}\n\n";
- // 测试1:用户买入物品撮合(可能没有待撮合订单)
- echo "1. 测试用户买入物品撮合日志记录\n";
- try {
- $buyResult = MexMatchLogic::executeUserBuyItemMatch(null, 10);
- echo "用户买入物品撮合结果: " . ($buyResult['success'] ? '成功' : '失败') . " - " . $buyResult['message'] . "\n";
- echo " - 处理商品数: " . count($buyResult['processed_items']) . "\n";
- echo " - 撮合订单数: {$buyResult['total_matched']}\n";
- echo " - 成交金额: {$buyResult['total_amount']}\n";
-
- // 检查是否产生了新的日志
- $newBuyLogCount = MexMatchLog::where('match_type', MatchType::USER_BUY)
- ->where('created_at', '>=', now()->subMinutes(1))
- ->count();
- echo " - 新增买入撮合日志数: {$newBuyLogCount}\n";
-
- if ($newBuyLogCount > 0) {
- $latestBuyLog = MexMatchLog::where('match_type', MatchType::USER_BUY)
- ->orderBy('created_at', 'desc')
- ->first();
- echo " - 最新日志: item_id={$latestBuyLog->item_id}, message='{$latestBuyLog->message}'\n";
- }
-
- } catch (\Exception $e) {
- echo "用户买入物品撮合测试失败: " . $e->getMessage() . "\n";
- }
- echo "\n";
- // 测试2:用户卖出物品撮合(可能没有待撮合订单)
- echo "2. 测试用户卖出物品撮合日志记录\n";
- try {
- $sellResult = MexMatchLogic::executeUserSellItemMatch(null, 10);
- echo "用户卖出物品撮合结果: " . ($sellResult['success'] ? '成功' : '失败') . " - " . $sellResult['message'] . "\n";
- echo " - 处理商品数: " . count($sellResult['processed_items']) . "\n";
- echo " - 撮合订单数: {$sellResult['total_matched']}\n";
- echo " - 成交金额: {$sellResult['total_amount']}\n";
-
- // 检查是否产生了新的日志
- $newSellLogCount = MexMatchLog::where('match_type', MatchType::USER_SELL)
- ->where('created_at', '>=', now()->subMinutes(1))
- ->count();
- echo " - 新增卖出撮合日志数: {$newSellLogCount}\n";
-
- if ($newSellLogCount > 0) {
- $latestSellLog = MexMatchLog::where('match_type', MatchType::USER_SELL)
- ->orderBy('created_at', 'desc')
- ->first();
- echo " - 最新日志: item_id={$latestSellLog->item_id}, message='{$latestSellLog->message}'\n";
- }
-
- } catch (\Exception $e) {
- echo "用户卖出物品撮合测试失败: " . $e->getMessage() . "\n";
- }
- echo "\n";
- // 测试3:指定商品撮合(测试单个商品的日志记录)
- echo "3. 测试指定商品撮合日志记录\n";
- $testItemId = 1001; // 使用一个不存在的商品ID来测试条件检查失败的情况
- try {
- $itemBuyResult = MexMatchLogic::executeUserBuyItemMatch($testItemId, 5);
- echo "指定商品买入撮合结果: " . ($itemBuyResult['success'] ? '成功' : '失败') . " - " . $itemBuyResult['message'] . "\n";
-
- // 检查是否为该商品产生了日志
- $itemLogCount = MexMatchLog::where('match_type', MatchType::USER_BUY)
- ->where('item_id', $testItemId)
- ->where('created_at', '>=', now()->subMinutes(1))
- ->count();
- echo " - 商品 {$testItemId} 的买入撮合日志数: {$itemLogCount}\n";
-
- } catch (\Exception $e) {
- echo "指定商品撮合测试失败: " . $e->getMessage() . "\n";
- }
- echo "\n";
- // 记录测试结束后的日志数量
- $finalLogCount = MexMatchLog::count();
- $addedLogs = $finalLogCount - $initialLogCount;
- echo "测试结束后日志总数: {$finalLogCount}\n";
- echo "本次测试新增日志数: {$addedLogs}\n\n";
- // 显示最近的几条日志
- echo "=== 最近的撮合日志 ===\n";
- $recentLogs = MexMatchLog::orderBy('created_at', 'desc')->limit(5)->get();
- foreach ($recentLogs as $log) {
- echo "ID: {$log->id}, 类型: {$log->match_type->value}, 商品: {$log->item_id}, ";
- echo "成功: " . ($log->success ? '是' : '否') . ", 消息: {$log->message}\n";
- }
- echo "\n=== 撮合日志测试完成 ===\n";
|