public function actionCreate($patienttype) { $model = new Patient(); $Fias = new Fias(); $Fias->AOGUID = '0bf0f4ed-13f8-446e-82f6-325498808076'; // Нижневартовск по умолчанию if ($Fias->load(Yii::$app->request->post())) { if (!empty($Fias->AOGUID)) { $Fias = Fias::findOne($Fias->AOGUID); if ($Fias->AOLEVEL > 4 && $Fias->AOLEVEL < 7) { $model->id_fias = $Fias->AOGUID; $model->scenario = 'nostreetrequired'; } else { $model->scenario = 'streetrequired'; } } } $Fias->scenario = 'citychooserequired'; // Адрес обязателен $dopparams = ['dopparams' => []]; if ($patienttype === 'glauk') { $Glaukuchet = new Glaukuchet(); $Glaukuchet->glaukuchet_lastvisit = date('Y-m-d'); $Glaukuchet->scenario = 'forvalidatewithout_id_patient'; $dopparams['dopparams']['Glaukuchet'] = $Glaukuchet; } $transaction = Yii::$app->db->beginTransaction(); try { if ($patienttype === 'glauk' && $model->load(Yii::$app->request->post()) && $Glaukuchet->load(Yii::$app->request->post()) && Model::validateMultiple([$model, $Glaukuchet, $Fias])) { $model->save(false); $Glaukuchet->id_patient = $model->primaryKey; $Glaukuchet->save(false); Proc::RemoveLastBreadcrumbsFromSession(); // Удаляем последнюю хлебную крошку из сессии (Создать меняется на Обновить) $transaction->commit(); return $this->redirect(['update', 'id' => $model->patient_id, 'patienttype' => $patienttype]); } else { // Откатываем транзакцию $transaction->rollBack(); return $this->render('create', array_merge(['model' => $model, 'Fias' => $Fias, 'patienttype' => $patienttype], $dopparams)); } } catch (Exception $e) { $transaction->rollBack(); throw new Exception($e->getMessage()); } }