/** * добавляет в базу новую ставку * @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); } }
/** * @return \yii\db\ActiveQuery */ public function getDraftPlayers() { return $this->hasMany(PokerDraftPlayer::className(), ['draft_id' => 'id']); }