Files
nuhodds_fi4/app/Console/Commands/Grapper/Betsapi/Willhill.php
T
2026-01-16 08:01:40 +01:00

92 lines
3.1 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\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Models\Odds3way;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Willhill
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$sport_id = 1;
/**
* williamhill
*/
$bookmaker_id = 42;
$res = Event::with('odds_3ways')
->where('betsapi_id', 0)
->where('sport_id', $sport_id)
->where('starttime', '>', Carbon::now())
->pluck('id');
$events = Odds3way::where('bookmaker_id', $bookmaker_id)
->whereIn('event_id', $res)
->where('bmoid', '!=', 0)
->pluck('event_id', 'bmoid');
foreach ($events as $willhill_id => $txodds_id) {
$url = 'https://api.b365api.com/v1/williamhill/result?token='.config('env.betsapi_token').'&event_id='.$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 : $txodds_id", "Betsapi ID : $betsapi_id", "Bet365 ID : $bet365_id", "Willhill ID : $willhill_id"], 'b');
}
if ($betsapi_id) {
if (isset($data['results'][0]['home'])) {
$match = Event::where('id', (int) $txodds_id)->first();
$ele = [];
$ele['sport_id'] = $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'] = $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 = [];
$group['sport_id'] = $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();
}
}
}
}
}