DailyTask.php 2.0 KB

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