Adminlog.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 $childrenGroupIds = [];
  18. protected $childrenAdminIds = [];
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = model('AdminLog');
  23. $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
  24. $this->childrenGroupIds = $this->auth->getChildrenGroupIds(true);
  25. $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds)
  26. ->column('id,name');
  27. $this->view->assign('groupdata', $groupName);
  28. }
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags', 'trim']);
  36. if ($this->request->isAjax()) {
  37. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  38. $isSuperAdmin = $this->auth->isSuperAdmin();
  39. $childrenAdminIds = $this->childrenAdminIds;
  40. $list = $this->model
  41. ->where($where)
  42. ->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) {
  43. if (!$isSuperAdmin) {
  44. $query->where('admin_id', 'in', $childrenAdminIds);
  45. }
  46. })
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. $result = array("total" => $list->total(), "rows" => $list->items());
  50. return json($result);
  51. }
  52. return $this->view->fetch();
  53. }
  54. /**
  55. * 详情
  56. */
  57. public function detail($ids)
  58. {
  59. $row = $this->model->get(['id' => $ids]);
  60. if (!$row) {
  61. $this->error(__('No Results were found'));
  62. }
  63. if (!$this->auth->isSuperAdmin()) {
  64. if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
  65. $this->error(__('You have no permission'));
  66. }
  67. }
  68. $this->view->assign("row", $row->toArray());
  69. return $this->view->fetch();
  70. }
  71. /**
  72. * 添加
  73. * @internal
  74. */
  75. public function add()
  76. {
  77. $this->error();
  78. }
  79. /**
  80. * 编辑
  81. * @internal
  82. */
  83. public function edit($ids = null)
  84. {
  85. $this->error();
  86. }
  87. /**
  88. * 删除
  89. */
  90. public function del($ids = "")
  91. {
  92. if (!$this->request->isPost()) {
  93. $this->error(__("Invalid parameters"));
  94. }
  95. $ids = $ids ? $ids : $this->request->post("ids");
  96. if ($ids) {
  97. $isSuperAdmin = $this->auth->isSuperAdmin();
  98. $childrenAdminIds = $this->childrenAdminIds;
  99. $adminList = $this->model->where('id', 'in', $ids)
  100. ->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) {
  101. if (!$isSuperAdmin) {
  102. $query->where('admin_id', 'in', $childrenAdminIds);
  103. }
  104. })
  105. ->select();
  106. if ($adminList) {
  107. $deleteIds = [];
  108. foreach ($adminList as $k => $v) {
  109. $deleteIds[] = $v->id;
  110. }
  111. if ($deleteIds) {
  112. $this->model->destroy($deleteIds);
  113. $this->success();
  114. }
  115. }
  116. }
  117. $this->error();
  118. }
  119. /**
  120. * 批量更新
  121. * @internal
  122. */
  123. public function multi($ids = "")
  124. {
  125. // 管理员禁止批量操作
  126. $this->error();
  127. }
  128. }