CheckProductPicTasksCommand.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\Anime\AnimeService;
  4. use Illuminate\Console\Command;
  5. class CheckProductPicTasksCommand extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'Anime:checkProductPicTasks';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '检查产品图片生成任务状态并更新产品记录';
  19. protected $animeService;
  20. public function __construct(AnimeService $animeService)
  21. {
  22. parent::__construct();
  23. $this->animeService = $animeService;
  24. }
  25. /**
  26. * Execute the console command.
  27. *
  28. * @return int
  29. */
  30. public function handle()
  31. {
  32. dLog('command')->info('====================开始检查产品图片生成任务状态====================');
  33. $time_start = microtime(true);
  34. $stats = $this->animeService->checkProductPicTasks();
  35. // 兼容:检查任务中心中 saveScriptProducts 类型的任务是否完成,完成则更新状态和结果
  36. $taskCenterUpdated = $this->animeService->checkSaveScriptProductTaskCenters();
  37. $time_end = microtime(true);
  38. $this->info('检查完成: ' . json_encode($stats, JSON_UNESCAPED_UNICODE));
  39. if ($taskCenterUpdated > 0) {
  40. $this->info('任务中心saveScriptProducts任务更新: ' . $taskCenterUpdated . ' 条');
  41. }
  42. dLog('command')->info('产品图片生成任务检查完成', [
  43. 'stats' => $stats,
  44. 'task_center_updated' => $taskCenterUpdated,
  45. 'cost_time' => round($time_end - $time_start, 2)
  46. ]);
  47. dLog('command')->info('====================结束检查产品图片生成任务状态====================');
  48. return 0;
  49. }
  50. }