Log.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * 日志控制器
  4. *
  5. * @author qifan
  6. * @date 2020-11-30
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\logic\LogLogic;
  10. use think\Hook;
  11. use think\Request;
  12. class Log extends ApiCommon
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission' => [''],
  24. 'allow' => ['dataRecord', 'systemRecord', 'loginRecord','excelImport']
  25. ];
  26. Hook::listen('check_auth',$action);
  27. $request = Request::instance();
  28. $a = strtolower($request->action());
  29. if (!in_array($a, $action['permission'])) {
  30. parent::_initialize();
  31. }
  32. }
  33. /**
  34. * 数据操作日志
  35. *
  36. * @param LogLogic $logLogic
  37. * @return \think\response\Json
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. public function dataRecord(LogLogic $logLogic)
  43. {
  44. $this->param['startTime']= !empty($this->param['startTime'])?$this->param['startTime'].' 00:00:00':'';
  45. $this->param['endTime']= !empty($this->param['endTime'])?$this->param['endTime'].' 23:59:59':'';
  46. if(!empty($this->param['subModelLabels'])){
  47. $this->param['modules']=$this->param['subModelLabels'];
  48. }else{
  49. switch ($this->param['model']){
  50. case 'crm': //客户管理
  51. $this->param['modules']=array(
  52. 'crm_leads' ,
  53. 'crm_customer',
  54. 'crm_pool' ,
  55. 'crm_contacts' ,
  56. 'crm_product' ,
  57. 'crm_business' ,
  58. 'crm_contract' ,
  59. 'crm_receivables' ,
  60. 'crm_visit' ,
  61. 'crm_invoice' ,
  62. 'crm_activity'
  63. );
  64. break;
  65. case 'oa' : //办公管理
  66. $this->param['modules']=array(
  67. 'oa_log' ,
  68. 'oa_event',
  69. );
  70. break;
  71. case 'work' ://项目管理
  72. $this->param['modules']=array(
  73. 'work_task' ,
  74. 'work',
  75. );
  76. break;
  77. default :
  78. $this->param['modules']=array(
  79. 'crm_leads' ,
  80. 'crm_customer',
  81. 'crm_pool' ,
  82. 'crm_contacts' ,
  83. 'crm_product' ,
  84. 'crm_business' ,
  85. 'crm_contract' ,
  86. 'crm_receivables' ,
  87. 'crm_visit' ,
  88. 'crm_invoice' ,
  89. 'crm_activity',
  90. 'oa_log' ,
  91. 'oa_event',
  92. 'work_task' ,
  93. 'work',
  94. );
  95. break;
  96. }
  97. }
  98. $data['list'] = $logLogic->getRecordLogs($this->param);
  99. $data['count'] = $logLogic->getRecordLogCount($this->param);
  100. $data['modules'] = $logLogic->recordModules;
  101. return resultArray(['data' => $data]);
  102. }
  103. /**
  104. * 系统操作日志
  105. *
  106. * @param LogLogic $logLogic
  107. * @return \think\response\Json
  108. * @throws \think\db\exception\DataNotFoundException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. * @throws \think\exception\DbException
  111. */
  112. public function systemRecord(LogLogic $logLogic)
  113. {
  114. $this->param['startTime']= !empty($this->param['startTime'])?$this->param['startTime'].' 00:00:00':'';
  115. $this->param['endTime']= !empty($this->param['endTime'])?$this->param['endTime'].' 23:59:59':'';
  116. if(!empty($this->param['subModelLabels'])){
  117. $this->param['modules']=$this->param['subModelLabels'];
  118. }
  119. $data['list'] = $logLogic->getSystemLogs($this->param);
  120. $data['count'] = $logLogic->getSystemLogCount($this->param);
  121. $data['modules'] = $logLogic->systemModules;
  122. return resultArray(['data' => $data]);
  123. }
  124. /**
  125. * 登录日志
  126. *
  127. * @param LogLogic $logLogic
  128. * @return \think\response\Json
  129. * @throws \think\exception\DbException
  130. */
  131. public function loginRecord(LogLogic $logLogic)
  132. {
  133. $this->param['startTime']= !empty($this->param['startTime'])?$this->param['startTime'].' 00:00:00':'';
  134. $this->param['endTime']= !empty($this->param['endTime'])?$this->param['endTime'].' 23:59:59':'';
  135. $data = $logLogic->getLoginRecord($this->param);
  136. return resultArray(['data' => $data]);
  137. }
  138. /**
  139. * 日志导出
  140. *
  141. * @param LogLogic $logLogic
  142. * @author alvin guogaobo
  143. * @version 1.0 版本号
  144. * @since 2021/4/8 0008 16:36
  145. */
  146. public function excelImport()
  147. {
  148. $logLogic =new LogLogic;
  149. $data = $logLogic->downExcel($this->param);
  150. return $data;
  151. }
  152. }