Log.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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']
  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. $data['list'] = $logLogic->getRecordLogs($this->param);
  45. $data['count'] = $logLogic->getRecordLogCount($this->param);
  46. $data['modules'] = $logLogic->recordModules;
  47. return resultArray(['data' => $data]);
  48. }
  49. /**
  50. * 系统操作日志
  51. *
  52. * @param LogLogic $logLogic
  53. * @return \think\response\Json
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. * @throws \think\exception\DbException
  57. */
  58. public function systemRecord(LogLogic $logLogic)
  59. {
  60. $data['list'] = $logLogic->getSystemLogs($this->param);
  61. $data['count'] = $logLogic->getSystemLogCount($this->param);
  62. $data['modules'] = $logLogic->systemModules;
  63. return resultArray(['data' => $data]);
  64. }
  65. /**
  66. * 登录日志
  67. *
  68. * @param LogLogic $logLogic
  69. * @return \think\response\Json
  70. * @throws \think\exception\DbException
  71. */
  72. public function loginRecord(LogLogic $logLogic)
  73. {
  74. $data = $logLogic->getLoginRecord($this->param);
  75. return resultArray(['data' => $data]);
  76. }
  77. }