TestConditionCommand.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Module\Game\Commands;
  3. use App\Module\Game\Services\ConditionService;
  4. use Illuminate\Console\Command;
  5. /**
  6. * 测试条件组功能的命令
  7. */
  8. class TestConditionCommand extends Command
  9. {
  10. /**
  11. * 命令名称
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'game:test-condition {user_id} {condition_group}';
  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. $conditionGroup = $this->argument('condition_group');
  31. $this->info("测试条件组功能");
  32. $this->info("用户ID: {$userId}");
  33. $this->info("条件组: {$conditionGroup}");
  34. // 检查条件
  35. $result = ConditionService::checkCondition($userId, $conditionGroup);
  36. if ($result['success']) {
  37. $this->info("结果: 成功");
  38. $this->info("消息: {$result['message']}");
  39. } else {
  40. $this->error("结果: 失败");
  41. $this->error("消息: {$result['message']}");
  42. }
  43. // 输出详细信息
  44. $this->line('');
  45. $this->line('详细信息:');
  46. unset($result['success']);
  47. unset($result['message']);
  48. foreach ($result as $key => $value) {
  49. if (is_array($value)) {
  50. $this->line("{$key}: " . json_encode($value, JSON_UNESCAPED_UNICODE));
  51. } else {
  52. $this->line("{$key}: {$value}");
  53. }
  54. }
  55. return 0;
  56. }
  57. }