Log.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * @var string
  28. */
  29. public $table = 'SystemLog';
  30. /**
  31. * 日志列表
  32. */
  33. public function index() {
  34. $this->title = '系统操作日志';
  35. $this->assign('actions', Db::name($this->table)->group('action')->column('action'));
  36. $db = Db::name($this->table)->order('id desc');
  37. $get = $this->request->get();
  38. foreach (['action', 'content', 'username'] as $key) {
  39. if (isset($get[$key]) && $get[$key] !== '') {
  40. $db->where($key, 'like', "%{$get[$key]}%");
  41. }
  42. }
  43. return parent::_list($db);
  44. }
  45. /**
  46. * 列表数据处理
  47. * @param $data
  48. */
  49. protected function _index_data_filter(&$data) {
  50. $ip = new \Ip2Region();
  51. foreach ($data as &$vo) {
  52. $result = $ip->btreeSearch($vo['ip']);
  53. $vo['isp'] = isset($result['region']) ? $result['region'] : '';
  54. $vo['isp'] = str_replace(['|0|0|0|0', '|'], ['', ' '], $vo['isp']);
  55. }
  56. }
  57. /**
  58. * 日志删除操作
  59. */
  60. public function del() {
  61. if (DataService::update($this->table)) {
  62. $this->success("日志删除成功!", '');
  63. }
  64. $this->error("日志删除失败,请稍候再试!");
  65. }
  66. }