/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DotaDraft::find()->joinWith('user')->joinWith('fantasy'); $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; } $query->andFilterWhere(['id' => $this->id, 'fantasy_id' => $this->fantasy_id, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getDotaDraft() { return $this->hasOne(DotaDraft::className(), ['id' => 'draft_id']); }
/** * Finds the DotaDraft model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DotaDraft the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DotaDraft::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * добавляет в базу новую ставку * * @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; }
private function showFantasyList($draft_id = 0, $meta_type = 'dota2-main') { $current_action = Yii::$app->controller->action->id; $fantasy_type = Yii::$app->request->get('type', 'all'); $DotaDraft = new DotaDraft(); $params = []; if ($draft_id > 0) { $params['DotaFantasySearch'] = ['draft_id' => $draft_id]; } $searchModel = new DotaFantasySearch(); $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; } if (count($fantasy_ids)) { $drafts_counts = $DotaDraft->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 = $DotaDraft->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, 'draft_id' => $draft_id, 'user_rates' => $user_rates, 'drafts_counts' => $drafts_counts, 'meta_info' => $meta_info]); }
/** * * @return \yii\db\ActiveQuery */ public function getDraftUser() { return $this->hasOne(DotaDraft::className(), ['fantasy_id' => 'id'])->where('user_id = :user_id', [':user_id' => Yii::$app->user->id]); }
/** * считает кол-во очков по смешанному драфту * @param $fantasy array * @param $rates array */ private static function calculateScoresInMixedDraft($fantasy, $rates) { $draft_ids = $draft_info = []; $DotaDraft = new DotaDraft(); foreach ($rates as $rate) { $draft_ids[] = $rate['draft_id']; } $draft_info_heroes = DotaDraftHero::getDraftsInfo($draft_ids); $draft_info_players = DotaDraftPlayer::getDraftsInfo($draft_ids); //echo'<pre>';print_r($draft_info_heroes);echo'</pre>';//die; //echo'<pre>';print_r($draft_info_players);echo'</pre>';//die; foreach ($draft_info_heroes as $key => $row) { $draft_info[$key]['heroes'] = $row; } foreach ($draft_info_players as $key => $row) { $draft_info[$key]['players'] = $row; } //echo'<pre>';print_r($draft_info);echo'</pre>';die; foreach ($draft_info as $draft_id => $row) { $DotaDraft->setScoresForMixedDraft($draft_id, $fantasy['event_id'], $row); } //die; }