95 lines
3.3 KiB
PHP
95 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\Betsapi;
|
|
|
|
use App\Console\Commands\Curl;
|
|
use App\Console\Commands\Nuh;
|
|
use App\Mapper\LoadElements;
|
|
use App\Mapper\LoadGroups;
|
|
use App\Mapper\StoreElement;
|
|
use App\Mapper\StoreGroup;
|
|
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;
|
|
|
|
$elements = LoadElements::load(Nuh::$options['provider_id']);
|
|
|
|
$groups = LoadGroups::load(Nuh::$options['provider_id']);
|
|
|
|
/**
|
|
* williamhill
|
|
*/
|
|
$bookmaker_id = 42;
|
|
|
|
$res = Odds3way::join('events', 'odds_3ways.event_id', 'events.id')
|
|
->where('odds_3ways.bookmaker_id', $bookmaker_id)
|
|
->where('events.starttime', '>', Carbon::now())
|
|
->where('events.betsapi_id', 0)
|
|
->where('events.sport_id', $sport_id)
|
|
->where('odds_3ways.bmoid', '>', 0)->pluck('odds_3ways.event_id', 'odds_3ways.bmoid');
|
|
|
|
foreach ($res 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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|