Syslog.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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['keyword'] = $keyword;
  19. if (!empty($type)) $filter['optype'] = $type;
  20. $filter['language'] = empty($language) ? 0 : 1;
  21. $download = $this->input->post('download',true);
  22. if ($role == COMPANY_ADMIN) {
  23. $filter['companyid'] = $this->get_user_info('companyid');
  24. }elseif ($role == COMPANY_CUSTOMER) {
  25. $filter['userid'] = $this->get_user_info('id');
  26. }
  27. $page = !isset($page) ? 1 : $page;
  28. $count = empty($count) ? 20 : $count;
  29. $field = "S.id,
  30. S.time,
  31. S.optype as type,
  32. S.userid,
  33. U.username,
  34. S.content,
  35. S.is_read";
  36. if (empty($download)) {
  37. if (isset($print) && !empty($print)) {
  38. $data = $this->Syslog_model->getList($filter,$page,$count,$field,1);
  39. }else{
  40. $data = $this->Syslog_model->getList($filter,$page,$count,$field);
  41. }
  42. $data = empty($data) ? array() : $data;
  43. $total = $this->Syslog_model->getTotal($filter);
  44. foreach ($data as &$v) {
  45. $v['username'] = empty($v['username']) ? '' : $v['username'];
  46. $v['content'] = empty($v['content']) ? '' : $v['content'];
  47. $v['userid'] = empty($v['userid']) ? '' : $v['userid'];
  48. $v['type'] = empty($v['type']) ? '' : $v['type'];
  49. $v['time'] = empty($v['time']) ? '' : $v['time'];
  50. }
  51. exit(json_result('0000',$this->response['0000'],array('total'=>ceil($total/$count),'list'=>$data)));
  52. }else{
  53. $data = $this->Syslog_model->getList($filter,($page-1)*$count,3000,$field);
  54. $data = empty($data) ? array() : $data;
  55. // 导出到Excel
  56. $version = $this->session->userdata('version');
  57. if (empty($version)) {
  58. $title = array(
  59. array('编号','操作时间','操作类型','操作用户id','操作用户名','操作内容'),
  60. );
  61. }else{
  62. $title = array(
  63. array('Index','Operation time','Operation type','User ID','Username','Behavior'),
  64. );
  65. }
  66. $temp = array();
  67. $i = ($page-1)*$count + 1;
  68. foreach ($data as $k=>$v) {
  69. $temp[$k][] = $i;
  70. $temp[$k][] = $v['time'];
  71. $temp[$k][] = $v['type'];
  72. $temp[$k][] = $v['username'];
  73. $temp[$k][] = $v['realname'];
  74. $temp[$k][] = $v['content'];
  75. $i ++;
  76. }
  77. $data = array_merge($title,$temp);
  78. $path = push_excel($data,'syslogExcel_'.date('Ymd'));
  79. exit(json_result('0000',$this->response['0000'],array('path'=>$path)));
  80. }
  81. }
  82. }
  83. ?>