DailyTask.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\ViolationStoreJobs;
  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. $CompanyModel = new CompanyModel();
  41. $company_list = $CompanyModel->select(['id', 'status'])->where('status', 0)->orderByDesc('cleaning_priority')->get()->toarray();
  42. foreach ($company_list as $company) {
  43. $message_data = ['company_id' => $company['id'], 'page' => '1', 'limit' => '50'];
  44. //执行低价挂网商品数据清洗任务
  45. LowPriceGoodsJobs::dispatch($message_data);
  46. //执行违规商品数据清洗任务
  47. ViolationProductJobs::dispatch($message_data);
  48. //执行违规公司数据清洗任务
  49. ViolationCompanyJobs::dispatch($message_data);
  50. //执行违规店铺数据清洗任务
  51. ViolationStoreJobs::dispatch($message_data);
  52. }
  53. // $message_data = ['page' => '1', 'limit' => '50'];
  54. // 执行低价挂网商品数据清洗任务
  55. // LowPriceGoodsJobs::dispatch($message_data);
  56. // 执行违规商品数据清洗任务
  57. // ViolationProductJobs::dispatch($message_data);
  58. // 执行违规公司数据清洗任务
  59. // ViolationCompanyJobs::dispatch($message_data);
  60. // 示例:记录日志
  61. $this->info('每日任务执行完成!');
  62. return Command::SUCCESS;
  63. } catch (\Exception $e) {
  64. Log::error('每日定时任务执行失败: ' . $e->getMessage());
  65. $this->error('任务执行失败: ' . $e->getMessage());
  66. return Command::FAILURE;
  67. }
  68. }
  69. }