Adminlog.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 日志首页
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller\auth;
  15. use app\admin\model\Adminlog as AdminlogModel;
  16. use app\common\controller\Backend;
  17. class Adminlog extends Backend
  18. {
  19. protected $modelClass = null;
  20. protected $childrenAdminIds = [];
  21. protected function initialize()
  22. {
  23. parent::initialize();
  24. $this->modelClass = new AdminlogModel;
  25. $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
  26. }
  27. //删除一个月前的操作日志
  28. public function deletelog()
  29. {
  30. $isAdministrator = $this->auth->isAdministrator();
  31. $childrenAdminIds = $this->childrenAdminIds;
  32. $where = [];
  33. if (!$isAdministrator) {
  34. $where[] = ['admin_id', 'in', $childrenAdminIds];
  35. }
  36. AdminlogModel::where('create_time', '<= time', time() - (86400 * 30))->where($where)->delete();
  37. $this->success("删除日志成功!");
  38. }
  39. /**
  40. * 查看
  41. */
  42. public function index()
  43. {
  44. if ($this->request->isAjax()) {
  45. //如果发送的来源是Selectpage,则转发到Selectpage
  46. if ($this->request->request('keyField')) {
  47. return $this->selectpage();
  48. }
  49. [$page, $limit, $where, $sort, $order] = $this->buildTableParames();
  50. $isAdministrator = $this->auth->isAdministrator();
  51. $childrenAdminIds = $this->childrenAdminIds;
  52. $res = $this->modelClass
  53. ->where($where)
  54. ->where(function ($query) use ($isAdministrator, $childrenAdminIds) {
  55. if (!$isAdministrator) {
  56. $query->where('admin_id', 'in', $childrenAdminIds);
  57. }
  58. })
  59. ->order($sort, $order)
  60. ->paginate($limit);
  61. $result = ["code" => 0, 'count' => $res->total(), 'data' => $res->items()];
  62. return json($result);
  63. }
  64. return $this->fetch();
  65. }
  66. /**
  67. * 详情
  68. */
  69. public function detail($id)
  70. {
  71. $row = $this->modelClass->find($id);
  72. if (!$row) {
  73. $this->error('记录未找到');
  74. }
  75. if (!$this->auth->isAdministrator()) {
  76. if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
  77. $this->error('你没有权限访问');
  78. }
  79. }
  80. $this->assign("row", $row->toArray());
  81. return $this->fetch();
  82. }
  83. //添加
  84. public function add()
  85. {
  86. $this->error();
  87. }
  88. //编辑
  89. public function edit()
  90. {
  91. $this->error();
  92. }
  93. //批量更新
  94. public function multi()
  95. {
  96. // 管理员禁止批量操作
  97. $this->error();
  98. }
  99. }