public function actionPartner()
 {
     $model = new \app\modules\cms\models\Partner();
     $items = $model->invitedList();
     $historyList = \app\modules\cms\models\BalanceHistory::getByUserId();
     return $this->render('partner', ['items' => $items, 'historyList' => $historyList]);
 }
 public function actionActivate($cvcode)
 {
     /**
      * @var $model \app\modules\discount\models\Card
      */
     $model = Card::findByCvcode($cvcode);
     if (!$model) {
         throw new HttpException('404', 'Карта с таким кодом не найдена!');
     }
     $user = new User();
     $user->scenario = 'client.create';
     $user->role = 'client';
     $profile = new Profile();
     $profile->scenario = 'client.create';
     $partner = new \app\modules\cms\models\Partner();
     $partner->scenario = 'card.activate';
     $partner->load($_POST);
     $partnerValidate = $partner->email ? $partner->validate() : true;
     //        var_dump($partnerValidate);
     if ($user->load($_POST) && $profile->load($_POST) && $partnerValidate) {
         $model->status = Card::STATUS_ACTIVE;
         $user->dateCreate = date(DATE_FORMAT_DB);
         if ($user->save()) {
             $model->userId = $user->id;
             $profile->file = UploadedFile::getInstance($profile, 'file');
             $profile->userId = $user->id;
             if ($profile->file) {
                 $filename = $user->id . '.' . $profile->file->extension;
                 $filepath = \Yii::getAlias(Profile::PHOTO_DIR_ALIAS) . '/' . $filename;
                 $profile->file->saveAs($filepath, false);
                 $profile->photo = $filename;
             }
             $profile->save();
             $model->dateActivate = date('Y-m-d H:i:s');
             $model->save(false, ['status', 'userId', 'dateActivate']);
             if ($partnerValidate) {
                 $partner->create($user);
             }
             $loginModel = new \app\models\LoginForm();
             $loginModel->username = $user->username;
             $loginModel->password = $user->password2;
             $loginModel->login();
             $this->redirect(['card', 'cvcode' => $cvcode]);
         }
     }
     return $this->render('activate', ['model' => $model, 'user' => $user, 'profile' => $profile, 'partner' => $partner]);
 }