Example #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 actionCheckPoint($id_app_task_checkpoint)
 {
     $model = AppTaskCheckpoint::findOne($id_app_task_checkpoint);
     if (Yii::$app->request->post()) {
         $model->status = true;
         $model->save(false);
         if ($model->save(false)) {
             if ($model->id_app_task_checkpoint_type == DictTask::LINE_IS_SET_UP) {
                 //对line-setup的checkout操作
                 //active log.checkout line-setup
                 Active::operationLog($model->appTask->id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, DictTask::$taskType[DictTask::TYPE_LINE_SETUP], ''], DictActive::USER_UPDATE_TASK, Yii::$app->user->getIdentity()->id);
             } else {
                 //其余三个都是application-review的checkout
                 foreach (DictTask::$checkPointType as $key => $val) {
                     switch ($model->id_app_task_checkpoint_type) {
                         //active log.checkout application-review
                         case $key:
                             Active::operationLog($model->appTask->id_application, [Yii::$app->user->getIdentity()->first_name, Yii::$app->user->getIdentity()->last_name, DictTask::$checkPointType[$model->id_app_task_checkpoint_type], DictTask::$taskType[DictTask::TYPE_APPLICATION_REVIEW]], DictActive::USER_REVIEWD_CHECK_POINT, Yii::$app->user->getIdentity()->id);
                     }
                 }
             }
         }
         return $this->redirect(AppTask::getSectionsUrl($model->appTask));
     }
     return $this->renderAjax('check_point', ['model' => $model]);
 }
 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_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();
         }
     }
 }