Oplog.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller;
  15. use think\admin\Controller;
  16. /**
  17. * 系统日志管理
  18. * Class Oplog
  19. * @package app\admin\controller
  20. */
  21. class Oplog extends Controller
  22. {
  23. /**
  24. * 绑定数据表
  25. * @var string
  26. */
  27. public $table = 'SystemOplog';
  28. /**
  29. * 系统日志管理
  30. * @auth true
  31. * @menu true
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function index()
  37. {
  38. $this->title = '系统日志管理';
  39. $query = $this->_query($this->table)->like('action,node,content,username,geoip');
  40. $query->dateBetween('create_at')->order('id desc')->page();
  41. }
  42. /**
  43. * 列表数据处理
  44. * @auth true
  45. * @param array $data
  46. * @throws \Exception
  47. */
  48. protected function _index_page_filter(&$data)
  49. {
  50. $ip = new \Ip2Region();
  51. foreach ($data as &$vo) {
  52. $result = $ip->btreeSearch($vo['geoip']);
  53. $vo['isp'] = isset($result['region']) ? $result['region'] : '';
  54. $vo['isp'] = str_replace(['内网IP', '0', '|'], '', $vo['isp']);
  55. }
  56. }
  57. /**
  58. * 清理系统日志
  59. * @auth true
  60. * @throws \think\db\exception\DbException
  61. */
  62. public function clear()
  63. {
  64. if ($this->app->db->name($this->table)->whereRaw('1=1')->delete() !== false) {
  65. $this->success('日志清理成功!');
  66. } else {
  67. $this->error('日志清理失败,请稍候再试!');
  68. }
  69. }
  70. /**
  71. * 删除系统日志
  72. * @auth true
  73. * @throws \think\db\exception\DbException
  74. */
  75. public function remove()
  76. {
  77. $this->_applyFormToken();
  78. $this->_delete($this->table);
  79. }
  80. }