Logs.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\admin\library\Log;
  4. use app\admin\model\User;
  5. use app\common\controller\Backend;
  6. /**
  7. * 日志管理
  8. *
  9. * @icon fa fa-user
  10. */
  11. class Logs extends Backend
  12. {
  13. protected $log = null;
  14. public function _initialize()
  15. {
  16. $this->log = new Log();
  17. parent::_initialize();
  18. }
  19. public function index()
  20. {
  21. if (false === $this->log->isAllow()) {
  22. die($this->log->getError());
  23. }
  24. $directory = $this->log->getDirectory();
  25. if ($this->request->isAjax()) {
  26. $filePaths = isset($_GET['file_paths']) ? $_GET['file_paths'] : [];
  27. if (mb_strpos($filePaths, '_cli.log') !== false) {
  28. $path = $this->log->complementLogPath($filePaths);
  29. if (false === $path) {
  30. $this->error(404);
  31. }
  32. $content = file_get_contents($path);
  33. $this->success('', '', $content);
  34. }
  35. $whereFilter = request()->param('filter');
  36. $whereFilter = $whereFilter ? json_decode($whereFilter, true) : [];
  37. $rows = $this->log->getLogs($filePaths, $whereFilter);
  38. $info = $this->log->getInfo($filePaths);
  39. if (false === $rows) {
  40. $this->error('获取失败');
  41. }
  42. return json(['rows' => $rows, 'info' => $info]);
  43. }
  44. $this->assign(compact('directory'));
  45. return $this->fetch();
  46. }
  47. public function del($ids = "")
  48. {
  49. $filePaths = input('file_paths');
  50. if ($ids && $filePaths) {
  51. $rows = $this->log->deleteForId($filePaths, explode(',', $ids));
  52. $this->success('', '', $rows);
  53. }
  54. $this->error(__('Parameter %s can not be empty', 'ids'));
  55. }
  56. }