Files
nuhodds_fi4/app/Console/Commands/Grapper/Betsapi/Willhill.php
T
2026-01-19 18:36:07 +01:00

103 lines
3.7 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Fixtures\StoreElement;
use App\Console\Commands\Grapper\Fixtures\StoreGroup;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Models\Odds2way;
use App\Models\Odds3way;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Willhill
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
/**
* williamhill
*/
$bookmaker_id = 42;
$collection = [];
$res = Odds3way::with('event')->where('bookmaker_id', $bookmaker_id)->get();
foreach ($res as $value) {
if ($value->event->starttime > Carbon::now() && ! $value->event->betsapi_id) {
$collection[] = [
'txodds_id' => $value->event_id,
'willhill_id' => $value->bmoid,
'sport_id' => $value->sport_id,
];
}
}
$res = Odds2way::with('event')->where('bookmaker_id', $bookmaker_id)->get();
foreach ($res as $value) {
if ($value->event->starttime > Carbon::now() && ! $value->event->betsapi_id) {
$collection[] = [
'txodds_id' => $value->event_id,
'willhill_id' => $value->bmoid,
'sport_id' => $value->sport_id,
];
}
}
foreach ($collection as $event) {
$url = 'https://api.b365api.com/v1/williamhill/result?token='.config('env.betsapi_token').'&event_id='.$event['willhill_id'];
$data = Curl::load($url);
$betsapi_id = $data['results'][0]['id'] ?? 0;
$bet365_id = $data['results'][0]['bet365_id'] ?? 0;
if ($debug) {
Notice::note(['TXdds ID : '.$event['txodds_id'], "Betsapi ID : $betsapi_id", "Bet365 ID : $bet365_id", 'Willhill ID : '.$event['willhill_id']], 'b');
}
if ($betsapi_id) {
if (isset($data['results'][0]['home'])) {
$match = Event::where('id', (int) $event['txodds_id'])->first();
$ele = [];
$ele['sport_id'] = $event['sport_id'];
$ele['provider_id'] = Nuh::$options['provider_id'];
$ele['element_id'] = $match->home_id ?? 0;
$ele['provider_element_id'] = $data['results'][0]['home']['id'] ?? 0;
$ele['name'] = $data['results'][0]['home']['name'];
StoreElement::store($elements, $ele);
$ele = [];
$ele['sport_id'] = $event['sport_id'];
$ele['provider_id'] = Nuh::$options['provider_id'];
$ele['element_id'] = $match->away_id ?? 0;
$ele['provider_element_id'] = $data['results'][0]['away']['id'] ?? 0;
$ele['name'] = $data['results'][0]['away']['name'];
StoreElement::store($elements, $ele);
$group = [];
$ele['sport_id'] = $event['sport_id'];
$group['provider_id'] = Nuh::$options['provider_id'];
$group['competition_group_id'] = $match->competition_group_id;
$group['provider_group_id'] = $data['results'][0]['league']['id'] ?? 0;
$group['name'] = $data['results'][0]['league']['name'];
StoreGroup::store($groups, $group);
$match->betsapi_id = $betsapi_id;
$match->bet365_id = $bet365_id;
$match->save();
Mapper::where('event_id', $betsapi_id)->delete();
}
}
}
}
}