UserVisitServices.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. declare (strict_types=1);
  12. namespace app\services\user;
  13. use app\services\BaseServices;
  14. use app\dao\user\UserVisitDao;
  15. use think\facade\Log;
  16. /**
  17. *
  18. * Class UserVisitServices
  19. * @package app\services\user
  20. * @mixin UserVisitDao
  21. */
  22. class UserVisitServices extends BaseServices
  23. {
  24. /**
  25. * UserVisitServices constructor.
  26. * @param UserVisitDao $dao
  27. */
  28. public function __construct(UserVisitDao $dao)
  29. {
  30. $this->dao = $dao;
  31. }
  32. /**
  33. * 登录后记录访问记录
  34. * @param array|object $user
  35. * @return mixed
  36. */
  37. public function loginSaveVisit($user)
  38. {
  39. try {
  40. $data = [
  41. 'url' => '/pages/index/index',
  42. 'uid' => $user['uid'] ?? 0,
  43. 'ip' => request()->ip(),
  44. 'add_time' => time(),
  45. 'province' => $user['province'] ?? '',
  46. 'channel_type' => $user['user_type'] ?? 'h5'
  47. ];
  48. if (!$data['uid']) {
  49. return false;
  50. }
  51. return $this->dao->save($data);
  52. } catch (\Throwable $e) {
  53. Log::error('登录记录访问日志错误,错误原因:' . $e->getMessage());
  54. }
  55. }
  56. }