search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User(['scenario' => 'create']);
$title = '添加用户';
if ($model->load(Yii::$app->request->post())) {
$login_user = Yii::$app->user->identity;
$model->syncPermissionFo();
$model->USER_PASSWORD = md5($model->USER_PASSWORD);
//车队系统添加的账号,运营主体都为车队运营主体
/* @var $login_user User */
$model->MAIN_CORP_ID = $login_user->MAIN_CORP_ID2;
$model->MAIN_CORP_ID2 = $login_user->MAIN_CORP_ID2;
$model->ORG_ID = $login_user->ORG_ID;
if ($model->save()) {
return '';
} else {
return $this->renderPartial('_form', [
'title' => $title,
'model' => $model,
'type' => 'create'
]);
}
} else {
return $this->renderPartial('_form', [
'title' => $title,
'model' => $model,
'type' => 'create'
]);
}
}
public function actionView($id)
{
return $this->actionUpdate($id, 'view');
}
/**
* Updates an existing User model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @param string $type 查看和修改页面相同
* @return mixed
*/
public function actionUpdate($id, $type = 'update')
{
$title = $type === 'update' ? '修改用户' : '查看用户';
$model = $this->findModel($id);
$model->setScenario('update');
if ($model->load(Yii::$app->request->post())) {
$model->syncPermissionFo();
//密码不为空,
if (trim($model->USER_PASSWORD) != '')
$model->USER_PASSWORD = md5($model->USER_PASSWORD);
else
$model->USER_PASSWORD = $model->getOldAttribute('USER_PASSWORD');
if ($model->save()) {
return '';
} else {
if (!is_array($model->USER_ROLE2)) {
$model->USER_ROLE2 = explode(',', $model->USER_ROLE2);
}
return $this->renderPartial('_form', [
'title' => $title,
'model' => $model,
'type' => $type
]);
}
} else {
if (!is_array($model->USER_ROLE2)) {
$model->USER_ROLE2 = explode(',', $model->USER_ROLE2);
}
$model->USER_PASSWORD = '';
return $this->render('_form', [
'title' => $title,
'model' => $model,
'type' => $type
]);
}
}
public function actionDisable($id)
{
$model = $this->findModel($id);
if ($model->STATUS == 1) {
$model->STATUS = 0;
if ($model->save(false))
$result = ['code' => 0, 'msg' => "启用成功!"];
else
$result = ['code' => 1, 'msg' => "启用失败!"];
} else {
$model->STATUS = 1;
if ($model->save(false))
$result = ['code' => 0, 'msg' => "停用成功!"];
else
$result = ['code' => 1, 'msg' => "停用失败!"];
}
return \GuzzleHttp\json_encode($result);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}