public function actionIndex() { $data['title'] = $this->title; // 拿出登录用户 $session = Yii::$app->session; $data['user'] = $session->get('name'); $userId = $session->get('userId'); // 拿出用户权限 $userGroup = Admin::find()->select(['group'])->where(['id' => $userId])->asArray()->one(); $userRole = Adminrole::find()->select(['root'])->where(['id' => $userGroup['group']])->asArray()->one(); // 权限管理 if ($userRole['root'] == "super") { // 超级权限 $res = $this->superMenu(); $data['mideMenus'] = $res['mideMenus']; $data['secendMenus'] = $res['secendMenus']; } elseif ($userRole['root'] == "") { // 无任何权限 $data['mideMenus'] = []; $data['secendMenus'] = []; } else { // 普通权限划分 $res = $this->normalMenu($userRole['root']); $data['mideMenus'] = $res['mideMenus']; $data['secendMenus'] = $res['secendMenus']; } return $this->renderPartial('index', $data); }
public function actionEditmanager($id = null) { $request = Yii::$app->request; if (!$request->isPost) { // 编辑模式 $data = Admin::find()->select(['id', 'name', 'username', 'tel', 'statu', 'group'])->where(['id' => $id])->asArray()->one(); // 拿出角色信息 $data['roles'] = Adminrole::find()->select(['id', 'name'])->asArray()->all(); return $this->renderPartial('editmanager', $data); } else { $data = $request->post('data'); // check data $res = $this->admincheck($data); if ($res['statu'] != "error") { $adminadd = Admin::find()->where(['id' => $data['id']])->one(); // 执行数据库插入 // 登陆账号 if ($adminadd['username'] != $data['username']) { // 已经修改用户账号 则查重 $ishas = Admin::find()->where(['username' => $data['username']])->asArray()->one(); if (sizeof($ishas)) { $res['statu'] = "error"; $res['des'] = "管理员登陆账号已存在!"; return json_encode($res); } } // 其他 $adminadd->name = $data['name']; $adminadd->username = $data['username']; $adminadd->tel = $data['tel']; $adminadd->statu = $data['statu']; $adminadd->group = $data['group']; // 密码修改 if ($data['psw'] != "******") { $adminadd->password = md5($data['psw']); } if ($adminadd->save()) { $res['des'] = "编辑管理员成功!"; $res['jump'] = Url::toRoute('/admin/management/management'); } else { $res['des'] = "编辑管理员失败!数据库错误!"; $res['statu'] = "error"; } } } return json_encode($res); }
public function actionChangerole() { $request = Yii::$app->request; if ($request->isPost) { $roleid = $request->post("id"); $menuid = $request->post("data"); $changerole = Adminrole::find()->where(["id" => $roleid])->one(); $changerole->root = $menuid ? implode("|", $menuid) : null; if ($changerole->save()) { $res['des'] = "角色授权成功!"; $res['jump'] = Url::toRoute('/admin/role/role'); } else { $res['des'] = "角色授权失败,请重试!"; $res['statu'] = "error"; } return json_encode($res); } }