Adminlog.php 3.1 KB

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