/** * Deletes an existing Application model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionAssignTo($id_app_task) { $model = AppTask::findOne($id_app_task); $task = new AppTask(); $assignTo = new AssigntoForm(); if ($assignTo->load(Yii::$app->request->post()) && $assignTo->validate()) { $owner_type = $assignTo->owner_type; $task->AssignTo($id_app_task, $owner_type); if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) { return $this->redirect(['/loan/application']); } else { return $this->redirect(['/application/view', 'id' => $model->id_application]); } } if (Yii::$app->request->post() && !$assignTo->owner_type) { if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) { return $this->redirect(['/loan/application']); } else { return $this->redirect(['/application/view', 'id' => $model->id_application]); } } return $this->renderAjax('assign_to', ['model' => $model, 'assignTo' => $assignTo]); }
public function actionSubmitEsign($id_app_task) { $model = AppTask::findOne($id_app_task); $application = $model->application; $appFormModel = $application->appForm; $appFormModel->load(Yii::$app->request->get()); $appFormModel->save(false); $appFormModel->setScenario('disclosures'); $status = $appFormModel->validate(true); AppFormStatus::changeStatus($application->id_application, 4, $status); //检查AppForm所有项是否正确填写 $result = $application->checkAppForm(); if (Yii::$app->request->post()) { // docusign $result_docusign = SendDocuSign::appForm($application->id_application); // Finish Task AppTask::taskFinish($id_app_task); //active log. client submit app-form Active::operationLog($application->id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, 'submitted', DictTask::$taskType[DictTask::TYPE_APPLICATION_FORM]], DictActive::USER_FINISH_TASK, Yii::$app->user->getIdentity()->id); //find user $res = SendEmail::findUserByApplication($application->id_application); //active log. system create task sing-app-form and assign to client/advisor Active::operationLog($application->id_application, [DictTask::$taskType[DictTask::TYPE_SIGN_APPLICATION_FORM], $res['advisor']->first_name, $res['advisor']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //system assign to advisor Active::operationLog($application->id_application, [DictTask::$taskType[DictTask::TYPE_SIGN_APPLICATION_FORM], $res['applicant']->first_name, $res['applicant']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //system assign to client if (!is_null($res['co_applicant'])) { Active::operationLog($application->id_application, [DictTask::$taskType[DictTask::TYPE_SIGN_APPLICATION_FORM], $res['co_applicant']->first_name, $res['co_applicant']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //system assign to co_client } //active log. system send docusign task email to user Active::operationLog($application->id_application, [DictTask::$taskType[DictTask::TYPE_APPLICATION_FORM], $res['advisor']->first_name, $res['advisor']->last_name], DictActive::SYSTEM_SEND_DOCUSIGN_EMAIL, 0); //system send docusign email to advisor Active::operationLog($application->id_application, [DictTask::$taskType[DictTask::TYPE_APPLICATION_FORM], $res['applicant']->first_name, $res['applicant']->last_name], DictActive::SYSTEM_SEND_DOCUSIGN_EMAIL, 0); //system send docusign email to client //active log. system create task supplemental-materials and assign to advisor Active::operationLog($application->id_application, [DictTask::$taskType[DictTask::TYPE_SUPPLEMENTAL_MATERIALS], $res['advisor']->first_name, $res['advisor']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //System send email new task “Supplemental materials Notification” to client SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_SUPPLEMENTAL_MATERIALS, $application->id_application, $id_app_task + 2]); //id_app_task_type:1(app-form);0:表示没有传递id_app_task if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) { return $this->redirect(['/loan/application']); } else { return $this->redirect(['/application/view', 'id' => $application->id_application]); } } return $this->renderAjax('submit_esign', ['model' => $model, 'result' => $result]); }
public function actionCheck($id_app_task) { $model = AppTask::findOne($id_app_task); // application $application = Application::findOne($model->id_application); // check points $checkPointsData = AppTaskCheckpoint::find()->where(['id_app_task' => $id_app_task])->all(); $checkPoints = []; $check_ctrl = true; foreach ($checkPointsData as $val) { $checkPoints[$val['id_app_task_checkpoint_type']] = $val; } if (!$application->have_existing_loan) { unset($checkPoints[5]); } return $this->renderAjax('check', ['model' => $model, 'checkPoints' => $checkPoints]); }
/** * Deletes an existing Application model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionIndex() { $documents_type = ['app_form.pdf' => DictDocument::TYPE_APPLICATION_FORM, 'loan_agreements.pdf' => DictDocument::TYPE_LINE_AGREEMENT, 'g3.pdf' => DictDocument::TYPE_G3, 'w9.pdf' => DictDocument::TYPE_W9]; // log Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 开始一次定时任务', Logger::LEVEL_ERROR); $dir = Yii::$app->params['outpdfPath']; $envelopes_data = DocusignRecipient::find()->andWhere(['status' => 0])->all(); $envelopes = []; foreach ($envelopes_data as $val) { $envelopes[] = $val->id_envelope; } $envelopes = array_unique($envelopes); if (count($envelopes) > 0) { // DocuSign $client = new DocuSign_Client(); $service = new DocuSign_StatusService($client); // Status foreach ($envelopes as $id_envelope) { $response = $service->status->getRecipientsStatus($id_envelope); $signers = $response->signers; foreach ($signers as $val) { if ($val->status == 'completed') { // DocusignRecipient $recipient = DocusignRecipient::find()->andWhere(['email' => $val->email, 'id_envelope' => $id_envelope])->one(); $user = User::findOne($recipient->id_user); if (isset($recipient) && isset($user) && $recipient->status == 0) { // 获取在线文件 $task = AppTask::findOne($recipient->id_app_task); //active log after E-signed documents switch ($task->id_app_task_type) { case DictTask::TYPE_SIGN_APPLICATION_FORM: Active::operationLog($recipient->id_application, [$user->first_name, $user->last_name, DictTask::$taskType[DictTask::TYPE_APPLICATION_FORM]], DictActive::USER_DOCSIGNED_TASK, $user->id_user); break; case DictTask::TYPE_SIGN_AGREEMENTS: Active::operationLog($recipient->id_application, [$user->first_name, $user->last_name, DictTask::$taskType[DictTask::TYPE_LINE_AGREEMENTS]], DictActive::USER_DOCSIGNED_TASK, $user->id_user); break; } $service_document = new DocuSign_EnvelopeService($client); $document_all = $service_document->envelope->getEnvelopeDocuments($id_envelope); foreach ($document_all->envelopeDocuments as $document) { if ($document->type == 'content') { Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 将' . $user->first_name . '.' . $user->last_name . '(id_user:'******')' . '-的签名改为已完成-' . $id_envelope, Logger::LEVEL_ERROR); $file = $dir . $recipient->id_application . '_' . $document->name; // 删除旧文件 if (file_exists($file)) { unlink($file); } // 读取 Docusign 新文件 $content = $service_document->envelope->getEnvelopeDocuments($id_envelope, $document->documentId); // 写入文件 $fp = @fopen($file, 'a'); fwrite($fp, $content); fclose($fp); // 上传 document $id_document_type = $documents_type[$document->name]; $result = Upload::uploadFileByApplication($recipient->id_application, $file, $document->name, $id_document_type); if ($result) { //delete local file $outpdf_file = $dir . $recipient->id_application . '_' . $document->name; if (file_exists($outpdf_file)) { unlink($outpdf_file); } //active log (0:present send by System) foreach (DictDocument::$documentType as $key => $val) { switch ($id_document_type) { case $key: Active::operationLog($recipient->id_application, [$val], DictActive::SYSTEM_UPDATED_TASK_WITH_SIGNATURE, 0); break; } } } } } // 变更 DocusignRecipient Status $recipient->status = 1; $recipient->save(false); // 变更 Task Status Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 变更 task status (id_app_task:' . $recipient->id_app_task . ')', Logger::LEVEL_ERROR); if (AppTask::taskFinish($recipient->id_app_task)) { //再次查询task (finish之后的appTask,每次子task完成之后会相应的改变父类task的status) $after_task = AppTask::findOne($recipient->id_app_task); $parent_status = $after_task->parent->status; if ($parent_status == DictTask::STATUS_FINISH) { //find user $user = SendEmail::findUserByApplication($recipient->id_application); if ($after_task->parent->id_app_task_type == DictTask::TYPE_SIGN_APPLICATION_FORM_BOX) { //system created a task 'Review Application' to loan officer Active::operationLog($recipient->id_application, [DictTask::$taskType[DictTask::TYPE_APPLICATION_REVIEW], $user['supernova']->first_name, $user['supernova']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //send email to supernova start task Application Review SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_APPLICATION_REVIEW, $recipient->id_application, $after_task->parent->id_app_task, DictTask::DOCUSIGN_NOTIFICATION]); } elseif ($after_task->parent->id_app_task_type == DictTask::TYPE_SIGN_AGREEMENTS_BOX) { //active log.system closed the task 'line Agreement' Active::operationLog($recipient->id_application, [DictTask::$taskType[DictTask::TYPE_LINE_AGREEMENTS]], DictActive::SYSTEM_CLOSED_TASK, 0); //active log. system create task line set-up and assign to client/advisor Active::operationLog($recipient->id_application, [DictTask::$taskType[DictTask::TYPE_LINE_SETUP], $user['supernova']->first_name, $user['supernova']->last_name], DictActive::SYSTEM_CREATE_TASK_TO_USER, 0); //system created task line-setup //send email to supernova start task Line Setup SendEmail::email(DictEmail::EMAIL_TASK_NOTIFICATION, [DictTask::TYPE_LINE_SETUP, $recipient->id_application, $after_task->parent->id_app_task, DictTask::DOCUSIGN_NOTIFICATION]); } } } } } } } } Yii::getLogger()->log(date("Y-m-d h:i:s", time()) . ' - 完成 ---------------------', Logger::LEVEL_ERROR); }
public function getAllTasksInProgress() { $_user = Yii::$app->user->getIdentity(); // 查找用户所有正在活动的任务,不包括节点 $app_tasks = AppTask::find()->andWhere(['id_application' => $this->id_application, 'child_relation_type' => DictTask::CHILD_RELATION_NULL, 'finish_type' => DictTask::FINISH_NULL, 'active' => DictTask::ACTIVE, 'status' => DictTask::STATUS_ACTIVE])->andWhere(['!=', 'owner_type', DictTask::$userRoleToOwner[$_user->id_user_role]])->andWhere(['!=', 'id_user', $_user->id_user])->all(); return $app_tasks; }
public function getAppTask() { return $this->hasOne(AppTask::className(), ['id_app_task' => 'id_app_task']); }
/** * 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]); }
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title" id="myModalLabel"><?php echo $model->name; ?> </h4> </div> <div class="modal-body"> <h4>Status: <span class="label <?php echo $label_css; ?> "> <?php echo AppTask::item('id_app_task_status', $model->id_app_task_status); ?> </span> </h4> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <?php if ($model->id_app_task_status == 2) { ?> <?php echo Html::submitButton('E-Sign', ['class' => 'btn btn-primary']); ?> <?php }
public function AssignTo($id_app_task, $owner_type) { $model = AppTask::find(false)->andWhere(['id_app_task' => $id_app_task])->one(); $model->owner_type = $owner_type; if ($model->save()) { foreach (DictTask::$taskType as $key => $val) { switch ($model->id_app_task_type) { case $key: //active log 包含在发送邮件的方法中 SendEmail::email(DictEmail::EMAIL_TASK_ASSIGN_TO, [$model->id_application, $id_app_task, $owner_type, $key]); break; } } } }
public function actionRemind($id_app_task) { $model = DocusignRecipient::find()->andWhere(['id_app_task' => $id_app_task])->one(); $task = AppTask::findOne($id_app_task); if (Yii::$app->request->post()) { // DocuSign Client $client = new DocuSign_Client(); $service = new DocuSign_StatusService($client); $service->status->getRemind($model->id_envelope); return $this->redirect(['application/view', 'id' => $task->id_application]); } return $this->renderAjax('remind', ['model' => $model]); }
public function actionCheck($id_app_task) { $model = AppTask::findOne($id_app_task); //find by document type $loanStatements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_LOAN_STATEMENT, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); //display loan statement? $application = Application::find()->andWhere(['id_application' => $model->id_application])->one(); if ($application->have_existing_loan == 1) { $loanStatements_display = 'list-item'; //method of display } $accountStatements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_ACCOUNT_STATEMENT, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); $photos = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_PHOTO_ID, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); $certification = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_TRUSTEE_CERTIFICATION, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->all(); $account = AppFormCollateralAccount::find()->andWhere(['id_application' => $model->id_application])->one(); if ($account->is_trust_account == 1) { $certification_display = 'list-item'; //method of display } return $this->renderAjax('check', ['model' => $model, 'loanStatements' => $loanStatements, 'accountStatements' => $accountStatements, 'photos' => $photos, 'certification' => $certification, 'loanStatements_display' => isset($loanStatements_display) ? $loanStatements_display : 'none', 'certification_display' => isset($certification_display) ? $certification_display : 'none']); }
public function beforeAction($action) { // ID $ctrl_id = $action->controller->id; $action_id = $action->id; $behaviour = $ctrl_id . '/' . $action_id; if (parent::beforeAction($action)) { // 判断 id_application 权限 if (isset($_GET['id_application']) && !isset($_GET['id_app_task'])) { $application = Application::findOne($_GET['id_application']); if (!$application->checkOnwerAccess($this->user->id_user)) { if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT) { $this->AUTH = Dict::AUTH_READ; $app_task = AppTask::findOne(['id_application' => $application->id_application, 'id_app_task_type' => DictTask::TYPE_APPLICATION_FORM]); if (($app_task->status != DictTask::STATUS_ACTIVE || $app_task->application->id_application_status != DictApplication::STATUS_ACTIVE) && !in_array($behaviour, ['task-sign/close', 'task-supplemental-information/view-file'])) { if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT || $this->user->id_user_role == Dict::USER_ROLE_ADVISOR) { $this->redirect(['/application/view', 'id' => $app_task->id_application]); } else { if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) { $this->redirect(['/loan/application']); } } return false; } } else { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } } else { // app-form 特殊判断 if ($ctrl_id == 'app-form') { $app_task = AppTask::findOne(['id_application' => $application->id_application, 'id_app_task_type' => DictTask::TYPE_APPLICATION_FORM]); if ($app_task->status != DictTask::STATUS_ACTIVE || $app_task->application->id_application_status != DictApplication::STATUS_ACTIVE) { if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT || $this->user->id_user_role == Dict::USER_ROLE_ADVISOR) { $this->redirect(['/application/view', 'id' => $app_task->id_application]); } else { if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) { $this->redirect(['/loan/application']); } } return false; } if ($app_task->owner_type == DictTask::$userRoleToOwner[$this->user->id_user_role]) { $this->AUTH = Dict::AUTH_OPERATE; } else { $this->AUTH = Dict::AUTH_READ; } } else { if ($behaviour == 'task-sign/close') { $betterdebt = Betterdebt::findOne(['id_user' => $this->user->id_user]); if ($betterdebt->is_in_service_team == Dict::BD_SERVICE_TEAM_YES) { $this->AUTH = Dict::AUTH_OPERATE; } else { $this->AUTH = Dict::AUTH_READ; } } else { $this->AUTH = Dict::AUTH_READ; } } } } // 判断 id_app_task 权限 if (isset($_GET['id_app_task'])) { $app_task = AppTask::findOne($_GET['id_app_task']); if ($app_task->application->checkOnwerAccess($this->user->id_user)) { if (!AppTask::checkOnwerAccess($app_task, $behaviour)) { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } else { if (in_array($behaviour, ['task-sign/close', 'task/assign-to', 'task-sign/remind'])) { $this->AUTH = Dict::AUTH_OPERATE; } else { if (DictTask::$ownerToUserRole[$app_task->owner_type] == $this->user->id_user_role) { $this->AUTH = Dict::AUTH_OPERATE; } else { $this->AUTH = Dict::AUTH_READ; } } } } else { if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT) { $this->AUTH = Dict::AUTH_READ; } else { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } } $loan = Loan::findOne(['id_application' => $app_task->id_application]); // 如果任务不是正在进行中,则跳转 if ($app_task->status != DictTask::STATUS_ACTIVE || $app_task->application->id_application_status != DictApplication::STATUS_ACTIVE || isset($loan) && $loan->status == Dict::LOAN_STATUS_CLOSED) { if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT || $this->user->id_user_role == Dict::USER_ROLE_ADVISOR) { $this->redirect(['/application/view', 'id' => $app_task->id_application]); } else { if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) { $this->redirect(['/loan/application']); } } return false; } } // 判断 id_app_form_collateral_account 权限 if (isset($_GET['id_app_form_collateral_account'])) { $collateral_account = AppFormCollateralAccount::findOne($_GET['id_app_form_collateral_account']); if (!$collateral_account->application->checkOnwerAccess($this->user->id_user)) { if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT) { $this->AUTH = Dict::AUTH_READ; } else { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } } else { $this->AUTH = Dict::AUTH_OPERATE; } } // 判断 id_app_task_checkpoint 权限 if (isset($_GET['id_app_task_checkpoint'])) { $checkpoint = AppTaskCheckpoint::findOne($_GET['id_app_task_checkpoint']); if (!$checkpoint->appTask->application->checkOnwerAccess($this->user->id_user) || !AppTask::checkOnwerAccess($checkpoint->appTask, $behaviour)) { if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT) { $this->AUTH = Dict::AUTH_READ; } else { throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page."); } } else { $this->AUTH = Dict::AUTH_OPERATE; } } } return true; }
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_WETSIGNED_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(); } } }
public static function taskNotification($type, $id_application, $id_app_task, $app_task_type, $is_docusign) { if ($id_app_task != 0) { $model = AppTask::findOne($id_app_task); $id_application = $model->id_application; } $subject = DictEmail::$emailType[$type]; $template = 'taskNotification'; $user = static::findUserByApplication($id_application); switch ($app_task_type) { case DictTask::TYPE_APPLICATION_FORM: $to_user = $user['advisor']; break; //application form //application form case DictTask::TYPE_UPLOAD_WETSIGNED_FORM: $to_user = $user['advisor']; break; //upload wetsigned form //upload wetsigned form case DictTask::TYPE_SUPPLEMENTAL_MATERIALS: $to_user = $user['advisor']; break; //supplemental materials //supplemental materials case DictTask::TYPE_APPLICATION_REVIEW: $to_user = $user['supernova']; if ($is_docusign == DictTask::DOCUSIGN_NOTIFICATION) { //完成e-sign后 is_null($user['co_applicant']) ? $id_app_task = $id_app_task + 3 : ($id_app_task = $id_app_task + 4); } else { //手动上传文档 is_null($user['co_applicant']) ? $id_app_task = $id_app_task + 9 : ($id_app_task = $id_app_task + 10); } break; //application review //application review case DictTask::TYPE_LINE_AGREEMENTS: $to_user = $user['supernova']; break; case DictTask::TYPE_LINE_SETUP: $to_user = $user['supernova']; if ($is_docusign == DictTask::DOCUSIGN_NOTIFICATION) { //完成e-sign后 is_null($user['co_applicant']) ? $id_app_task = $id_app_task + 2 : ($id_app_task = $id_app_task + 3); } else { //手动上传文档 is_null($user['co_applicant']) ? $id_app_task = $id_app_task + 3 : ($id_app_task = $id_app_task + 4); } break; //line setup } return ['user' => $to_user, 'subject' => $subject, 'template' => $template, 'id_application' => $id_application, 'id_app_task' => $id_app_task, 'app_task_type' => $app_task_type]; }
public static function recipient($id_application, $response, $id_app_task_type) { if (isset($response->envelopeId)) { $eSignTasks = AppTask::find()->where(['id_application' => $id_application, 'active' => DictTask::ACTIVE, 'id_app_task_type' => $id_app_task_type])->all(); foreach ($eSignTasks as $task) { $docusign = new DocusignRecipient(); $docusign->id_application = $id_application; $docusign->id_envelope = $response->envelopeId; $docusign->id_app_task = $task->id_app_task; $docusign->id_user = $task->id_user; $docusign->email = $task->user->email; $docusign->status = 0; $docusign->save(false); } } return true; }
public function actionCheck($id_app_task) { $model = AppTask::findOne($id_app_task); // 判断是否可以 approve $loanModel = Loan::find()->where(['id_application' => $model->id_application])->one(); $loanModel->setScenario('review'); $loan_ctrl = $loanModel->validate(); // check points $checkPoints = AppTaskCheckpoint::find()->where(['id_app_task' => $id_app_task])->all(); return $this->renderAjax('check', ['model' => $model, 'loan_ctrl' => $loan_ctrl, 'checkPoints' => $checkPoints]); }
public function actionCheck($id_app_task) { $model = AppTask::findOne($id_app_task); //find by document type $loanAgreements = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_LINE_AGREEMENT, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->one(); $g3 = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_G3, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->one(); $w9 = AppDocument::find()->andWhere(['id_document_type' => DictDocument::TYPE_W9, 'id_application' => $model->id_application])->orderBy(['id_app_document' => SORT_DESC])->one(); return $this->renderAjax('check', ['model' => $model, 'loanAgreements' => $loanAgreements, 'g3' => $g3, 'w9' => $w9]); }