Log.php 2.4 KB

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