DailyTask.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\ViolationCompanyJobs;
  8. use App\Models\Manager\External\Company as CompanyModel;
  9. use App\Jobs\Manager\Process\ScrapeDataProductJobs;
  10. /**
  11. * 定时清洗采集的商品数据
  12. * @author 唐远望
  13. * @version 1.0
  14. * @date 2025-12-10
  15. */
  16. class DailyTask extends Command
  17. {
  18. /**
  19. * 命令名称和签名
  20. *
  21. * @var string
  22. */
  23. protected $signature = 'task:daily';
  24. /**
  25. * 命令描述
  26. *
  27. * @var string
  28. */
  29. protected $description = '每天12点执行的定时任务';
  30. /**
  31. * 执行命令
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. $this->info('开始执行每日任务...');
  38. try {
  39. Log::info('每日数据清洗任务执行中 - ' . now());
  40. $start_time = time() - 60 * 5; // 开始时间 5分钟之前
  41. $end_time = time(); //结束时间
  42. $CompanyModel = new CompanyModel();
  43. $company_list = $CompanyModel->select(['id', 'status'])->where('status', 0)->orderByDesc('cleaning_priority')->get()->toarray();
  44. foreach ($company_list as $company) {
  45. $message_data = ['company_id' => $company['id'], 'page' => '1', 'limit' => '10000', 'start_time' => $start_time, 'end_time' => $end_time];
  46. //执行低价挂网商品数据清洗任务
  47. ScrapeDataProductJobs::dispatch($message_data);
  48. }
  49. $this->info('每日任务执行完成!');
  50. return Command::SUCCESS;
  51. } catch (\Exception $e) {
  52. Log::error('每日定时任务执行失败: ' . $e->getMessage());
  53. $this->error('任务执行失败: ' . $e->getMessage());
  54. return Command::FAILURE;
  55. }
  56. }
  57. }