SyncHotRankingListen.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\listens;
  12. use crmeb\interfaces\ListenerInterface;
  13. use crmeb\jobs\SyncProductTopJob;
  14. use crmeb\services\TimerService;
  15. use think\facade\Log;
  16. use think\facade\Queue;
  17. class SyncHotRankingListen extends TimerService implements ListenerInterface
  18. {
  19. public function handle($event): void
  20. {
  21. $hot = systemConfig('hot_ranking_switch');
  22. if (!$hot) return ;
  23. $time = systemConfig('hot_ranking_time');
  24. $time = ($time && $time > 1) ?: 1 ;
  25. $this->tick(1000 * 60 * 60 * $time, function () {
  26. request()->clearCache();
  27. try{
  28. Queue::push(SyncProductTopJob::class, []);
  29. }catch (\Exception $e) {
  30. Log::info('热卖排行错误:'.var_export([$e->getMessage()],1));
  31. }
  32. });
  33. }
  34. }