/**
  * добавляет в базу новую ставку
  * @param Model $fantasy
  */
 public function addRate($fantasy)
 {
     $draftModel = new PokerDraft();
     $PokerDraftPlayer = new PokerDraftPlayer();
     $draftModel->attributes = $this->attributes;
     $draftModel->save();
     //echo'<pre>'; print_r($draftModel);echo'</pre>';die;
     $PokerDraftPlayer->addPlayersRows($this->players, $draftModel->id);
     //снимаем взнос+комиссия у игрока
     $user = User::findOne(Yii::$app->user->id);
     $deposit_before = $user->deposit;
     $user->deposit = $user->deposit - $fantasy->deposit - $fantasy->fee;
     if ($user->save()) {
         //заносим в лог
         $data = ['fantasy_id' => $fantasy->id, 'game' => Transaction::TR_GAME_POKER];
         $trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
         Transaction::saveTransaction($user->id, $deposit_before, -($fantasy->deposit + $fantasy->fee), $trans_descr);
     }
     //если нужно - увеличиваем призовой фонд
     //$total_sum_rates = PokerDraft::getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     $total_sum_rates = $draftModel->getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     if ($total_sum_rates > $fantasy->prize_pool_real) {
         PokerFantasy::upateRealPrizePool($fantasy->id, $total_sum_rates);
     }
 }
 /**
  * добавляет в базу новую ставку
  *
  * @param $fantasy
  * @return bool
  */
 public function addRate($fantasy)
 {
     $draftModel = new DotaDraft();
     $draftModel->attributes = $this->attributes;
     if ($draftModel->save() === false) {
         return false;
     }
     //echo'<pre>'; print_r($draftModel);echo'</pre>';die;
     switch ($this->scenario) {
         case self::SCENARIO_MIXED_DRAFT:
             $DotaDraftPlayer = new DotaDraftPlayer();
             $DotaDraftHero = new DotaDraftHero();
             $DotaDraftPlayer->addPlayersRows($this->players, $draftModel->id, $this->draft_slots);
             $DotaDraftHero->addHeroesRows($this->heroes, $draftModel->id);
             break;
         case self::SCENARIO_PLAYERS_DRAFT:
             $DotaDraftPlayer = new DotaDraftPlayer();
             $DotaDraftPlayer->addPlayersRows($this->players, $draftModel->id, $this->draft_slots);
             break;
         case self::SCENARIO_HEROES_DRAFT:
             $DotaDraftHero = new DotaDraftHero();
             $DotaDraftHero->addHeroesRows($this->heroes, $draftModel->id);
             break;
     }
     //снимаем взнос+комиссия у игрока
     $user = User::findOne(Yii::$app->user->id);
     $deposit_before = $user->deposit;
     $user->deposit = $user->deposit - $fantasy->deposit - $fantasy->fee;
     if ($user->save() === false) {
         $draftModel->delete();
         //если возникла ошибка - удаляем из базы ставку пользователя
         return false;
     }
     //заносим в лог
     $data = ['fantasy_id' => $fantasy->id, 'game' => Transaction::TR_GAME_DOTA];
     $trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
     Transaction::saveTransaction($user->id, $deposit_before, -($fantasy->deposit + $fantasy->fee), $trans_descr);
     //если нужно - увеличиваем призовой фонд
     $total_sum_rates = $draftModel->getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     if ($total_sum_rates > $fantasy->prize_pool_real) {
         DotaFantasy::upateRealPrizePool($fantasy->id, $total_sum_rates);
     }
     return true;
 }
 public function actionTransactions()
 {
     echo '<pre>';
     print_r('actionTransactions');
     echo '</pre>';
     //die;
     $user_id = 19;
     $data = ['fantasy_id' => 7];
     $trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
     echo '<pre>$trans_descr ';
     print_r($trans_descr);
     echo '</pre>';
     //die;
     $deposit_before = User::getDepositValue($user_id);
     $value = 10.9;
     echo '<pre>$deposit_before ';
     print_r($deposit_before);
     echo '</pre>';
     //die;
     //Transaction::saveTransaction($user_id, $deposit_before, $value, $trans_descr);
     $trans_txt = Transaction::buildTransactionDescr($trans_descr);
     echo '<pre>$trans_txt ';
     print_r($trans_txt);
     echo '</pre>';
     //die;
     die;
 }