TestTaskTempCommand.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Module\Task\Commands;
  3. use App\Module\Game\Services\TaskTempService;
  4. use Illuminate\Console\Command;
  5. /**
  6. * 测试任务暂存功能命令
  7. */
  8. class TestTaskTempCommand extends Command
  9. {
  10. /**
  11. * 命令签名
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'task:test-temp {user_id : 用户ID} {--clear : 清理暂存数据}';
  16. /**
  17. * 命令描述
  18. *
  19. * @var string
  20. */
  21. protected $description = '测试任务暂存功能';
  22. /**
  23. * 执行命令
  24. *
  25. * @return int
  26. */
  27. public function handle(): int
  28. {
  29. $userId = (int) $this->argument('user_id');
  30. $clear = $this->option('clear');
  31. $this->info("测试用户 {$userId} 的任务暂存功能");
  32. if ($clear) {
  33. // 清理暂存数据
  34. $result = TaskTempService::clearUserTaskChanges($userId);
  35. if ($result) {
  36. $this->info('✓ 暂存数据已清理');
  37. } else {
  38. $this->error('✗ 暂存数据清理失败');
  39. }
  40. return 0;
  41. }
  42. // 检查是否有暂存数据
  43. $hasChanges = TaskTempService::hasUserTaskChanges($userId);
  44. $this->info("是否有暂存数据: " . ($hasChanges ? '是' : '否'));
  45. if (!$hasChanges) {
  46. $this->warn('用户没有任务暂存数据');
  47. return 0;
  48. }
  49. // 获取统计信息
  50. $stats = TaskTempService::getUserTaskChangeStats($userId);
  51. $this->info('=== 暂存数据统计 ===');
  52. $this->info("总变更数: {$stats['total_changes']}");
  53. $this->info("进度更新: {$stats['progress_updates']}");
  54. $this->info("完成任务: {$stats['completed_tasks']}");
  55. $this->info("奖励领取: {$stats['reward_claims']}");
  56. if ($stats['latest_update']) {
  57. $this->info("最新更新: " . date('Y-m-d H:i:s', $stats['latest_update']));
  58. }
  59. // 获取所有暂存数据
  60. $changes = TaskTempService::getUserTaskChanges($userId);
  61. $this->info("\n=== 暂存数据详情 ===");
  62. foreach ($changes as $change) {
  63. $this->info("任务ID: {$change->taskId}");
  64. $this->info("任务名称: {$change->taskName}");
  65. $this->info("变更类型: {$change->getChangeTypeDescription()}");
  66. $this->info("任务状态: {$change->getStatusDescription()}");
  67. if ($change->isProgressUpdate()) {
  68. $this->info("进度: {$change->getFormattedProgress()}");
  69. if ($change->progressDetails) {
  70. $this->info("进度详情: " . json_encode($change->progressDetails, JSON_UNESCAPED_UNICODE));
  71. }
  72. }
  73. if ($change->isRewardClaimed()) {
  74. $this->info("奖励数量: {$change->getRewardCount()}");
  75. }
  76. $this->info("更新时间: " . date('Y-m-d H:i:s', $change->updatedAt));
  77. $this->info("---");
  78. }
  79. // 获取最近的变更
  80. $recentChanges = TaskTempService::getUserRecentTaskChanges($userId, 3);
  81. $this->info("\n=== 最近3次变更 ===");
  82. foreach ($recentChanges as $index => $change) {
  83. $this->info(($index + 1) . ". 任务: {$change->taskName} - {$change->getChangeTypeDescription()} - " . date('H:i:s', $change->updatedAt));
  84. }
  85. return 0;
  86. }
  87. }