DailyTask.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Log;
  5. use App\Jobs\Manager\Process\LowPriceGoodsJobs;
  6. use App\Jobs\Manager\Process\ViolationProductJobs;
  7. use App\Jobs\Manager\Process\ViolationStoreJobs;
  8. /**
  9. * 定时清洗采集的商品数据
  10. * @author 唐远望
  11. * @version 1.0
  12. * @date 2025-12-10
  13. */
  14. class DailyTask extends Command
  15. {
  16. /**
  17. * 命令名称和签名
  18. *
  19. * @var string
  20. */
  21. protected $signature = 'task:daily';
  22. /**
  23. * 命令描述
  24. *
  25. * @var string
  26. */
  27. protected $description = '每天12点执行的定时任务';
  28. /**
  29. * 执行命令
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. $this->info('开始执行每日任务...');
  36. try {
  37. Log::info('每日数据清洗任务执行中 - ' . now());
  38. $message_data = ['page' => '1', 'limit' => '50'];
  39. //执行低价挂网商品数据清洗任务
  40. LowPriceGoodsJobs::dispatch($message_data);
  41. //执行违规商品数据清洗任务
  42. ViolationProductJobs::dispatch($message_data);
  43. //执行违规门店数据清洗任务
  44. ViolationStoreJobs::dispatch($message_data);
  45. // 示例:记录日志
  46. $this->info('每日任务执行完成!');
  47. return Command::SUCCESS;
  48. } catch (\Exception $e) {
  49. Log::error('每日定时任务执行失败: ' . $e->getMessage());
  50. $this->error('任务执行失败: ' . $e->getMessage());
  51. return Command::FAILURE;
  52. }
  53. }
  54. }