コード例 #1
0
ファイル: Bet.php プロジェクト: mdominoni/binarybtc
 public static function checkExpired()
 {
     $expired = Bet::available()->where('expires_at', '<=', date('Y-m-d H:i:s'))->whereNull('accepted_by_user_id')->lists('id');
     if (count($expired) > 0) {
         Bet::whereIn('id', $expired)->update(array('expired' => 1));
     }
     $finished = Bet::where('expires_at', '<=', date('Y-m-d H:i:s'))->whereNotNull('accepted_by_user_id')->where('winner_paid', 0)->get();
     foreach ($finished as $bet) {
         $bet->handleWinner();
     }
 }
コード例 #2
0
ファイル: BetController.php プロジェクト: mdominoni/binarybtc
 public function postDelete()
 {
     if (!Input::has('bet_id')) {
         return array('success' => false);
     }
     $bet_id = Input::get('bet_id');
     $bet = Bet::where('id', $bet_id)->where('created_by_user_id', Auth::user()->id)->first();
     if (is_null($bet)) {
         return array('success' => false);
     } else {
         if ($bet->canBeDeleted()) {
             $bet->deleted = 1;
             $bet->price_when_deleted = Bitcoin::toUSD();
             $bet->deleted_at = time();
             $bet->save();
             Auth::user()->addToBalance($bet->bet_amount);
             return array('success' => true);
         } else {
             return array('success' => false);
         }
     }
 }
コード例 #3
0
ファイル: cron.php プロジェクト: kxopa/PHPLotterySystem
 $draw_id = $draw->id;
 $draw_winning_price = $draw->winning_price;
 // GENERATE RANDOM NUMBERS FROM 1-42
 $range = range(1, 42);
 shuffle($range);
 $num = 6;
 $r = array();
 for ($i = 0; $i < $num; $i++) {
     $r[] = $range[$i];
 }
 $shuffled = $num == 1 ? $r[0] : $r;
 sort($shuffled, SORT_NUMERIC);
 // SAVE THE WINNING NUMBER TO DATABASE
 $draw = Draw::where("date", "=", $date)->update(array('numbers' => implode(",", $shuffled), 'status' => 'closed'));
 // FIND WINNERS
 $bets = Bet::where("draw_id", "=", $draw_id)->where("numbers", "=", implode(",", $shuffled));
 // GET NUMBER OF WINNERS AND DIVIDED IT
 $price = $draw_winning_price / $bets->count();
 // WINNERS
 $winners = $bets->get();
 // SAVE WINNERS TO DATABASE
 foreach ($winners as $winner) {
     $w = new Winner();
     $w->draw_id = $draw_id;
     $w->winning_numbers = implode(",", $shuffled);
     $w->winning_price = $price;
     $w->ticket_number = $winner->ticket_number;
     $w->security_code = $winner->security_code;
     $w->draw_date = $date;
     $w->save();
     echo "Winner Saved";
コード例 #4
0
 public function showCurrentBets()
 {
     // Get the current user
     $this->data['user'] = Confide::user();
     // Initialize the potential money that can be won as the current money the user has
     $this->data['potential_money'] = $this->data['user']->current_money;
     // Get all of the users outstanding bets
     $current_bets = Bet::where('user_id', '=', $this->data['user']->id)->where('final', false)->get();
     if ($current_bets) {
         $this->data['bet_objects'] = [];
         // Get all of the games
         $repo = App::make('GameRepository');
         $pending_games = $repo->getPendingGames('NFL', '4');
         foreach ($current_bets as $bet) {
             if (array_key_exists($bet->game_code, $pending_games)) {
                 // Get the game associated with the bet
                 $game = $pending_games[$bet->game_code];
                 $visiting_team = $game['visiting-team']['@attributes'];
                 $home_team = $game['home-team']['@attributes'];
                 if ($visiting_team['id'] === $bet->team) {
                     $picked_team = $visiting_team;
                     $opposing_team = $home_team;
                 } else {
                     $picked_team = $home_team;
                     $opposing_team = $visiting_team;
                 }
                 $bet_object = (object) [];
                 $bet_object->bet = $bet;
                 $bet_object->game = $game['gamestate']['@attributes'];
                 $bet_object->visiting_team = $visiting_team;
                 $bet_object->home_team = $home_team;
                 $bet_object->picked_team = $picked_team;
                 $bet_object->game_title = $visiting_team['display_name'] . ' ' . $visiting_team['nickname'] . ' at ' . $home_team['display_name'] . ' ' . $home_team['nickname'];
                 if ($bet->bet_type === 'pointspread') {
                     $adjusted_team_score = $picked_team['score'] + $bet->point_spread;
                 } else {
                     $adjusted_team_score = $picked_team['score'];
                 }
                 // If this is a current winning bet
                 if ($adjusted_team_score > $opposing_team['score']) {
                     // Payout will be the initial bet plus winnings
                     $payout = $bet->bet_amount + $bet->win_potential;
                     // If the game is over, record win and set bet to final
                     if ($bet_object->game['status'] === 'Final') {
                         $bet->won = true;
                         $bet->final = true;
                         $bet->save();
                         $this->data['user']->current_money += $payout;
                         $this->data['user']->save();
                     } else {
                         $bet_object->status = 'panel-success';
                         $this->data['potential_money'] += $payout;
                         $this->data['bet_objects'][] = $bet_object;
                     }
                 } else {
                     if ($adjusted_team_score === $opposing_team['score']) {
                         // Payout will be just the initial bet
                         $payout = $bet->bet_amount;
                         // If the game is over, record win and set bet to final
                         if ($bet_object->game['status'] === 'Final') {
                             $bet->won = true;
                             $bet->final = true;
                             $bet->save();
                             $this->data['user']->current_money += $payout;
                             $this->data['user']->save();
                         } else {
                             $bet_object->status = 'panel-warning';
                             // Payout will be just the initial bet
                             $this->data['potential_money'] += $payout;
                             $this->data['bet_objects'][] = $bet_object;
                         }
                     } else {
                         // If the game is over, set bet to final
                         if ($bet_object->game['status'] === 'Final') {
                             $bet->final = true;
                             $bet->save();
                         } else {
                             $bet_object->status = 'panel-danger';
                             $this->data['bet_objects'][] = $bet_object;
                         }
                     }
                 }
             }
         }
     }
     return View::make('bets', $this->data);
 }