TestConsumeCommand.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Module\Game\Commands;
  3. use App\Module\Game\Services\ConsumeService;
  4. use Illuminate\Console\Command;
  5. /**
  6. * 测试消耗组功能的命令
  7. */
  8. class TestConsumeCommand extends Command
  9. {
  10. /**
  11. * 命令名称
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'game:test-consume {user_id} {consume_group} {--check : 只检查不执行消耗}';
  16. /**
  17. * 命令描述
  18. *
  19. * @var string
  20. */
  21. protected $description = '测试消耗组功能';
  22. /**
  23. * 执行命令
  24. *
  25. * @return int
  26. */
  27. public function handle()
  28. {
  29. $userId = (int) $this->argument('user_id');
  30. $consumeGroup = $this->argument('consume_group');
  31. $checkOnly = $this->option('check');
  32. $this->info("测试消耗组功能");
  33. $this->info("用户ID: {$userId}");
  34. $this->info("消耗组: {$consumeGroup}");
  35. $this->info("模式: " . ($checkOnly ? '只检查' : '检查并执行'));
  36. if ($checkOnly) {
  37. // 只检查不执行
  38. $result = ConsumeService::checkConsume($userId, $consumeGroup);
  39. } else {
  40. // 检查并执行
  41. $result = ConsumeService::executeConsume($userId, $consumeGroup, 'test_command');
  42. }
  43. if ($result['success']) {
  44. $this->info("结果: 成功");
  45. $this->info("消息: {$result['message']}");
  46. } else {
  47. $this->error("结果: 失败");
  48. $this->error("消息: {$result['message']}");
  49. }
  50. // 输出详细信息
  51. $this->line('');
  52. $this->line('详细信息:');
  53. unset($result['success']);
  54. unset($result['message']);
  55. foreach ($result as $key => $value) {
  56. if (is_array($value)) {
  57. $this->line("{$key}: " . json_encode($value, JSON_UNESCAPED_UNICODE));
  58. } else {
  59. $this->line("{$key}: {$value}");
  60. }
  61. }
  62. return 0;
  63. }
  64. }