/** * 修改管理员 * * @param array $_POST[] 管理员修改数据 */ public function actionUpdate() { //菜单权限检测 Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login'); $mAdmin = new Admin(); if ($params = Yii::$app->request->post()) { //验证 if (empty($params['user_name'])) { Yii::$app->util->msg('参数错误'); } if (empty($params['password']) && empty($params['repassword'])) { $options = ['id' => $params['id'], 'user_name' => $params['user_name'], 'auth' => isset($params['auth']) ? json_encode($params['auth']) : '']; } else { if ($params['password'] != $params['repassword']) { Yii::$app->util->msg('两次密码不一致'); } else { $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $salt = substr(str_shuffle($str), 0, 8); $options = ['id' => $params['id'], 'user_name' => $params['user_name'], 'salt' => $salt, 'password' => Yii::$app->util->passwordEncode($params['password'], $salt), 'auth' => isset($params['auth']) ? json_encode($params['auth']) : '']; } } if ($mAdmin->store($options)) { return $this->redirect('admin-list'); } else { Yii::$app->util->msg('入库错误'); } } else { $id = Yii::$app->request->get('id', 0); $one = $mAdmin->getAdminById($id); if (!$one) { return $this->redirect('admin-list'); } else { $mMenu = new Menu(); $data = $mMenu->menu(); $auth = json_decode($one['auth']); if (!empty($auth)) { foreach ($data as $k => $v) { if (in_array($v['id'], $auth)) { $data[$k]['checked'] = 'checked'; } else { $data[$k]['checked'] = ''; } } } return $this->render('update', ['data' => $data, 'one' => $one]); } } }