/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Betterdebt::find(); if (!isset($params['sort'])) { $query->orderBy(['id_betterdebt' => SORT_DESC]); } $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id_betterdebt' => $this->id_betterdebt, 'id_user' => $this->id_user, 'is_in_service_team' => $this->is_in_service_team, 'is_primary_service_member' => $this->is_primary_service_member, 'delete' => $this->delete, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'betterdebt_id', $this->betterdebt_id])->andFilterWhere(['like', 'phone', $this->phone]); return $dataProvider; }
public function getUsers() { $users = []; // 找到 advisor if (isset($this->advisors)) { foreach ($this->advisors as $val) { $users[] = $val->user; } } // 找到 applicant if (isset($this->appApplicants)) { foreach ($this->appApplicants as $val) { $users[] = $val->user; } } // 找到 supernova $supernovas = Betterdebt::find()->andWhere(['is_in_service_team' => Dict::BD_SERVICE_TEAM_YES])->all(); if (isset($supernovas)) { foreach ($supernovas as $val) { $users[] = $val->user; } } return $users; }
/** * 将加入service team的次要的supernova用户设置为primary loan officer * @param integer $id * @return mixed */ public function actionPrimary($id) { $model = $this->findModel($id); $model->is_primary_service_member = Dict::BD_PRIMARY_MEMBER_YES; /** * 如果选择了设置为primary loan officer,则将其他的自动调回不是primary */ $result = Betterdebt::updateAll(['is_primary_service_member' => Dict::BD_PRIMARY_MEMBER_NOT], "id_betterdebt not in ({$id}) "); if ($result != 0) { //$result 返回的被修改的行数 $model->save(); } return $this->redirect(['index']); }
}], ['label' => 'Group Name', 'value' => function ($model) { if ($model->group) { return $model->group->group_id; } }], ['class' => 'common\\widgets\\ActionColumn', 'template' => '{invite}{view}', 'width' => '15%', 'buttons' => ['invite' => function ($url, $model, $key) { if ($model->user) { if ($model->user->status == 0) { $options = ['class' => 'btn btn-light btn-icon', 'title' => Yii::t('yii', 'Invite'), 'aria-label' => Yii::t('yii', 'Invite'), 'data-confirm' => Yii::t('yii', 'Are you sure invite this client to email?'), 'data-pjax' => '0']; return Html::a('<span class="glyphicon"></span>', $url, $options); } } }, 'cancelinvite' => function ($url, $model, $key) { $options = ['class' => 'btn btn-light btn-icon', 'title' => Yii::t('yii', 'Cancel Invition'), 'aria-label' => Yii::t('yii', 'Cancel Invition'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to cancel invition?'), 'data-pjax' => '0']; return Html::a('<span class="glyphicon"></span>', $url, $options); }, 'view' => function ($url, $model, $key) { $betterdebt = Betterdebt::find()->andWhere(['id_user' => Yii::$app->user->getId()])->one(); $options = ['class' => 'btn btn-light btn-icon', 'title' => Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_ADVISOR || Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_BETTERDEBT && $betterdebt->is_in_service_team == Dict::BD_SERVICE_TEAM_NOT ? Yii::t('yii', 'View') : Yii::t('yii', 'Update'), 'aria-label' => Yii::t('yii', 'View'), 'data-pjax' => '0']; if (Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_ADVISOR || Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_BETTERDEBT && $betterdebt->is_in_service_team == Dict::BD_SERVICE_TEAM_NOT) { return Html::a('<span class="glyphicon"></span>', Url::to(['/client/update', 'id' => $model->id_client]), $options); } else { if (Yii::$app->user->getIdentity()->id_user_role == Dict::USER_ROLE_BETTERDEBT && $betterdebt->is_in_service_team == Dict::BD_SERVICE_TEAM_YES) { return Html::a('<span class="glyphicon"></span>', Url::to(['/client/update', 'id' => $model->id_client]), $options); } } }], 'detailViewAttributes' => function ($model, $key) { return ['id_client', ['label' => 'Group Name', 'value' => $model->group ? $model->group->group_id : ''], 'client_id']; }]]]); ?> </div> </div>
public static function createByApplication($application) { $primaryAppApplicant = $application->primaryAppApplicant; $coAppApplicant = $application->coAppApplicant; $primaryAdvisor = $application->primaryAdvisor; $primarySupernova = $application->primarySupernova; $appUserModel = new self(); $appUserModel->id_application = $application->id_application; $primaryClientUserModel = clone $appUserModel; $primaryClientUserModel->id_user = $primaryAppApplicant->id_user; $primaryClientUserModel->is_primary_contact = 1; $primaryClientUserModel->save(); if ($application->is_joint_application) { $coClientUserModel = clone $appUserModel; $coClientUserModel->id_user = $coAppApplicant->id_user; $coClientUserModel->is_primary_contact = 0; $coClientUserModel->save(); } foreach ($application->group->advisors as $advisorModel) { $model = clone $appUserModel; $model->id_user = $advisorModel->id_user; if ($advisorModel->id_user == $primaryAdvisor->id_user) { $model->is_primary_contact = 1; } else { $model->is_primary_contact = 0; } $model->save(); } $betterdebts = Betterdebt::find()->andWhere(['is_in_service_team' => Dict::BD_SERVICE_TEAM_YES])->all(); foreach ($betterdebts as $betterdebt) { $model = clone $appUserModel; $model->id_user = $betterdebt->id_user; if ($betterdebt->id_user == $primarySupernova->id_user) { $model->is_primary_contact = 1; } else { $model->is_primary_contact = 0; } $model->save(); } return true; }
public function getInfo() { switch ($this->id_user_role) { case Dict::USER_ROLE_BETTERDEBT: return $this->hasOne(Betterdebt::classname(), ['id_user' => 'id_user']); break; case Dict::USER_ROLE_ADVISOR: return $this->hasOne(Advisor::classname(), ['id_user' => 'id_user']); break; case Dict::USER_ROLE_CLIENT: return $this->hasOne(Client::classname(), ['id_user' => 'id_user']); break; case Dict::USER_ROLE_BANK: return $this->hasOne(BankUser::classname(), ['id_user' => 'id_user']); break; default: return null; break; } }
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; }