UserAccessLog.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\index\model\user;
  13. use app\common\model\user\UserAccessLog as UserAccessLogModel;
  14. use think\db\Where;
  15. /**
  16. * 系统设置模型
  17. * Class Setting
  18. * @package app\api\model
  19. */
  20. class UserAccessLog extends UserAccessLogModel
  21. {
  22. /**
  23. * 页面:vapePoints,index,login
  24. * 接口:register,sendEmailCaptcha
  25. **/
  26. /**
  27. * 获取积分名称
  28. * @return bool
  29. */
  30. public static function doSave($data)
  31. {
  32. if (empty($data)) return false;
  33. return static::insert($data);
  34. }
  35. public static function getAccessLog($path, $from, $to, $page = 1, $size = 50)
  36. {
  37. $m = self::where('create_time', '>=', $from)->where('create_time', '<=', $to);
  38. if (!empty($path)) {
  39. $m = $m->where('path', $path);
  40. }
  41. $count = $m->count();
  42. $items = $m->page($page, $size)->select();
  43. return ['count' => $count, 'item' => $items];
  44. }
  45. public static function getAccessLogPathes($from, $to)
  46. {
  47. $path = ['vapePoints', 'index', 'login', 'register', 'sendEmailCaptcha'];
  48. $res = [];
  49. foreach ($path as $item) {
  50. $res[$item] = self::where('create_time', '>=', $from)->where('create_time', '<=', $to)->where('path', $item)->count('distinct ip');
  51. }
  52. return $res;
  53. }
  54. public static function getAccessLogDistinctIps($from, $to)
  55. {
  56. $res[$item] = self::where('create_time', '>=', $from)->where('create_time', '<=', $to)->count('distinct ip');
  57. return $res;
  58. }
  59. }