ProductSurveillance.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Log;
  5. use App\Jobs\Manager\CollectData\Statistics\ProductSurveillanceJobs;
  6. use App\Models\Manager\External\Company as CompanyModel;
  7. class ProductSurveillance extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'task:product_surveillance_notice';
  15. /**
  16. * 命令描述
  17. *
  18. * @var string
  19. */
  20. protected $description = '每小时执行一次商品数据-监控采集清洗情况通知任务';
  21. /**
  22. * 执行命令
  23. *
  24. * @return int
  25. */
  26. public function handle()
  27. {
  28. try {
  29. Log::info('开始执行商品数据-监控采集清洗情况通知任务 - ' . now());
  30. $start_time = time() - 60 * 60; // 1小时前开始时间
  31. $end_time = time(); // 当前时间
  32. $CompanyModel = new CompanyModel();
  33. $company_list = $CompanyModel->select(['id', 'status'])->where('status', 0)->orderByDesc('cleaning_priority')->get()->toarray();
  34. foreach ($company_list as $company) {
  35. $message_data = ['company_id' => $company['id'], 'start_time' => $start_time, 'end_time' => $end_time];
  36. //执行低价挂网商品数据清洗任务
  37. ProductSurveillanceJobs::dispatch($message_data);
  38. }
  39. Log::info('商品数据-监控采集清洗情况通知执行完成!' . now());
  40. return Command::SUCCESS;
  41. } catch (\Exception $e) {
  42. Log::error('商品数据-监控采集清洗情况通知任务执行失败: ' . $e->getMessage());
  43. return Command::FAILURE;
  44. }
  45. }
  46. }