本文整理汇总了PHP中Game::whereRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::whereRaw方法的具体用法?PHP Game::whereRaw怎么用?PHP Game::whereRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game::whereRaw方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
while (true) {
$date = new DateTime();
$games = Game::whereRaw('date < ? && winner_id IS NULL', array(new DateTime()))->get();
if (count($games) > 0) {
$response = Unirest::get("http://live.mobileapp.fifa.com/api/wc/matches");
foreach ($games as $value) {
//On regarde tout les matchs de la liste retourné par l'API
foreach ($response->body->data->second as $match) {
//Si le match corespond a celui qu'on veut mettre à jour
if (isset($match->c_HomeNatioShort) && isset($match->c_AwayNatioShort) && $match->c_HomeNatioShort == $value->team1()->first()->code && $match->c_AwayNatioShort == $value->team2()->first()->code) {
//Si le match à commencé
if ($match->b_Started == true) {
$value->team1_goals = $match->n_HomeGoals;
$value->team2_goals = $match->n_AwayGoals;
$this->info('[' . $date->format('Y-m-d H:i:s') . '] MAJ scores : ' . $value->team1()->first()->name . ' ' . $value->team1_goals . '-' . $value->team2_goals . ' ' . $value->team2()->first()->name . '.');
}
if ($match->b_Finished == true) {
if ($value->team1_goals > $value->team2_goals) {
$value->setFinished(1);
$this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team1()->first()->name . ' gagnant.');
} else {
if ($value->team1_goals < $value->team2_goals) {
$value->setFinished(2);
$this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team2()->first()->name . ' gagnant.');
} else {
if ($value->team1_goals == $value->team2_goals) {
$value->team1_kick_at_goal = $match->n_HomeGoalsShootout;
$value->team2_kick_at_goal = $match->n_AwayGoalsShootout;
if ($match->n_HomeGoalsShootout > $match->n_AwayGoalsShootout) {
$value->setFinished(1);
$this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team1()->first()->name . ' gagnant.');
} else {
$value->setFinished(2);
$this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team2()->first()->name . ' gagnant.');
}
}
}
}
}
break;
}
}
$value->save();
}
} else {
$this->info('[' . $date->format('Y-m-d H:i:s') . '] Aucun match à surveiller.');
}
sleep(50);
}
}
示例2: setRound
private function setRound()
{
$start_stage_id = Stage::getStartStage()->id;
$next_stage_id = $start_stage_id;
while ($next_stage_id) {
$games = array();
$this->labels[] = Stage::find($next_stage_id)->name;
$next_stage_id_tmp = Stage::find($next_stage_id)->next_stage;
foreach (Game::whereRaw('stage_id = ?', array($next_stage_id))->orderBy('stage_game_num', 'ASC')->get() as $value) {
$score1 = $value->team1_goals;
$score2 = $value->team2_goals;
if ($value->team1_kick_at_goal != null && $value->team2_kick_at_goal != null) {
$score1 .= " (" . $value->team1_kick_at_goal . ")";
}
if ($value->team1_kick_at_goal != null && $value->team2_kick_at_goal != null) {
$score2 .= " (" . $value->team2_kick_at_goal . ")";
}
$games[] = array(array('name' => $value->team1()->first() ? $value->team1()->first()->name : "-", 'id' => $value->team1_id, 'score' => $score1), array('name' => $value->team2()->first() ? $value->team2()->first()->name : "-", 'id' => $value->team2_id, 'score' => $score2));
}
$this->rounds[] = $games;
if ($next_stage_id_tmp == null) {
$gamme = Game::whereRaw('stage_id = ? && stage_game_num = 1', array($next_stage_id))->first();
//Vinqueur
$this->rounds[] = array(array(array('name' => $gamme->winner()->first() ? $gamme->winner()->first()->name : "-", 'id' => $gamme->winner_id)));
}
$next_stage_id = $next_stage_id_tmp;
}
/////////////////////////////////////////////////
//******************* 3e place ****************//
/////////////////////////////////////////////////
$stage_third = Stage::getThirdStage()->id;
$gamme_third = Game::whereRaw('stage_id = ?', array($stage_third))->first();
if ($gamme_third != null) {
$score1 = $value->team1_goals;
$score2 = $value->team2_goals;
if ($gamme_third->team1_kick_at_goal != null && $gamme_third->team2_kick_at_goal != null) {
$score1 .= " (" . $gamme_third->team1_kick_at_goal . ")";
}
if ($gamme_third->team1_kick_at_goal != null && $gamme_third->team2_kick_at_goal != null) {
$score2 .= " (" . $gamme_third->team2_kick_at_goal . ")";
}
$this->third[] = array(array(array('name' => $gamme_third->team1()->first() ? $gamme_third->team1()->first()->name : "-", 'id' => $gamme_third->team1_id, 'score' => $score2), array('name' => $gamme_third->team2()->first() ? $gamme_third->team2()->first()->name : "-", 'id' => $gamme_third->team2_id, 'score' => $score2)));
//Vinqueur 3e place
$this->third[] = array(array(array('name' => $gamme_third->winner()->first() ? $gamme_third->winner()->first()->name : "-", 'id' => $gamme_third->winner_id)));
}
}
示例3: setFinished
public function setFinished($num_team)
{
//Si l'équipe une a gagnée, on redistribue les points pour les paris corrects (paris sur l'équipe une)
if ($num_team == 1) {
foreach (Bet::whereRaw('game_id = ? && winner_id = ?', array($this->id, $this->team1_id))->get() as $bet) {
$cote = $this->getTeam1CoteAttribute();
$points = $bet->points * $cote;
if ($this->team1_goals == $bet->team1_goals && $this->team2_goals == $bet->team2_goals) {
$points += $bet->points / 10 * $cote;
}
Transaction::addTransaction($bet->user_id, $bet->id, $points, 'gain');
}
$this->winner_id = $this->team1_id;
//Si l'équipe deux a gagnée, on redistribue les points pour les paris corrects (paris sur l'équipe deux)
} else {
foreach (Bet::whereRaw('game_id = ? && winner_id = ?', array($this->id, $this->team2_id))->get() as $bet) {
$cote = $this->getTeam2CoteAttribute();
$points = $bet->points * $cote;
if ($this->team1_goals == $bet->team1_goals && $this->team2_goals == $bet->team2_goals) {
$points += $bet->points / 10 * $cote;
}
Transaction::addTransaction($bet->user_id, $bet->id, $points, 'gain');
}
$this->winner_id = $this->team2_id;
}
/////////////////////////////////////////////////
//******************* ROUND X *****************//
/////////////////////////////////////////////////
//On inscrit l'équipe gagnante dans son prochain match
$id = $this->stage()->first()->next_stage()->first()->id;
$num_game = round($this->stage_game_num / 2);
$game = Game::whereRaw("stage_id = ? && stage_game_num = ?", array($id, $num_game))->first();
if ($this->stage_game_num % 2 == 1) {
$game->team1_id = $this->winner_id;
} else {
$game->team2_id = $this->winner_id;
}
$game->save();
/////////////////////////////////////////////////
//******************* 3e place ****************//
/////////////////////////////////////////////////
//Si on est lors des demi, on va définir aussi la 3e finale
if ($this->stage()->first()->next_stage()->first()->next_stage == null) {
$stage_third = Stage::getThirdStage()->id;
$gamme_third = Game::whereRaw('stage_id = ?', array($stage_third))->first();
//Si équipe 1 a gagné on met l'équipe 2 en 3e place
if ($num_game == 1) {
if ($this->stage_game_num % 2 == 1) {
$gamme_third->team1_id = $this->team1_id;
} else {
$gamme_third->team2_id = $this->team1_id;
}
} else {
if ($this->stage_game_num % 2 == 1) {
$gamme_third->team1_id = $this->team2_id;
} else {
$gamme_third->team2_id = $this->team2_id;
}
}
$gamme_third->save();
}
$this->save();
}