Adminlog.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. ->field('content,useragent', true)
  48. ->order($sort, $order)
  49. ->paginate($limit);
  50. $result = array("total" => $list->total(), "rows" => $list->items());
  51. return json($result);
  52. }
  53. return $this->view->fetch();
  54. }
  55. /**
  56. * 详情
  57. */
  58. public function detail($ids)
  59. {
  60. $row = $this->model->get(['id' => $ids]);
  61. if (!$row) {
  62. $this->error(__('No Results were found'));
  63. }
  64. if (!$this->auth->isSuperAdmin()) {
  65. if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
  66. $this->error(__('You have no permission'));
  67. }
  68. }
  69. $this->view->assign("row", $row->toArray());
  70. return $this->view->fetch();
  71. }
  72. /**
  73. * 添加
  74. * @internal
  75. */
  76. public function add()
  77. {
  78. $this->error();
  79. }
  80. /**
  81. * 编辑
  82. * @internal
  83. */
  84. public function edit($ids = null)
  85. {
  86. $this->error();
  87. }
  88. /**
  89. * 删除
  90. */
  91. public function del($ids = "")
  92. {
  93. if (!$this->request->isPost()) {
  94. $this->error(__("Invalid parameters"));
  95. }
  96. $ids = $ids ? $ids : $this->request->post("ids");
  97. if ($ids) {
  98. $isSuperAdmin = $this->auth->isSuperAdmin();
  99. $childrenAdminIds = $this->childrenAdminIds;
  100. $adminList = $this->model->where('id', 'in', $ids)
  101. ->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) {
  102. if (!$isSuperAdmin) {
  103. $query->where('admin_id', 'in', $childrenAdminIds);
  104. }
  105. })
  106. ->select();
  107. if ($adminList) {
  108. $deleteIds = [];
  109. foreach ($adminList as $k => $v) {
  110. $deleteIds[] = $v->id;
  111. }
  112. if ($deleteIds) {
  113. $this->model->destroy($deleteIds);
  114. $this->success();
  115. }
  116. }
  117. }
  118. $this->error();
  119. }
  120. /**
  121. * 批量更新
  122. * @internal
  123. */
  124. public function multi($ids = "")
  125. {
  126. // 管理员禁止批量操作
  127. $this->error();
  128. }
  129. }