<?php
// +----------------------------------------------------------------------
// | 角色列表
// +----------------------------------------------------------------------
// | Copyright (c) 2018 https://blog.junphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小黄牛 <1731223728@qq.com>
// +----------------------------------------------------------------------

namespace app\controller\admin\auth;
use app\controller\SuperClass\Admin;

class Role_list extends Admin
{

    /**
     * @AopBefore(class="app\aop\AdminLogin", function="before")
     * @RequestMapping(route="/admin/auth/role_list", method="GET|POST", title="角色列表")
     * @Param(name="page", value="1")
     * @Param(name="limit", value="10")
    */
    public function run() {
        if (\x\Request::is_ajax()) {
            return $this->showlist();
        }
        return $this->display();
    }

    // 列表
    private function showlist() {
        $Db = new \x\Db();
        $param = \x\Request::get();
        $where = $this->_where($param);
        $list = $Db->name('auth_role')->where($where)->order('id DESC')->page($param['page'], $param['limit'])->select();
        $count = $Db->name('auth_role')->where($where)->count();
        foreach ($list as $k=>$v) {
            $list[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
            $list[$k]['status'] = $v['status']==1?'开启':'关闭';
        }
        $Db->return();
        return $this->_list('0', '', $count, $list);
    }

    // 搜索条件
    private function _where($param=[]) {
        $where = [];
        if (!empty($param['name'])) {
            $where[] = ['name', '=', $param['name']];
        }

        return $where;
    }
}