Adminlog.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\admin\controller\auth;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. /**
  6. * 管理员日志
  7. *
  8. * @icon fa fa-users
  9. * @remark 管理员可以查看自己所拥有的权限的管理员日志
  10. */
  11. class Adminlog extends Backend
  12. {
  13. protected $model = null;
  14. //当前登录管理员所有子节点组别
  15. protected $childrenIds = [];
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = model('AdminLog');
  20. $groups = $this->auth->getGroups();
  21. // 取出所有分组
  22. $grouplist = model('AuthGroup')->all(['status' => 'normal']);
  23. $objlist = [];
  24. foreach ($groups as $K => $v)
  25. {
  26. // 取出包含自己的所有子节点
  27. $childrenlist = Tree::instance()->init($grouplist)->getChildren($v['id'], TRUE);
  28. $obj = Tree::instance()->init($childrenlist)->getTreeArray($v['pid']);
  29. $objlist = array_merge($objlist, Tree::instance()->getTreeList($obj));
  30. }
  31. $groupdata = [];
  32. foreach ($objlist as $k => $v)
  33. {
  34. $groupdata[$v['id']] = $v['name'];
  35. }
  36. $this->childrenIds = array_keys($groupdata);
  37. $this->view->assign('groupdata', $groupdata);
  38. }
  39. /**
  40. * 查看
  41. */
  42. public function index()
  43. {
  44. if ($this->request->isAjax())
  45. {
  46. $childrenAdminIds = model('AuthGroupAccess')
  47. ->field('uid')
  48. ->where('group_id', 'in', $this->childrenIds)
  49. ->column('uid');
  50. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  51. $total = $this->model
  52. ->where($where)
  53. ->where('admin_id', 'in', $childrenAdminIds)
  54. ->order($sort, $order)
  55. ->count();
  56. $list = $this->model
  57. ->where($where)
  58. ->where('admin_id', 'in', $childrenAdminIds)
  59. ->order($sort, $order)
  60. ->limit($offset, $limit)
  61. ->select();
  62. $result = array("total" => $total, "rows" => $list);
  63. return json($result);
  64. }
  65. return $this->view->fetch();
  66. }
  67. /**
  68. * 详情
  69. */
  70. public function detail($ids)
  71. {
  72. $row = $this->model->get(['id' => $ids]);
  73. if (!$row)
  74. $this->error(__('No Results were found'));
  75. $this->view->assign("row", $row->toArray());
  76. return $this->view->fetch();
  77. }
  78. /**
  79. * 添加
  80. * @internal
  81. */
  82. public function add()
  83. {
  84. $this->code = -1;
  85. }
  86. /**
  87. * 编辑
  88. * @internal
  89. */
  90. public function edit($ids = NULL)
  91. {
  92. $this->code = -1;
  93. }
  94. /**
  95. * 删除
  96. */
  97. public function del($ids = "")
  98. {
  99. $this->code = -1;
  100. if ($ids)
  101. {
  102. $childrenGroupIds = $this->childrenIds;
  103. $adminList = $this->model->where('id', 'in', $ids)->where('admin_id', 'in', function($query) use($childrenGroupIds) {
  104. $query->name('auth_group_access')->field('uid');
  105. })->select();
  106. if ($adminList)
  107. {
  108. $deleteIds = [];
  109. foreach ($adminList as $k => $v)
  110. {
  111. $deleteIds[] = $v->id;
  112. }
  113. if ($deleteIds)
  114. {
  115. $this->model->destroy($deleteIds);
  116. $this->code = 1;
  117. }
  118. }
  119. }
  120. return;
  121. }
  122. /**
  123. * 批量更新
  124. * @internal
  125. */
  126. public function multi($ids = "")
  127. {
  128. // 管理员禁止批量操作
  129. $this->code = -1;
  130. }
  131. }