审查视图

application/admin/controller/auth/Adminlog.php 3.3 KB
1 2 3 4
<?php

namespace app\admin\controller\auth;
5
use app\admin\model\AuthGroup;
6 7 8 9 10
use app\common\controller\Backend;

/**
 * 管理员日志
 *
11
 * @icon   fa fa-users
12 13 14 15 16
 * @remark 管理员可以查看自己所拥有的权限的管理员日志
 */
class Adminlog extends Backend
{
17 18 19
    /**
     * @var \app\admin\model\AdminLog
     */
20
    protected $model = null;
21 22
    protected $childrenGroupIds = [];
    protected $childrenAdminIds = [];
23 24 25 26 27 28

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('AdminLog');
29
        $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
Karson authored
30
        $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin() ? true : false);
31
32
        $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds)
33
            ->column('id,name');
34 35

        $this->view->assign('groupdata', $groupName);
36 37 38 39 40 41 42
    }

    /**
     * 查看
     */
    public function index()
    {
43
        if ($this->request->isAjax()) {
44 45
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
46 47 48 49
                ->where($where)
                ->where('admin_id', 'in', $this->childrenAdminIds)
                ->order($sort, $order)
                ->count();
50 51

            $list = $this->model
52 53 54 55 56
                ->where($where)
                ->where('admin_id', 'in', $this->childrenAdminIds)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
57 58 59 60 61 62
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }
Karson authored
63
64 65 66 67 68 69
    /**
     * 详情
     */
    public function detail($ids)
    {
        $row = $this->model->get(['id' => $ids]);
70
        if (!$row) {
71
            $this->error(__('No Results were found'));
72
        }
73 74 75 76 77 78 79 80 81 82
        $this->view->assign("row", $row->toArray());
        return $this->view->fetch();
    }

    /**
     * 添加
     * @internal
     */
    public function add()
    {
Karson authored
83
        $this->error();
84 85 86 87 88 89
    }

    /**
     * 编辑
     * @internal
     */
90
    public function edit($ids = null)
91
    {
Karson authored
92
        $this->error();
93 94 95 96 97 98 99
    }

    /**
     * 删除
     */
    public function del($ids = "")
    {
100 101 102 103 104
        if (!$this->request->isPost()) {
            $this->error(__("Invalid parameters"));
        }
        $ids = $ids ? $ids : $this->request->post("ids");
        if ($ids) {
105
            $childrenGroupIds = $this->childrenGroupIds;
106 107 108 109
            $adminList = $this->model->where('id', 'in', $ids)->where('admin_id', 'in', function ($query) use ($childrenGroupIds) {
                $query->name('auth_group_access')->field('uid');
            })->select();
            if ($adminList) {
110
                $deleteIds = [];
111
                foreach ($adminList as $k => $v) {
112 113
                    $deleteIds[] = $v->id;
                }
114
                if ($deleteIds) {
115
                    $this->model->destroy($deleteIds);
Karson authored
116
                    $this->success();
117 118 119
                }
            }
        }
Karson authored
120
        $this->error();
121 122 123 124 125 126 127 128 129
    }

    /**
     * 批量更新
     * @internal
     */
    public function multi($ids = "")
    {
        // 管理员禁止批量操作
Karson authored
130
        $this->error();
131
    }
132
133 134 135 136
    public function selectpage()
    {
        return parent::selectpage();
    }
137
}