VisitProductMiddleware.php 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-04-15
  7. *
  8. *
  9. */
  10. namespace app\common\middleware;
  11. use app\common\repositories\user\UserVisitRepository;
  12. use app\Request;
  13. use crmeb\services\SwooleTaskService;
  14. use think\Response;
  15. class VisitProductMiddleware extends BaseMiddleware
  16. {
  17. public function before(Request $request)
  18. {
  19. // TODO: Implement before() method.
  20. }
  21. public function after(Response $response)
  22. {
  23. $id = intval($this->request->param('id'));
  24. if ($this->request->isLogin() && $id) {
  25. $uid = $this->request->uid();
  26. if(!app()->make(UserVisitRepository::class)->getWhereCount(['type'=>'product','uid' => $uid,'type_id' => $id])){
  27. SwooleTaskService::visit(intval($uid), $id, 'product');
  28. }
  29. }
  30. }
  31. }