80 lines
2.4 KiB
PHP
80 lines
2.4 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\OddsDc;
|
|
use App\Utilities\Margin;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class Bet365
|
|
{
|
|
public static function grap()
|
|
{
|
|
$debug = Nuh::$options['d'] ?? 0;
|
|
|
|
/**
|
|
* Bet365
|
|
*/
|
|
$bookmaker_id = 126;
|
|
|
|
$events = Event::where('bet365_id', '>', 0)->where('events.starttime', '>', Carbon::now())->get();
|
|
|
|
foreach ($events as $event) {
|
|
|
|
/**
|
|
* BET365 ODDS (per event)
|
|
*/
|
|
$url = 'https://api.b365api.com/v4/bet365/prematch?token='.config('env.betsapi_token').'&FI='.$event->bet365_id;
|
|
|
|
$data = Curl::load($url);
|
|
|
|
$offer = $data['results'][0]['main']['sp'];
|
|
|
|
/**
|
|
* 1X2
|
|
*/
|
|
$odds = [];
|
|
$odds['h3w'] = $offer['full_time_result']['odds'][0]['odds'];
|
|
$odds['d3w'] = $offer['full_time_result']['odds'][1]['odds'];
|
|
$odds['a3w'] = $offer['full_time_result']['odds'][2]['odds'];
|
|
$odds['margin'] = (float) Margin::calculate([$odds['h3w'], $odds['d3w'], $odds['a3w']], 1);
|
|
$odds['sport_id'] = $event->sport_id;
|
|
$odds['provider_id'] = Nuh::$options['provider_id'];
|
|
$odds['bmoid'] = $event->bet365_id;
|
|
$odds['flag'] = 1;
|
|
$odds['last_check_at'] = Carbon::now();
|
|
|
|
Odds3way::updateOrCreate([
|
|
'event_id' => $event->id,
|
|
'bookmaker_id' => $bookmaker_id,
|
|
], $odds);
|
|
|
|
/**
|
|
* DC
|
|
*/
|
|
$odds = [];
|
|
$odds['dc1x'] = $offer['full_time_result']['odds'][0]['odds'];
|
|
$odds['dc12'] = $offer['full_time_result']['odds'][1]['odds'];
|
|
$odds['dcx2'] = $offer['full_time_result']['odds'][2]['odds'];
|
|
$odds['margin'] = (float) Margin::calculate([$odds['dc1x'], $odds['dc12'], $odds['dcx2']], 1);
|
|
$odds['sport_id'] = $event->sport_id;
|
|
$odds['provider_id'] = Nuh::$options['provider_id'];
|
|
$odds['bmoid'] = $event->bet365_id;
|
|
$odds['flag'] = 1;
|
|
$odds['last_check_at'] = Carbon::now();
|
|
|
|
OddsDc::updateOrCreate([
|
|
'event_id' => $event->id,
|
|
'bookmaker_id' => $bookmaker_id,
|
|
], $odds);
|
|
|
|
dd($odds);
|
|
|
|
}
|
|
}
|
|
}
|