142 lines
5.7 KiB
PHP
142 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\Betsapi;
|
|
|
|
use App\Console\Commands\Curl;
|
|
use App\Console\Commands\Nuh;
|
|
use App\Models\Event;
|
|
use App\Models\Odds3way;
|
|
use App\Models\Supervisor;
|
|
use App\Utilities\Margin;
|
|
use App\Utilities\Notice;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class Odds
|
|
{
|
|
/**
|
|
* Create a new class instance.
|
|
*/
|
|
public static function grap()
|
|
{
|
|
$debug = Nuh::$options['d'] ?? 0;
|
|
|
|
$today = Nuh::$options['t'] ?? 0;
|
|
|
|
$week = Nuh::$options['w'] ?? 0;
|
|
|
|
$single = Nuh::$options['id'] ?? 0;
|
|
|
|
if ($debug) {
|
|
Notice::note('BETSAPI ODDS '.Nuh::$options['sport'], 'b');
|
|
}
|
|
|
|
$sources = [83 => 'pinnaclesports'];
|
|
|
|
$flags = [];
|
|
|
|
if ($single) {
|
|
$events = Event::where('id', Nuh::$options['id'])->where('betsapi_id', '>', 0)->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
|
|
} elseif ($today) {
|
|
$events = Event::where('sport_id', Nuh::$options['sport_id'])->where('betsapi_id', '>', 0)->where('starttime', '>', Carbon::now()->toDateTimeString())->where('starttime', '<', Carbon::now()->addDay()->toDateTimeString())->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
|
|
} elseif ($week) {
|
|
$events = Event::where('sport_id', Nuh::$options['sport_id'])->where('betsapi_id', '>', 0)->where('starttime', '>', Carbon::now()->toDateTimeString())->where('starttime', '<', Carbon::now()->addDays(7)->toDateTimeString())->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
|
|
} else {
|
|
// all
|
|
$events = Event::where('sport_id', Nuh::$options['sport_id'])->where('betsapi_id', '>', 0)->where('starttime', '>', Carbon::now()->toDateTimeString())->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
|
|
}
|
|
|
|
foreach ($events as $key => $event) {
|
|
|
|
if ($debug) {
|
|
Notice::note([
|
|
'id' => $event->id,
|
|
'betsapi_id' => $event->betsapi_id,
|
|
'starttime' => $event->starttime,
|
|
'count' => count($events).'/'.$key + 1,
|
|
], 'b');
|
|
}
|
|
|
|
$since_time = Nuh::$options['lastcall'] - 600;
|
|
|
|
$since_time = 0;
|
|
|
|
foreach ($sources as $bookmaker_id => $source) {
|
|
|
|
$url = 'https://api.b365api.com/v2/event/odds?token='.config('env.betsapi_token').'&source'.$source.'&since_time='.$since_time.'&event_id='.$event->betsapi_id;
|
|
|
|
$data = Curl::load($url);
|
|
|
|
$base = [];
|
|
$base['event_id'] = $event->id;
|
|
$base['bookmaker_id'] = $bookmaker_id;
|
|
$base['sport_id'] = $event->sport_id;
|
|
$base['provider_id'] = Nuh::$options['provider_id'];
|
|
$base['bmoid'] = $event->betsapi_id;
|
|
$base['flag'] = 1;
|
|
|
|
foreach ($data['results']['odds'] as $key => $value) {
|
|
switch ($key) {
|
|
case '1_1':
|
|
|
|
$odds = [];
|
|
$odds['h3w'] = number_format($value[0]['home_od'], 2) ?? 1;
|
|
$odds['d3w'] = number_format($value[0]['draw_od'], 2) ?? 1;
|
|
$odds['a3w'] = number_format($value[0]['away_od'], 2) ?? 1;
|
|
$odds['margin'] = (float) Margin::calculate($odds, 1);
|
|
|
|
$odds = array_merge($odds, $base);
|
|
|
|
$flags['odds_3ways'][] = $event->id;
|
|
|
|
$res = Odds3way::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
|
|
|
|
if (! $res) {
|
|
Odds3way::create($odds);
|
|
} else {
|
|
$res->h3w = $odds['h3w'];
|
|
$res->a3w = $odds['d3w'];
|
|
$res->d3w = $odds['a3w'];
|
|
$res->flags = 1;
|
|
$res->margin = $odds['margin'];
|
|
$res->save();
|
|
}
|
|
break;
|
|
case '1_3':
|
|
|
|
dd($value);
|
|
|
|
$odds = [];
|
|
$odds['h3w'] = number_format($value[0]['home_od'], 2) ?? 1;
|
|
$odds['d3w'] = number_format($value[0]['draw_od'], 2) ?? 1;
|
|
$odds['a3w'] = number_format($value[0]['away_od'], 2) ?? 1;
|
|
$odds['margin'] = (float) Margin::calculate($odds, 1);
|
|
|
|
$odds = array_merge($odds, $base);
|
|
|
|
$res = Odds3way::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
|
|
|
|
if (! $res) {
|
|
Odds3way::create($odds);
|
|
} else {
|
|
$res->h3w = $odds['h3w'];
|
|
$res->a3w = $odds['d3w'];
|
|
$res->d3w = $odds['a3w'];
|
|
$res->flags = 1;
|
|
$res->margin = $odds['margin'];
|
|
$res->save();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Supervisor::where('id', Nuh::$options['supervisor_id'])->update(['lastcall' => time()]);
|
|
|
|
}
|
|
// needs check
|
|
foreach ($flags as $table => $event_ids) {
|
|
DB::table($table)->where('bookmaker_id', $bookmaker_id)->whereNotIn('event_id', $event_ids)->update(['flags' => 0]);
|
|
}
|
|
}
|
|
}
|