Files
nuhodds_fi4/app/Console/Commands/Grapper/Betsapi/Bwin.php
T
2025-12-22 08:15:59 +01:00

62 lines
1.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\Mapper;
use App\Models\Sport;
use App\Utilities\Notice;
class Bwin
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$sportmap = Sport::map('bwin');
$total = 1;
foreach ($sportmap as $sport_id => $bwin_sport_id) {
$page = 1;
/**
* BWIN ODDS & BETRADAR ID (per page)
*/
$url = 'https://api.b365api.com/v1/bwin/prematch?token='.config('env.betsapi_token').'&page=###page###&sport_id='.$bwin_sport_id;
while ($page <= $total) {
$url = str_replace('###page###', $page, $url);
$data = Curl::load($url);
$page++;
$total = round($data['pager']['total'] / $data['pager']['per_page']);
if ($debug) {
Notice::note("Page: $page \nTotal: $total");
}
if (isset($data['results'])) {
foreach ($data['results'] as $event) {
$bwin_id = $event['Id'];
$betradar_id = $event['BetRadarId'] ?? 0;
$betsapi_id = $event['our_event_id'];
if ($betradar_id) {
Event::where('betsapi_id', (int) $betsapi_id)->update(['betradar_id' => $betradar_id, 'bwin_id' => $bwin_id]);
Mapper::where('event_id', $betsapi_id)->delete();
}
}
}
}
}
}
}