UserLogService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\site;
  12. use app\model\sys\SysUserLog;
  13. use core\base\BaseAdminService;
  14. use Exception;
  15. /**
  16. * 操作日志
  17. * Class UserLogService
  18. * @package app\service\admin\site
  19. */
  20. class UserLogService extends BaseAdminService
  21. {
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. $this->model = new SysUserLog();
  26. }
  27. /**
  28. * 获取用户日志
  29. * @param array $where
  30. * @return array
  31. */
  32. public function getPage(array $where)
  33. {
  34. $field = 'id, ip, site_id, uid, username, url, params, type, create_time';
  35. $order = 'create_time desc';
  36. $search_model = $this->model->where([['site_id', '=', $this->site_id]])->withSearch(['username', 'create_time', 'uid', 'ip', 'type', 'url'], $where)->field($field)->order($order);
  37. return $this->pageQuery($search_model);
  38. }
  39. /**
  40. * 日志详情
  41. * @param int $id
  42. * @return array
  43. */
  44. public function getInfo(int $id){
  45. $where = array(
  46. ['id', '=', $id],
  47. ['site_id', '=', $this->site_id]
  48. );
  49. $field = 'id, ip, site_id, uid, username, url, params, type, create_time';
  50. return $this->model->where($where)->field($field)->findOrEmpty()->toArray();
  51. }
  52. /**
  53. * 添加用户(添加用户,不添加站点)
  54. * @param array $data
  55. * @return bool
  56. * @throws Exception
  57. */
  58. public function add(array $data){
  59. $data['site_id'] = $this->site_id;
  60. $res = $this->model->create($data);
  61. return $res->id;
  62. }
  63. }