LogLists.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\setting\system;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\lists\ListsExcelInterface;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\OperationLog;
  19. /**
  20. * 日志列表
  21. * Class LogLists
  22. * @package app\adminapi\lists\setting\system
  23. */
  24. class LogLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author ljj
  30. * @date 2021/8/3 4:21 下午
  31. */
  32. public function setSearch(): array
  33. {
  34. return [
  35. '%like%' => ['admin_name','url','ip','type'],
  36. 'between_time' => 'create_time',
  37. ];
  38. }
  39. /**
  40. * @notes 查看系统日志列表
  41. * @return array
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\DbException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. * @author ljj
  46. * @date 2021/8/3 4:21 下午
  47. */
  48. public function lists(): array
  49. {
  50. $lists = OperationLog::field('id,action,admin_name,admin_id,url,type,params,ip,create_time')
  51. ->where($this->searchWhere)
  52. ->limit($this->limitOffset, $this->limitLength)
  53. ->order('id','desc')
  54. ->select()
  55. ->toArray();
  56. return $lists;
  57. }
  58. /**
  59. * @notes 查看系统日志总数
  60. * @return int
  61. * @author ljj
  62. * @date 2021/8/3 4:23 下午
  63. */
  64. public function count(): int
  65. {
  66. return OperationLog::where($this->searchWhere)->count();
  67. }
  68. /**
  69. * @notes 设置导出字段
  70. * @return string[]
  71. * @author ljj
  72. * @date 2021/8/3 4:48 下午
  73. */
  74. public function setExcelFields(): array
  75. {
  76. return [
  77. // '数据库字段名(支持别名) => 'Excel表字段名'
  78. 'id' => '记录ID',
  79. 'action' => '操作',
  80. 'admin_name' => '管理员',
  81. 'admin_id' => '管理员ID',
  82. 'url' => '访问链接',
  83. 'type' => '访问方式',
  84. 'params' => '访问参数',
  85. 'ip' => '来源IP',
  86. 'create_time' => '日志时间',
  87. ];
  88. }
  89. /**
  90. * @notes 设置默认表名
  91. * @return string
  92. * @author ljj
  93. * @date 2021/8/3 4:48 下午
  94. */
  95. public function setFileName(): string
  96. {
  97. return '系统日志';
  98. }
  99. }