public function actionSave($id_app_task)
 {
     $model = AppTask::findOne($id_app_task);
     if (Yii::$app->request->post()) {
         // save loan
         $loan = Loan::find()->where(['id_application' => $model->id_application])->one();
         $loan->setScenario('review');
         if (Yii::$app->request->isAjax && $loan->load(Yii::$app->request->post())) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($loan);
         }
         if ($loan->load(Yii::$app->request->post()) && $loan->validate()) {
             if ((int) $loan->total_capacity == 0 && Yii::$app->params['capacity_test_initialize']) {
                 $loan->total_capacity = $loan->loc;
             }
             $loan->save();
         }
         // save application
         $app = Application::findOne($model->id_application);
         $app->loc = $loan->loc;
         $app->interest_rate = $loan->interest_rate;
         $app->advance_rate = $loan->advance_rate;
         $app->maintainance_rate = $loan->maintainance_rate;
         $app->margin_rate = $loan->margin_rate;
         $app->total_capacity = $loan->total_capacity;
         $app->save(false);
         //send email to client(s)---application approval letter
         $data = AppUser::find()->andWhere(['id_application' => $model->id_application, 'is_primary_contact' => 1])->all();
         $users_id = [];
         foreach ($data as $val) {
             if ($val->user->id_user_role == Dict::USER_ROLE_BETTERDEBT) {
                 $users_id[] = $val->id_user;
             }
         }
     }
     return $this->redirect(['/task-app-review/index', 'id_app_task' => $id_app_task]);
 }
Example #2
0
 public function getAppUsers()
 {
     return $this->hasMany(AppUser::className(), ['id_application' => 'id_application']);
 }
 /**
  * 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]);
 }
Example #4
0
 public function getPrimaryAdvisor()
 {
     $a = AppApplicant::find()->andWhere(['id_user' => Yii::$app->user->getId()])->one();
     return AppUser::find()->joinwith('appApplicant')->joinwith('user')->andWhere(['app_applicant.id_user' => Yii::$app->user->getId(), 'app_applicant.id_application' => $a['id_application'], 'is_primary_contact' => 1, 'id_user_role' => Dict::USER_ROLE_ADVISOR]);
 }
 public function safeUp()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     // 读取 application
     $application_list = Application::find()->all();
     // application添加的2个字段primaty_advisor和primary_supernova补充完整
     foreach ($application_list as $application) {
         $id_application = $application->id_application;
         // 读取advisor
         $user_advisor = AppUser::find()->andWhere(['id_application' => $id_application, 'is_primary_contact' => 1])->joinWith('user')->andWhere(['id_user_role' => Dict::USER_ROLE_ADVISOR])->one();
         // 读取 supernova
         $user_supernova = AppUser::find()->andWhere(['id_application' => $id_application, 'is_primary_contact' => 1])->joinWith('user')->andWhere(['id_user_role' => Dict::USER_ROLE_BETTERDEBT])->one();
         $application->primary_advisor = $user_advisor->id_user;
         $application->primary_supernova = $user_supernova->id_user;
         $application->save();
         // 读取application初始化新的app_task和app_task_checkpoint
         AppTask::initialize($id_application);
         $app_task_list = AppTask::find()->andWhere(['id_application' => $id_application])->all();
         AppTaskCheckpoint::initialize($app_task_list);
         //读取app_owner_task_back和app_owner_task_checkpoint_back
         $app_owner_task_list = Yii::$app->db->createCommand("SELECT O.* FROM app_task_back AS T, app_owner_task_back as O where T.id_app_task = O.id_app_task and T.id_application = {$id_application}")->queryAll();
         $app_owner_task_checkpoint_list = Yii::$app->db->createCommand("SELECT B.* FROM app_task_back AS T, app_owner_task_checkpoint_back as B, app_owner_task_back as O where B.id_app_owner_task = O.id_app_owner_task and T.id_app_task = O.id_app_task and T.id_application = {$id_application}")->queryAll();
         // app_owner_task_back
         foreach ($app_owner_task_list as $app_owner_task_key => $app_owner_task) {
             $back_to_now = ['1' => DictTask::TYPE_APPLICATION_FORM, '2' => DictTask::TYPE_SIGN_APPLICATION_FORM, '3' => DictTask::TYPE_UPLOAD_WET­SIGNED_FORM, '4' => DictTask::TYPE_SUPPLEMENTAL_MATERIALS, '5' => DictTask::TYPE_APPLICATION_REVIEW, '6' => DictTask::TYPE_LINE_AGREEMENTS, '7' => DictTask::TYPE_SIGN_AGREEMENTS, '8' => DictTask::TYPE_LINE_SETUP];
             // 读取对应的 app_task
             $app_task_where = ['id_application' => $id_application, 'id_app_task_type' => $back_to_now[$app_owner_task['id_app_owner_task_type']]];
             if (in_array($app_owner_task['id_app_owner_task_type'], array('2', '7'))) {
                 $app_task_where['id_user'] = $app_owner_task['id_user'];
             }
             $app_task = AppTask::findOne($app_task_where);
             // 逻辑修正
             if ($app_owner_task['id_app_owner_task_type'] == 6 && $app_owner_task_list[$app_owner_task_key + 1]['delete'] == Dict::DELETE_NOT && $app_owner_task_list[$app_owner_task_key + 1]['id_app_owner_task_status'] != DictTask::STATUS_NOT_ACTIVE) {
                 AppTask::close($app_task->id_app_task);
             } else {
                 // 变更完成状态
                 switch ($app_owner_task['id_app_owner_task_status']) {
                     case DictTask::STATUS_ACTIVE:
                         $app_task->nextStart($app_task->id_app_task);
                         break;
                     case DictTask::STATUS_FINISH:
                         if ($app_task->active == DictTask::INACTIVE) {
                             $app_task->active = DictTask::ACTIVE;
                             $app_task->save();
                         }
                         $app_task->taskFinish($app_task->id_app_task);
                         break;
                 }
             }
             // 变更结束状态
             if ($app_owner_task['delete'] == Dict::DELETE_YES) {
                 AppTask::close($app_task->id_app_task);
             }
             // 变更任务所属人角色
             if ($app_task['id_app_task_type'] != DictTask::TYPE_SIGN_APPLICATION_FORM) {
                 if ($app_task['id_app_task_type'] != DictTask::TYPE_SIGN_AGREEMENTS) {
                     $id_user = $app_owner_task['id_user'];
                     $user = User::findOne(['id_user' => $id_user]);
                     $app_task->owner_type = DictTask::$userRoleToOwner[$user->id_user_role];
                     $app_task->save();
                 }
             }
             // 判断是否是签名任务
             if (in_array($app_owner_task['id_app_owner_task_type'], array('2', '7'))) {
                 // 找到对应的签名记录
                 $docusign_recipient = DocusignRecipient::find(false)->andWhere(['id_application' => $id_application, 'id_app_task' => $app_owner_task['id_app_owner_task']])->one();
                 if (isset($docusign_recipient)) {
                     // 找到新的 id_app_task
                     $app_task_new = AppTask::findOne(['id_application' => $id_application, 'id_user' => $app_owner_task['id_user'], 'id_app_task_type' => $back_to_now[$app_owner_task['id_app_owner_task_type']]]);
                     // 变更 id_app_task
                     $docusign_recipient->id_app_task = $app_task_new->id_app_task;
                     $docusign_recipient->save();
                 }
             }
         }
         // 变更app_task_checkpoint里面的status
         foreach ($app_owner_task_checkpoint_list as $app_owner_task_checkpoint) {
             $app_task_checkpoint = AppTaskCheckpoint::findOne(['id_application' => $id_application, 'id_app_task_checkpoint_type' => $app_owner_task_checkpoint['id_app_owner_task_checkpoint_type']]);
             $app_task_checkpoint->status = $app_owner_task_checkpoint['status'];
             $app_task_checkpoint->save();
         }
     }
 }