VisitProductJob.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\jobs;
  12. use app\common\repositories\user\UserHistoryRepository;
  13. use app\common\repositories\user\UserVisitRepository;
  14. use crmeb\interfaces\JobInterface;
  15. use crmeb\services\SwooleTaskService;
  16. use think\Exception;
  17. use think\facade\Log;
  18. use think\queue\Job;
  19. class VisitProductJob implements JobInterface
  20. {
  21. public function fire($job, $data)
  22. {
  23. try{
  24. $spu = app()->make(UserHistoryRepository::class)->createOrUpdate($data);
  25. //if ($spu) {
  26. // $make = app()->make(UserVisitRepository::class);
  27. // $count = $make->search(['uid' => $data['uid'], 'type' => 'product'])->where('type_id', $spu['product_id'])->whereTime('create_time', '>', date('Y-m-d H:i:s', strtotime('- 300 seconds')))->count();
  28. // if (!$count) {
  29. // SwooleTaskService::visit(intval($data['uid']), $spu['product_id'], 'product');
  30. // }
  31. //}
  32. }catch (\Exception $e){
  33. }
  34. $job->delete();
  35. }
  36. public function failed($data)
  37. {
  38. // TODO: Implement failed() method.
  39. }
  40. }