Log.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Think.Admin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/Think.Admin
  12. // +----------------------------------------------------------------------
  13. namespace app\admin\controller;
  14. use controller\BasicAdmin;
  15. use service\DataService;
  16. use think\Db;
  17. /**
  18. * 系统日志管理
  19. * Class User
  20. * @package app\admin\controller
  21. * @author Anyon <zoujingli@qq.com>
  22. * @date 2017/02/15 18:12
  23. */
  24. class Log extends BasicAdmin
  25. {
  26. /**
  27. * 指定当前数据表
  28. * @var string
  29. */
  30. public $table = 'SystemLog';
  31. /**
  32. * 日志列表
  33. * @return array|string
  34. */
  35. public function index()
  36. {
  37. $this->title = '系统操作日志';
  38. $get = $this->request->get();
  39. // 日志行为类别
  40. $actions = Db::name($this->table)->group('action')->column('action');
  41. $this->assign('actions', $actions);
  42. // 日志数据库对象
  43. $db = Db::name($this->table)->order('id desc');
  44. foreach (['action', 'content', 'username'] as $key) {
  45. if (isset($get[$key]) && $get[$key] !== '') {
  46. $db->where($key, 'like', "%{$get[$key]}%");
  47. }
  48. }
  49. return parent::_list($db);
  50. }
  51. /**
  52. * 列表数据处理
  53. * @param array $data
  54. */
  55. protected function _index_data_filter(&$data)
  56. {
  57. $ip = new \Ip2Region();
  58. foreach ($data as &$vo) {
  59. $result = $ip->btreeSearch($vo['ip']);
  60. $vo['isp'] = isset($result['region']) ? $result['region'] : '';
  61. $vo['isp'] = str_replace(['|0|0|0|0', '0', '|'], ['', '', ' '], $vo['isp']);
  62. }
  63. }
  64. /**
  65. * 日志删除操作
  66. */
  67. public function del()
  68. {
  69. if (DataService::update($this->table)) {
  70. $this->success("日志删除成功!", '');
  71. }
  72. $this->error("日志删除失败, 请稍候再试!");
  73. }
  74. }