/**
  * Step 3
  * @param $hardId
  * @return string|\yii\web\Response
  * @throws HttpException
  */
 public function actionCreateAccount($hardId, $groupId = '')
 {
     /** @var PersonsGroupRecord $group */
     if ($groupId !== '') {
         $group = PersonsGroupRecord::findOne($groupId);
     } else {
         $group = PersonsGroupRecord::getDefault();
     }
     /** @var PersonsRecord $user */
     $user = Yii::createObject(['class' => PersonsRecord::className(), 'scenario' => 'create']);
     /** @var CardForm $card */
     $card = \Yii::createObject(CardForm::className());
     $card->HardID = $hardId;
     if (!$card->isExist()) {
         $card = $card->create();
     } else {
         $card = $card->find();
     }
     if (!$card->ID) {
         throw new HttpException(400, 'Не удалось сохранить номер карты');
     }
     $user->CardID = $card->id;
     $user->GroupID = $group->id;
     $user->ServiceCard = $group->IsService;
     $this->performAjaxValidation($user);
     if ($user->load(Yii::$app->request->post()) && $user->create()) {
         /** @var FinanceRecord $finance */
         $finance = Yii::createObject(FinanceRecord::className());
         $finance->ClassID = 2;
         //Регистраци карты
         $finance->ContractorID = $user->ID;
         $finance->save();
         Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User has been created'));
         return $this->redirect(['/accounts/charge-balance', 'id' => $user->account->id]);
     }
     return $this->render('createAccount', ['user' => $user]);
 }
Exemplo n.º 2
0
 public function actionCreateAccount($hardId, $groupId = '')
 {
     /** @var PersonsGroupRecord $group */
     if ($groupId !== '') {
         $group = PersonsGroupRecord::findOne($groupId);
     } else {
         $group = PersonsGroupRecord::getDefault();
     }
     /** @var PersonsRecord $user */
     $user = Yii::$app->user->identity;
     if ($group->ID < $user->GroupID) {
         throw new ForbiddenHttpException('Вы не можете зарегистрировать карту более высокого уровня');
     }
     /** @var PersonsRecord $user */
     $user = Yii::createObject(['class' => PersonsRecord::className(), 'scenario' => 'create']);
     $user->GroupID = $group->id;
     $user->ServiceCard = $group->IsService;
     //from parent controller (not my behavior)
     $this->performAjaxValidation($user);
     //data already loaded with ajax validation
     if ($user->load(Yii::$app->request->post()) && $user->validate()) {
         $card = null;
         /** @var CardForm $card */
         $cardForm = \Yii::createObject(CardForm::className());
         $cardForm->HardID = $hardId;
         if (!$cardForm->isExist()) {
             $card = $cardForm->create();
         } else {
             if ($cardForm->isUsed()) {
                 throw new HttpException(400, 'Данная карта уже зарегистрирована в системе');
             } else {
                 $card = $cardForm->find();
             }
         }
         if (!$card->ID) {
             throw new HttpException(400, 'Не удалось зарегистрировать карту');
         }
         $user->CardID = $card->id;
         if ($user->create()) {
             /** @var FinanceRecord $finance */
             $finance = Yii::createObject(FinanceRecord::className());
             $finance->ClassID = 2;
             //Регистраци карты
             $finance->ContractorID = $user->ID;
             $finance->save();
             //Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User has been created'));
             return $this->redirect(['/person/children', 'personId' => $user->id]);
         }
     }
     return $this->render('createAccount', ['user' => $user]);
 }
Exemplo n.º 3
0
 public function actionChangeCardSwipe($id, $broken = false)
 {
     /** @var PersonsRecord $user */
     $user = $this->findModel($id);
     /** @var CardForm $model */
     $model = \Yii::createObject(CardForm::className());
     if ($model->load(Yii::$app->request->post(), '') && $model->validate()) {
         if (!$model->isExist()) {
             $card = $model->create();
         } else {
             $card = $model->find();
         }
         if ($user->CardID !== $card->ID) {
             $personGroup = $user->group;
             if ($broken && null !== $personGroup && $personGroup->CardRepairCost > 0) {
                 if ($user->account->Money < $personGroup->CardRepairCost) {
                     throw new HttpException(400, 'У вас не достаточно средств для замены карты. Стоимость замены карты: ' . Yii::$app->formatter->asCurrency($personGroup->CardRepairCost));
                 } else {
                     if (!$user->updateAttributes(['CardID' => $card->ID])) {
                         throw new HttpException(400, 'Не удалось обновить номер карты');
                     }
                     $user->account->Money = $user->account->Money - $personGroup->CardRepairCost;
                     if ($user->account->save(false, ['Money'])) {
                         /** @var FinanceRecord $finance */
                         $finance = Yii::createObject(['class' => FinanceRecord::className()]);
                         $finance->ClassID = 19;
                         //Плата за восстановление карты
                         $finance->CashSum = $personGroup->CardRepairCost;
                         $finance->ContractorID = $id;
                         $finance->Comment = "Замена карты для пользователя " . Html::a($id, ['/user/admin/update', 'id' => $id]);
                         Yii::getLogger()->log($finance->Comment, Logger::LEVEL_WARNING);
                         $finance->save();
                     }
                     $flashMsg = 'Замена карты выполнена, со счета сянто: ' . Yii::$app->formatter->asCurrency($personGroup->CardRepairCost);
                     Yii::getLogger()->log($flashMsg, Logger::LEVEL_WARNING);
                     Yii::$app->getSession()->setFlash('success', $flashMsg);
                 }
             } else {
                 if (!$user->updateAttributes(['CardID' => $card->ID])) {
                     throw new HttpException(400, 'Не удалось обновить номер карты');
                 }
                 Yii::getLogger()->log("Замена карты для пользователя " . Html::a($id, ['/user/admin/update', 'id' => $id]), Logger::LEVEL_WARNING);
                 Yii::getLogger()->log('Замена карты выполнена', Logger::LEVEL_WARNING);
                 Yii::getLogger()->log('Замена карты выполнена', Logger::LEVEL_WARNING);
             }
         } else {
             throw new HttpException(400, 'Проведите другую карту');
         }
     } else {
         throw new HttpException(400, $model->getFirstError('HardID'));
     }
     return $this->redirect(['/user/admin/update', 'id' => $id]);
 }