Syslog.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/controllers/Base_Controller.php');
  3. class Syslog extends Base_Controller {
  4. public function __construct() {
  5. parent::__construct();
  6. $this->load->model('Syslog_model');
  7. }
  8. // 获取用户日志列表
  9. public function get_list(){
  10. $keyword = $this->input->post('keyword',true);
  11. $type = $this->input->post('type',true);
  12. $page = $this->input->post('page',true);
  13. $count = $this->input->post('count',true);
  14. $language = $this->session->userdata('version');
  15. $role = $this->get_user_info('role');
  16. $print = $this->input->post('print',true);
  17. $filter = array();
  18. if (!empty($keyword)) $filter['S.content|U.username|U.name|S.time'] = $keyword;
  19. if (!empty($type)) $filter['S.optype'] = $type;
  20. $filter['language'] = empty($language) ? 0 : 1;
  21. $download = $this->input->post('download',true);
  22. if ($role != SYSTEM_ADMIN) $filter['U.company'] = $this->get_user_info('company');
  23. $page = !isset($page) ? 1 : $page;
  24. $count = empty($count) ? 20 : $count;
  25. $limit = $count;
  26. $offset = ($page - 1) * $count;
  27. $field = "S.id,
  28. S.time,
  29. S.optype as type,
  30. S.userid,
  31. U.username,
  32. U.name as realname,
  33. S.content,
  34. S.is_read";
  35. if (empty($download)) {
  36. $join = array();
  37. $join[] = ['table'=>'user as U','cond'=>'U.id = S.userid','type'=>'left'];
  38. if (isset($print) && !empty($print)) {
  39. $data = $this->Syslog_model->get_list_by_join($filter, $field,3000, 0, $join, 'S.time DESC,S.id DESC', NUll, 'S');
  40. }else{
  41. $data = $this->Syslog_model->get_list_by_join($filter, $field,$limit, $offset, $join, 'S.time DESC,S.id DESC', NUll, 'S');
  42. }
  43. $total = $this->Syslog_model->get_list_by_multi_join($filter, 'count(*) as total',null, null, $join, null, NUll, 'S',true);
  44. $data = empty($data) ? array() : $data;
  45. $total = $total['total'];
  46. foreach ($data as &$v) {
  47. $v['username'] = empty($v['username']) ? '' : $v['username'];
  48. $v['content'] = empty($v['content']) ? '' : $v['content'];
  49. $v['userid'] = empty($v['userid']) ? '' : $v['userid'];
  50. $v['type'] = empty($v['type']) ? '' : $v['type'];
  51. $v['time'] = empty($v['time']) ? '' : $v['time'];
  52. }
  53. exit(json_result('0000',$this->response['0000'],array('total'=>ceil($total/$count),'list'=>$data)));
  54. }else{
  55. $data = $this->Syslog_model->getList($filter,($page-1)*$count,3000,$field);
  56. $data = empty($data) ? array() : $data;
  57. // 导出到Excel
  58. $version = $this->session->userdata('version');
  59. if (empty($version)) {
  60. $title = array(
  61. array('编号','操作时间','操作类型','操作用户id','操作用户名','操作内容'),
  62. );
  63. }else{
  64. $title = array(
  65. array('Index','Operation time','Operation type','User ID','Username','Behavior'),
  66. );
  67. }
  68. $temp = array();
  69. $i = ($page-1)*$count + 1;
  70. foreach ($data as $k=>$v) {
  71. $temp[$k][] = $i;
  72. $temp[$k][] = $v['time'];
  73. $temp[$k][] = $v['type'];
  74. $temp[$k][] = $v['username'];
  75. $temp[$k][] = $v['realname'];
  76. $temp[$k][] = $v['content'];
  77. $i ++;
  78. }
  79. $data = array_merge($title,$temp);
  80. $path = push_excel($data,'syslogExcel_'.date('Ymd'));
  81. exit(json_result('0000',$this->response['0000'],array('path'=>$path)));
  82. }
  83. }
  84. }
  85. ?>