Пример #1
0
 /**
  * Creates a new Client model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Client();
     $userModel = new User();
     if (Yii::$app->request->isAjax && $userModel->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($userModel);
     }
     if ($model->load(Yii::$app->request->post()) && $userModel->load(Yii::$app->request->post())) {
         $arr = ['User' => $_POST['User'], 'Client' => $_POST['Client']];
         $result = User::createUser($this->_roleId, $arr);
         if ($result) {
             return $this->redirect(['index']);
         } else {
             return $this->render('create', ['model' => $model, 'userModel' => $userModel]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'userModel' => $userModel]);
     }
 }
Пример #2
0
 public function actionCreate()
 {
     $model = new Client();
     $userModel = new User();
     //validate email unique
     if (Yii::$app->request->isAjax && $userModel->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($userModel);
     }
     //     		$group = Advisor::findGroupByAdvisor($this->user->id_extend);
     if ($model->load(Yii::$app->request->post())) {
         $user = User::createUser(Dict::USER_ROLE_CLIENT, ['User' => Yii::$app->request->post('User'), 'Client' => Yii::$app->request->post('Client')]);
         if ($user) {
             return $this->redirect(['index']);
         }
     } else {
         return $this->render('create', ['model' => $model, 'userModel' => $userModel]);
     }
 }
 /**
  * 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]);
 }
Пример #4
0
 /**
  * add advisor
  */
 public function actionAddAdvisor($id = null)
 {
     $model = new Advisor();
     $userModel = new User();
     //validate email unique
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && $userModel->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return array_merge(ActiveForm::validate($userModel), ActiveForm::validate($model));
     }
     if ($model->load(Yii::$app->request->get()) && $userModel->load(Yii::$app->request->get())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $user = User::createUser(Dict::USER_ROLE_ADVISOR, ['User' => $_GET['User'], 'Advisor' => $_GET['Advisor']]);
         if ($user) {
             if (!empty($id)) {
                 $advisorGroup = new AdvisorGroup();
                 $advisorGroup->id_group = $id;
                 $advisorGroup->id_advisor = $user->advisor->id_advisor;
                 $advisorGroup->save();
             }
             return true;
         } else {
             return false;
         }
     }
     return $this->renderAjax('add_advisor', ['model' => $model, 'user' => $userModel, 'id' => $id]);
 }