MexTestCommand.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace App\Module\Mex\Commands;
  3. use App\Module\Mex\Logic\MexMatchLogic;
  4. use Illuminate\Console\Command;
  5. /**
  6. * Mex模块测试命令
  7. *
  8. * 用于测试撮合逻辑的基本功能
  9. */
  10. class MexTestCommand extends Command
  11. {
  12. /**
  13. * 命令签名
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'mex:test';
  18. /**
  19. * 命令描述
  20. *
  21. * @var string
  22. */
  23. protected $description = '测试Mex模块撮合逻辑';
  24. /**
  25. * 执行命令
  26. *
  27. * @return int
  28. */
  29. public function handle(): int
  30. {
  31. $this->info('=== Mex模块测试开始 ===');
  32. // 测试1:检查用户买入物品撮合条件
  33. $this->info('');
  34. $this->info('1. 测试用户买入物品撮合条件检查');
  35. $itemId = 1001;
  36. try {
  37. $result = MexMatchLogic::checkUserBuyItemMatchConditions($itemId);
  38. $status = $result['can_match'] ? '可以撮合' : '不能撮合';
  39. $this->line("没有价格配置: {$status} - {$result['message']}");
  40. } catch (\Exception $e) {
  41. $this->error("测试1异常: " . $e->getMessage());
  42. }
  43. // 测试2:检查用户卖出物品撮合条件
  44. $this->info('');
  45. $this->info('2. 测试用户卖出物品撮合条件检查');
  46. try {
  47. $result = MexMatchLogic::checkUserSellItemMatchConditions($itemId);
  48. $status = $result['can_match'] ? '可以撮合' : '不能撮合';
  49. $this->line("没有价格配置: {$status} - {$result['message']}");
  50. } catch (\Exception $e) {
  51. $this->error("测试2异常: " . $e->getMessage());
  52. }
  53. // 测试3:获取统计信息
  54. $this->info('');
  55. $this->info('3. 测试统计信息获取');
  56. try {
  57. $buyStats = MexMatchLogic::getUserBuyItemMatchStats();
  58. $this->line('用户买入物品撮合统计:');
  59. $this->line(" - 待撮合订单数: {$buyStats['pending_orders']}");
  60. $this->line(" - 涉及商品数: {$buyStats['pending_items']}");
  61. $this->line(" - 待撮合数量: {$buyStats['pending_quantity']}");
  62. $this->line(" - 待撮合金额: {$buyStats['pending_amount']}");
  63. $sellStats = MexMatchLogic::getUserSellItemMatchStats();
  64. $this->line('用户卖出物品撮合统计:');
  65. $this->line(" - 待撮合订单数: {$sellStats['pending_orders']}");
  66. $this->line(" - 涉及商品数: {$sellStats['pending_items']}");
  67. $this->line(" - 待撮合数量: {$sellStats['pending_quantity']}");
  68. $this->line(" - 待撮合金额: {$sellStats['pending_amount']}");
  69. } catch (\Exception $e) {
  70. $this->error("测试3异常: " . $e->getMessage());
  71. }
  72. // 测试4:测试撮合任务执行(试运行)
  73. $this->info('');
  74. $this->info('4. 测试撮合任务执行(试运行)');
  75. try {
  76. $buyResult = MexMatchLogic::executeUserBuyItemMatch(null, 10);
  77. $status = $buyResult['success'] ? '成功' : '失败';
  78. $this->line("用户买入物品撮合任务结果: {$status} - {$buyResult['message']}");
  79. $this->line(" - 处理商品数: " . count($buyResult['processed_items']));
  80. $this->line(" - 撮合订单数: {$buyResult['total_matched']}");
  81. $this->line(" - 成交金额: {$buyResult['total_amount']}");
  82. $sellResult = MexMatchLogic::executeUserSellItemMatch(null, 10);
  83. $status = $sellResult['success'] ? '成功' : '失败';
  84. $this->line("用户卖出物品撮合任务结果: {$status} - {$sellResult['message']}");
  85. $this->line(" - 处理商品数: " . count($sellResult['processed_items']));
  86. $this->line(" - 撮合订单数: {$sellResult['total_matched']}");
  87. $this->line(" - 成交金额: {$sellResult['total_amount']}");
  88. } catch (\Exception $e) {
  89. $this->error("测试4异常: " . $e->getMessage());
  90. }
  91. // 测试5:测试兼容性方法
  92. $this->info('');
  93. $this->info('5. 测试兼容性方法');
  94. try {
  95. $oldResult = MexMatchLogic::executeMatch(null, 10);
  96. $status = $oldResult['success'] ? '成功' : '失败';
  97. $this->line("旧版撮合任务结果: {$status} - {$oldResult['message']}");
  98. $oldStats = MexMatchLogic::getMatchStats();
  99. $this->line("旧版统计信息: 待撮合订单数 {$oldStats['pending_orders']}");
  100. $oldCondition = MexMatchLogic::checkMatchConditions($itemId);
  101. $status = $oldCondition['can_match'] ? '可以撮合' : '不能撮合';
  102. $this->line("旧版条件检查: {$status} - {$oldCondition['message']}");
  103. } catch (\Exception $e) {
  104. $this->error("测试5异常: " . $e->getMessage());
  105. }
  106. $this->info('');
  107. $this->info('=== Mex模块测试完成 ===');
  108. return Command::SUCCESS;
  109. }
  110. }