public function checkAppForm() { $form = $this->appForm; $appModel = $this->primaryAppApplicant; $coAppModel = $this->coAppApplicant; $errorCount = 0; $totalCount = 1; $errorList = []; $tmpModel = new AppForm(['scenario' => 'complate-rate-check', 'id_application' => $this->id_application]); $tmpModel->validate(); $totalCount += count($tmpModel->getErrors()); $tmpModel = new AppApplicant(['scenario' => 'complate-rate-check']); $tmpModel->validate(); $totalCount += count($tmpModel->getErrors()); if ($coAppModel) { $tmpModel = new AppApplicant(['scenario' => 'co-complate-rate-check']); $tmpModel->validate(); $totalCount += count($tmpModel->getErrors()); } $form->setScenario('complate-rate-check'); $form->validate(); $errorCount += count($form->getErrors()); $errorList = array_merge($errorList, $form->getErrors()); $appModel->setScenario('complate-rate-check'); $appModel->validate(); $errorCount += count($appModel->getErrors()); $errorList = array_merge($errorList, $appModel->getErrors()); if ($coAppModel) { $coAppModel->setScenario('co-complate-rate-check'); $coAppModel->validate(); $errorCount += count($coAppModel->getErrors()); $errorList = array_merge($errorList, $coAppModel->getErrors()); } $collateralAccount = AppFormCollateralAccount::find()->andWhere(['id_application' => $this->id_application])->all(); if (!$collateralAccount) { $errorCount += 1; $errorList['collateral_account'] = ['need add one collateral account']; } return ['totalCount' => $totalCount, 'errorCount' => $errorCount, 'errorList' => $errorList]; }
/** * Creates a new Application model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Application(); $appModel = new AppApplicant(['scenario' => 'primary-create']); $coAppModel = new AppApplicant(['scenario' => 'co-create']); $appFormModel = new AppForm(); //加载数据并验证 if ($model->load(Yii::$app->request->post()) && $appModel->load(Yii::$app->request->post()) && $coAppModel->load(Yii::$app->request->post()) && $appFormModel->load(Yii::$app->request->post()) && $model->validate() && $appModel->validate() && ($model->is_joint_application == 1 ? $coAppModel->validate() : true) && ($model->is_joint_application == 1 ? $appModel->email_address != $coAppModel->email_address : true)) { //开启事务 $transaction = Yii::$app->db->beginTransaction(); try { if (!$appModel->id_user) { $user = User::createUser(Dict::USER_ROLE_CLIENT, ['User' => ['first_name' => $appModel->first_name, 'last_name' => $appModel->last_name, 'mid_name' => $appModel->mid_name, 'email' => $appModel->email_address], 'Client' => ['id_group' => $model->id_group]]); //设置applicant的id_user $appModel->id_user = $user->id_user; SendEmail::email(DictEmail::EMAIL_INVITE_USER, [$user]); } if ($model->is_joint_application && !$coAppModel->id_user) { $user = User::createUser(Dict::USER_ROLE_CLIENT, ['User' => ['first_name' => $coAppModel->first_name, 'last_name' => $coAppModel->last_name, 'mid_name' => $coAppModel->mid_name, 'email' => $coAppModel->email_address], 'Client' => ['id_group' => $model->id_group]]); //设置co-applicant的id_user $coAppModel->id_user = $user->id_user; SendEmail::email(DictEmail::EMAIL_INVITE_USER, [$user]); } $model->application_name = $appModel->first_name . ($model->is_joint_application ? ' and ' . $coAppModel->first_name : '') . "'s application"; $model->charge_fee = Advisor::findOne(['id_user' => Yii::$app->user->getId()])->will_charge_fee; if (!$model->save()) { $transaction->rollBack(); } $user = Yii::$app->user->getIdentity(); Active::operationLog($model->id_application, [$user->first_name, $user->last_name], DictActive::CREATE_APPLICATION, $user->id); $appModel->id_application = $model->id_application; $appModel->id_app_applicant_type = 1; if (!$appModel->save()) { $transaction->rollBack(); } if ($model->is_joint_application == 1) { $coAppModel->id_application = $model->id_application; $coAppModel->id_app_applicant_type = 2; if (!$coAppModel->save()) { $transaction->rollBack(); } } $appFormModel->id_application = $model->id_application; if (!$appFormModel->save()) { $transaction->rollBack(); } //初始化任务 AppTask::initialize($model->id_application); // 将AppTaskCheckpoint中的模板转换为实例 AppTaskCheckpoint::initialize($model->appTask); //创建AppUser记录 AppUser::createByApplication($model); //send email to notificate advisor create application success.method email([$task_type,$id_application,$id_app_owner_task],$notify_type) SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_APPLICATION_FORM, $model->id_application, 0]); //id_app_owner_task_type:1(app-form);0:表示没有传递id_app_owner_task $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); } return $this->redirect(['/app-form/basic-info', 'id_application' => $model->id_application]); } return $this->render('create', ['model' => $model, 'appModel' => $appModel, 'coAppModel' => $coAppModel, 'appFormModel' => $appFormModel]); }