VisitProductMiddleware.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\middleware;
  12. use app\common\repositories\user\UserHistoryRepository;
  13. use app\Request;
  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. $type = $this->getArg(0);
  25. if ($this->request->isLogin() && $id) {
  26. $make = app()->make(UserHistoryRepository::class);
  27. $data = [
  28. 'uid' => $this->request->uid(),
  29. 'res_type' => 1,
  30. 'id' => $id,
  31. 'product_type' => $type
  32. ];
  33. $make->createOrUpdate($data);
  34. }
  35. }
  36. }