/** * добавляет в базу новую ставку * @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); } }
public function getInfos(&$dataProvider) { $arFantasies = []; foreach ($dataProvider->models as $model) { $arFantasies[$model->game][] = $model->fantasy_id; } //echo'<pre>';print_r($arFantasies);echo'</pre>';//die; foreach ($arFantasies as $game => $fanrasies) { switch ($game) { case GamesParams::GAME_DOTA: $fantasyModel = new DotaFantasy(); $draftModel = new DotaDraft(); break; case GamesParams::GAME_POKER: $fantasyModel = new PokerFantasy(); $draftModel = new PokerDraft(); break; } $fantasiesList = $fantasyModel->getFantasiesFromIds($fanrasies); $drafts_counts = $draftModel->getDraftsCount($fanrasies); //echo'<pre>';print_r($drafts_counts);echo'</pre>';//die; foreach ($dataProvider->models as $model) { if ($model->game == $game) { foreach ($fantasiesList as $item) { if ($item['id'] == $model->fantasy_id) { $model->info = $item; } } foreach ($drafts_counts as $id => $item) { if ($id == $model->fantasy_id) { $model->info['drafts_counts'] = $item; } } } } } return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PokerDraft::find()->joinWith('user')->joinWith('fantasy'); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'fantasy_id' => $this->fantasy_id, 'user_id' => $this->user_id, 'scores' => $this->scores, 'position' => $this->position, 'prize' => $this->prize, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); return $dataProvider; }
/** * Finds the PokerDraft model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PokerDraft the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PokerDraft::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getDraft() { return $this->hasOne(PokerDraft::className(), ['id' => 'draft_id']); }
private function showFantasyList($meta_type = 'poker-main') { $current_action = Yii::$app->controller->action->id; $fantasy_type = Yii::$app->request->get('type', 'all'); //echo $fantasy_type; $params = []; $searchModel = new PokerFantasySearch(); $dataProvider = $searchModel->search($params, $fantasy_type); //echo'<pre>';print_r(Yii::$app->user->id);echo'</pre>';die; $fantasy_ids = []; foreach ($dataProvider->models as $model) { $fantasy_ids[] = $model->id; } $PokerDraft = new PokerDraft(); if (count($fantasy_ids)) { $drafts_counts = $PokerDraft->getDraftsCount($fantasy_ids); } else { $drafts_counts = []; } //echo'<pre>';print_r($drafts_counts);echo'</pre>';die; if (Yii::$app->user->isGuest) { $user_rates = []; } else { $user_rates = $PokerDraft->getUserRateList(Yii::$app->user->id); } //echo'<pre>';print_r($user_rates);echo'</pre>';die; $meta_info = MetaInfo::getMetaInfo($meta_type); return $this->render('fantasy-list', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'current_action' => $current_action, 'fantasy_type' => $fantasy_type, 'user_rates' => $user_rates, 'drafts_counts' => $drafts_counts, 'meta_info' => $meta_info]); }
/** * * @return \yii\db\ActiveQuery */ public function getDraftUser() { return $this->hasOne(PokerDraft::className(), ['fantasy_id' => 'id'])->where('user_id = :user_id', [':user_id' => Yii::$app->user->id]); }