* @date 2017/02/15 10:41 */ class Index extends BasicAdmin { /** * 后台框架布局 * @return View */ public function index() { $list = Db::name('SystemMenu')->field('title,id,pid,url,icon')->order('sort asc,id asc')->where('status', '1')->select(); $menus = $this->_filter_menu(Tools::arr2tree($list)); $this->assign('title', '后台管理'); $this->assign('menus', $menus); return view(); } /** * 后台主菜单权限过滤 * @param array $menus * @return array */ private function _filter_menu($menus) { foreach ($menus as $key => &$menu) { if (!empty($menu['sub'])) { $menu['sub'] = $this->_filter_menu($menu['sub']); } if (!empty($menu['sub'])) { $menu['url'] = '#'; } elseif (stripos($menu['url'], 'http') === 0) { continue; } elseif ($menu['url'] !== '#' && auth(join('/', array_slice(explode('/', $menu['url']), 0, 3)))) { $menu['url'] = url($menu['url']); } else { unset($menus[$key]); } } return $menus; } /** * 主机信息显示 * @return View */ public function main() { $_version = Db::query('select version() as ver'); $version = array_pop($_version); $this->assign('mysql_ver', $version['ver']); if (session('user.username') === 'admin' && session('user.password') === '662af1cd1976f09a9f8cecc868ccc0a2') { $alert = [ 'type' => 'danger', 'title' => '安全提示', 'content' => '超级管理员默认密码未修改,建议马上修改!' ]; $this->assign('alert', $alert); $this->assign('title', '后台首页'); } return view(); } /** * 修改密码 */ public function pass() { if (intval($this->request->request('id')) !== intval(session('user.id'))) { $this->error('访问异常!'); } if ($this->request->isGet()) { $this->assign('verify', true); return $this->_form('SystemUser', 'user/pass'); } else { $data = $this->request->post(); if ($data['password'] !== $data['repassword']) { $this->error('两次输入的密码不一致,请重新输入!'); } $user = Db::name('SystemUser')->where('id', session('user.id'))->find(); if (md5($data['oldpassword']) !== $user['password']) { $this->error('旧密码验证失败,请重新输入!'); } if (Data::save('SystemUser', ['id' => session('user.id'), 'password' => md5($data['password'])])) { $this->success('密码修改成功,下次请使用新密码登录!', ''); } else { $this->error('密码修改失败,请稍候再试!'); } } } /** * 修改资料 */ public function info() { if (intval($this->request->request('id')) === intval(session('user.id'))) { return $this->_form('SystemUser', 'user/form'); } else { $this->error('访问异常!'); } } }