/**
  * @inheritdoc
  */
 public function apply($model)
 {
     if ($this->isDue() && in_array($model->ClassID, [6, 12])) {
         $userID = $model->contractor->id;
         \Yii::info('Проверка и применение акции "' . self::$name . '"' . "({$this->getModel()->id})" . ' для пользователя ' . Html::a($userID, ['/user/admin/update', 'id' => $userID]), 'info');
         $settings = $this->getModel()->parseSettings();
         if (empty($settings['attributes'])) {
             return false;
         }
         ArrayHelper::multisort($settings['attributes'], 'payment', SORT_DESC);
         $account = $model->contractor->account;
         foreach ($settings['attributes'] as $attributes) {
             $discount = $this->getModel()->getDiscount();
             $discount->setAttributes($attributes);
             if ($model->CashSum >= $discount->payment) {
                 \Yii::info('Применение акции с атрибутами: ' . Json::encode($attributes), 'info');
                 $account->BonusGames = $account->BonusGames + $discount->bonusGamesCount;
                 if ($account->save(false, ['BonusGames'])) {
                     $finance = new FinanceRecord();
                     $finance->CashSum = 0;
                     $finance->ClassID = 21;
                     //Начисление бонусов
                     $finance->ContractorID = $model->ContractorID;
                     $finance->Comment = $this->getDescription();
                     $finance->save();
                     return true;
                 }
             }
         }
     } else {
         //            var_export(in_array($model->ClassID, [6, 12]));
     }
     return false;
 }
 /**
  * Creates a new FinanceRecord model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new FinanceRecord();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->ID]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }