Syslog.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if (isset($print) && !empty($print)) {
  37. // $data = $this->Syslog_model->get_list_by_join($where=NULL, $fields='*',$limit=NULL, $offset=NULL, $join = NULL, $order=NULL, $group=NUll, $alias=NULL);
  38. // $data = $this->Syslog_model->get_list_by_join($filter,$page,$count,$field,1);
  39. var_dump('expression');
  40. }else{
  41. $join = array();
  42. $join[] = ['table'=>'user as U','cond'=>'U.id = S.userid','type'=>'left'];
  43. $data = $this->Syslog_model->get_list_by_join($filter, $field,$limit, $offset, $join, 'time DESC,id DESC', NUll, 'S');
  44. // var_dump($this->db->last_query());die;
  45. // $data = $this->Syslog_model->getList($filter,$page,$count,$field);
  46. }
  47. $data = empty($data) ? array() : $data;
  48. $total = $this->Syslog_model->getTotal($filter);
  49. foreach ($data as &$v) {
  50. $v['username'] = empty($v['username']) ? '' : $v['username'];
  51. $v['content'] = empty($v['content']) ? '' : $v['content'];
  52. $v['userid'] = empty($v['userid']) ? '' : $v['userid'];
  53. $v['type'] = empty($v['type']) ? '' : $v['type'];
  54. $v['time'] = empty($v['time']) ? '' : $v['time'];
  55. }
  56. exit(json_result('0000',$this->response['0000'],array('total'=>ceil($total/$count),'list'=>$data)));
  57. }else{
  58. $data = $this->Syslog_model->getList($filter,($page-1)*$count,3000,$field);
  59. $data = empty($data) ? array() : $data;
  60. // 导出到Excel
  61. $version = $this->session->userdata('version');
  62. if (empty($version)) {
  63. $title = array(
  64. array('编号','操作时间','操作类型','操作用户id','操作用户名','操作内容'),
  65. );
  66. }else{
  67. $title = array(
  68. array('Index','Operation time','Operation type','User ID','Username','Behavior'),
  69. );
  70. }
  71. $temp = array();
  72. $i = ($page-1)*$count + 1;
  73. foreach ($data as $k=>$v) {
  74. $temp[$k][] = $i;
  75. $temp[$k][] = $v['time'];
  76. $temp[$k][] = $v['type'];
  77. $temp[$k][] = $v['username'];
  78. $temp[$k][] = $v['realname'];
  79. $temp[$k][] = $v['content'];
  80. $i ++;
  81. }
  82. $data = array_merge($title,$temp);
  83. $path = push_excel($data,'syslogExcel_'.date('Ymd'));
  84. exit(json_result('0000',$this->response['0000'],array('path'=>$path)));
  85. }
  86. }
  87. }
  88. ?>