예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 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]);
 }
예제 #3
0
 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 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();
         }
     }
 }