| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace App\Module\Mex\Commands;
- use App\Module\Mex\Logic\MexMatchLogic;
- use Illuminate\Console\Command;
- /**
- * Mex模块测试命令
- *
- * 用于测试撮合逻辑的基本功能
- */
- class MexTestCommand extends Command
- {
- /**
- * 命令签名
- *
- * @var string
- */
- protected $signature = 'mex:test';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '测试Mex模块撮合逻辑';
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle(): int
- {
- $this->info('=== Mex模块测试开始 ===');
- // 测试1:检查用户买入物品撮合条件
- $this->info('');
- $this->info('1. 测试用户买入物品撮合条件检查');
- $itemId = 1001;
- try {
- $result = MexMatchLogic::checkUserBuyItemMatchConditions($itemId);
- $status = $result['can_match'] ? '可以撮合' : '不能撮合';
- $this->line("没有价格配置: {$status} - {$result['message']}");
- } catch (\Exception $e) {
- $this->error("测试1异常: " . $e->getMessage());
- }
- // 测试2:检查用户卖出物品撮合条件
- $this->info('');
- $this->info('2. 测试用户卖出物品撮合条件检查');
- try {
- $result = MexMatchLogic::checkUserSellItemMatchConditions($itemId);
- $status = $result['can_match'] ? '可以撮合' : '不能撮合';
- $this->line("没有价格配置: {$status} - {$result['message']}");
- } catch (\Exception $e) {
- $this->error("测试2异常: " . $e->getMessage());
- }
- // 测试3:获取统计信息
- $this->info('');
- $this->info('3. 测试统计信息获取');
- try {
- $buyStats = MexMatchLogic::getUserBuyItemMatchStats();
- $this->line('用户买入物品撮合统计:');
- $this->line(" - 待撮合订单数: {$buyStats['pending_orders']}");
- $this->line(" - 涉及商品数: {$buyStats['pending_items']}");
- $this->line(" - 待撮合数量: {$buyStats['pending_quantity']}");
- $this->line(" - 待撮合金额: {$buyStats['pending_amount']}");
- $sellStats = MexMatchLogic::getUserSellItemMatchStats();
- $this->line('用户卖出物品撮合统计:');
- $this->line(" - 待撮合订单数: {$sellStats['pending_orders']}");
- $this->line(" - 涉及商品数: {$sellStats['pending_items']}");
- $this->line(" - 待撮合数量: {$sellStats['pending_quantity']}");
- $this->line(" - 待撮合金额: {$sellStats['pending_amount']}");
- } catch (\Exception $e) {
- $this->error("测试3异常: " . $e->getMessage());
- }
- // 测试4:测试撮合任务执行(试运行)
- $this->info('');
- $this->info('4. 测试撮合任务执行(试运行)');
- try {
- $buyResult = MexMatchLogic::executeUserBuyItemMatch(null, 10);
- $status = $buyResult['success'] ? '成功' : '失败';
- $this->line("用户买入物品撮合任务结果: {$status} - {$buyResult['message']}");
- $this->line(" - 处理商品数: " . count($buyResult['processed_items']));
- $this->line(" - 撮合订单数: {$buyResult['total_matched']}");
- $this->line(" - 成交金额: {$buyResult['total_amount']}");
- $sellResult = MexMatchLogic::executeUserSellItemMatch(null, 10);
- $status = $sellResult['success'] ? '成功' : '失败';
- $this->line("用户卖出物品撮合任务结果: {$status} - {$sellResult['message']}");
- $this->line(" - 处理商品数: " . count($sellResult['processed_items']));
- $this->line(" - 撮合订单数: {$sellResult['total_matched']}");
- $this->line(" - 成交金额: {$sellResult['total_amount']}");
- } catch (\Exception $e) {
- $this->error("测试4异常: " . $e->getMessage());
- }
- // 测试5:测试兼容性方法
- $this->info('');
- $this->info('5. 测试兼容性方法');
- try {
- $oldResult = MexMatchLogic::executeMatch(null, 10);
- $status = $oldResult['success'] ? '成功' : '失败';
- $this->line("旧版撮合任务结果: {$status} - {$oldResult['message']}");
- $oldStats = MexMatchLogic::getMatchStats();
- $this->line("旧版统计信息: 待撮合订单数 {$oldStats['pending_orders']}");
- $oldCondition = MexMatchLogic::checkMatchConditions($itemId);
- $status = $oldCondition['can_match'] ? '可以撮合' : '不能撮合';
- $this->line("旧版条件检查: {$status} - {$oldCondition['message']}");
- } catch (\Exception $e) {
- $this->error("测试5异常: " . $e->getMessage());
- }
- $this->info('');
- $this->info('=== Mex模块测试完成 ===');
- return Command::SUCCESS;
- }
- }
|