Adminlog.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\admin\controller\auth;
  3. use app\admin\model\AuthGroup;
  4. use app\common\controller\Backend;
  5. /**
  6. * 管理员日志
  7. *
  8. * @icon fa fa-users
  9. * @remark 管理员可以查看自己所拥有的权限的管理员日志
  10. */
  11. class Adminlog extends Backend
  12. {
  13. /**
  14. * @var \app\admin\model\AdminLog
  15. */
  16. protected $model = null;
  17. protected $childrenAdminIds = [];
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('AdminLog');
  22. $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
  23. }
  24. /**
  25. * 查看
  26. */
  27. public function index()
  28. {
  29. //设置过滤方法
  30. $this->request->filter(['strip_tags', 'trim']);
  31. if ($this->request->isAjax()) {
  32. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  33. $isSuperAdmin = $this->auth->isSuperAdmin();
  34. $childrenAdminIds = $this->childrenAdminIds;
  35. $list = $this->model
  36. ->where($where)
  37. ->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) {
  38. if (!$isSuperAdmin) {
  39. $query->where('admin_id', 'in', $childrenAdminIds);
  40. }
  41. })
  42. ->field('content,useragent', true)
  43. ->order($sort, $order)
  44. ->paginate($limit);
  45. $result = array("total" => $list->total(), "rows" => $list->items());
  46. return json($result);
  47. }
  48. return $this->view->fetch();
  49. }
  50. /**
  51. * 详情
  52. */
  53. public function detail($ids)
  54. {
  55. $row = $this->model->get(['id' => $ids]);
  56. if (!$row) {
  57. $this->error(__('No Results were found'));
  58. }
  59. if (!$this->auth->isSuperAdmin()) {
  60. if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
  61. $this->error(__('You have no permission'));
  62. }
  63. }
  64. $this->view->assign("row", $row->toArray());
  65. return $this->view->fetch();
  66. }
  67. /**
  68. * 添加
  69. * @internal
  70. */
  71. public function add()
  72. {
  73. $this->error();
  74. }
  75. /**
  76. * 编辑
  77. * @internal
  78. */
  79. public function edit($ids = null)
  80. {
  81. $this->error();
  82. }
  83. /**
  84. * 删除
  85. */
  86. public function del($ids = "")
  87. {
  88. if (!$this->request->isPost()) {
  89. $this->error(__("Invalid parameters"));
  90. }
  91. $ids = $ids ? $ids : $this->request->post("ids");
  92. if ($ids) {
  93. $isSuperAdmin = $this->auth->isSuperAdmin();
  94. $childrenAdminIds = $this->childrenAdminIds;
  95. $adminList = $this->model->where('id', 'in', $ids)
  96. ->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) {
  97. if (!$isSuperAdmin) {
  98. $query->where('admin_id', 'in', $childrenAdminIds);
  99. }
  100. })
  101. ->select();
  102. if ($adminList) {
  103. $deleteIds = [];
  104. foreach ($adminList as $k => $v) {
  105. $deleteIds[] = $v->id;
  106. }
  107. if ($deleteIds) {
  108. $this->model->destroy($deleteIds);
  109. $this->success();
  110. }
  111. }
  112. }
  113. $this->error();
  114. }
  115. /**
  116. * 批量更新
  117. * @internal
  118. */
  119. public function multi($ids = "")
  120. {
  121. // 管理员禁止批量操作
  122. $this->error();
  123. }
  124. }