public function winnings() { if (ACL::checkUserPermission('reports.winnings') == false) { return Redirect::action('dashboard'); } $game_winnings = Gamewinnings::with('channel.tabledetails.operator')->get(); $title = Lang::get('Winning Numbers'); $data = array('acl' => ACL::buildACL(), 'winnings' => $game_winnings, 'title' => $title); return View::make('reports/winnings', $data); }
public function winnings() { //retrieve POST value $param = Input::only('gameid', 'winning_number'); $rules = array('gameid' => 'required|exists:game_channel,id', 'winning_number' => 'required|integer|between:0,36'); //custom error messaging $messages = array('gameid.exists' => 'Game doesn\'t exist'); $validator = Validator::make($param, $rules, $messages); if ($validator->passes()) { $gamewinnings = array('game_id' => 1, 'channel_id' => $param['gameid'], 'winning_number' => $param['winning_number']); $winnings = Gamewinnings::create($gamewinnings); Gamechannel::where('id', $param['gameid'])->update(array('channel_status' => 0)); $bets = Gamebets::with('channel', 'payout')->where('channel_id', $param['gameid'])->get(); $bet_win = array(); foreach ($bets as $row) { $win = false; switch ($row->payout->name) { case "straight": if ($row->bet_number == $param['winning_number']) { $win = true; } break; case "split": $numbers = explode(",", $row->bet_number); if (in_array($param['winning_number'], $numbers)) { $win = true; } break; case "line": $numbers = explode(",", $row->bet_number); if (in_array($param['winning_number'], $numbers)) { $win = true; } break; case "square": $numbers = explode(",", $row->bet_number); if (in_array($param['winning_number'], $numbers)) { $win = true; } break; case "basket": $numbers = explode(",", $row->bet_number); if (in_array($param['winning_number'], $numbers)) { $win = true; } break; case "1stcolumn": $numbers_covered = explode(',', $row->payout->numbers_covered); if (in_array($param['winning_number'], $numbers_covered)) { $win = true; } break; case "2ndcolumn": $numbers_covered = explode(',', $row->payout->numbers_covered); if (in_array($param['winning_number'], $numbers_covered)) { $win = true; } break; case "3rdcolumn": $numbers_covered = explode(',', $row->payout->numbers_covered); if (in_array($param['winning_number'], $numbers_covered)) { $win = true; } break; case "1dozen": $numbers_covered = explode(',', $row->payout->numbers_covered); if (in_array($param['winning_number'], $numbers_covered)) { $win = true; } break; case "2dozen": $numbers_covered = explode(',', $row->payout->numbers_covered); if (in_array($param['winning_number'], $numbers_covered)) { $win = true; } break; case "3dozen": $numbers_covered = explode(',', $row->payout->numbers_covered); if (in_array($param['winning_number'], $numbers_covered)) { $win = true; } break; case "even": if ($param['winning_number'] % 2 == 0) { $win = true; } break; case "odd": if ($param['winning_number'] % 2 != 0) { $win = true; } break; default: $numbers_covered = explode(',', $row->payout->numbers_covered); if (in_array($param['winning_number'], $numbers_covered)) { $win = true; } } if ($win == true) { $update = array('bet_result' => 'win', 'bet_status' => 0); Gamebets::where('id', $row->id)->update($update); $this->player_winnings($row->payout->payout, $row->player_id, $row->bet_amount, $row->channel->channel_id); $bet_win[] = $row->id; } elseif ($win == false) { $update = array('bet_result' => 'loss', 'bet_status' => 0); Gamebets::where('id', $row->id)->update($update); } } if (count($bet_win) > 0) { $player_winnings = Gamebets::with('payout', 'playerdetails')->whereIn('id', $bet_win)->get(); if (!empty($player_winnings->first())) { $response = array('betwin' => true, 'message' => 'List of players who won.', 'data' => $player_winnings->toArray()); } } else { $response = array('betwin' => false, 'message' => 'No player has won this game.'); } } else { //All error message in validation $messages = $validator->messages(); //response if merchant doesnt have list of products. $response = array('betwin' => 404, 'error' => 'not_found', 'error_message' => $messages->all()); } echo json_encode($response); }