Exemplo n.º 1
0
<?php

/*
 * CRON SCRIPT: Simulate Bets
 * Runs every 30 minutes
 */
chdir(dirname(__FILE__));
require '../config.php';
$matches = Match::GetAll();
// Get the users accounts that represent the automated bots
$users = $db->fetch("SELECT * FROM User WHERE id IN (42, 43, 44, 28)", null, 'User');
foreach ($users as $user) {
    foreach ($matches as $match) {
        if (strtotime($match->start_time) > strtotime('now')) {
            // Filter by upcoming matches only
            // Setup the bet
            $bet = new Bet();
            $bet->user_id = $user->id;
            $bet->match_id = $match->id;
            $bet->type = 1;
            $bet->team = mt_rand(0, 2);
            $bet_amount = mt_rand(10, $user->points / 100) / 10 * 10;
            // Random bet amount up to a tenth of the user's balance
            $bet->points_simple = $bet_amount;
            // Create the bet
            $bet->Create();
        }
    }
}
Exemplo n.º 2
0
    $user = User::GetByToken($app->request->headers->get('token'));
    // Create the bet
    $bet = new Bet();
    $bet->user_id = $user->id;
    $bet->match_id = $id;
    $bet->type = $type;
    $bet->team = $team;
    if ($type === 1) {
        $bet->points_simple = $data['points_simple'];
    } elseif ($type === 2) {
        $bet->points_goals = $data['points_goals'];
        $bet->points_yellowcards = $data['points_yellowcards'];
        $bet->points_redcards = $data['points_redcards'];
        $bet->points_defenses = $data['points_defenses'];
    }
    if ($bet_id = $bet->Create()) {
        $app->render_json(['id' => $bet_id]);
    } else {
        throw new Exception("Bet not allowed", 400);
    }
});
/* Get bets
 **********************************************************************************************************************/
$app->get('/bets', function () use($app) {
    $user = User::GetByToken($app->request->headers->get('token'));
    $response = Bet::GetByUser($user->id);
    $app->render_json($response);
});
/* Get global stats
 **********************************************************************************************************************/
$app->get('/stats', function () use($app) {