Files
nuhodds_fi4/app/Console/Commands/Grapper/Magloo/Odds.php
T
2026-01-18 14:35:30 +01:00

317 lines
14 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Magloo;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Magloo\Odds\FilterHandicap;
use App\Console\Commands\Grapper\Magloo\Odds\FilterHandicapQ1;
use App\Console\Commands\Grapper\Magloo\Odds\FilterTotals;
use App\Console\Commands\Grapper\Magloo\Odds\FilterTotalsQ1;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Odds3way;
use App\Models\OddsDc;
use App\Models\OddsGgng;
use App\Models\OddsPoint;
use App\Models\OddsPointQ1;
use App\Models\OddsTotal;
use App\Models\OddsTotalQ1;
use App\Models\OddsTq;
use App\Models\Sport;
use App\Utilities\Margin;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Odds
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$proxy = Nuh::$options['p'] ?? 0;
$event_id_collector = [];
$sportmap = Sport::map('magl', 1, [1, 3]);
if ($proxy) {
Notice::note('PROXY USED', 'r');
}
if ($debug) {
Notice::note(Nuh::$options['provider'].' '.Nuh::$options['name'], 'g');
}
foreach ($sportmap as $magloo_sport_id => $sport_id) {
$url = Nuh::$options['base_url'].'/1/prematch/sport/'.$magloo_sport_id.'/odds';
$data = Curl::load($url, ['timeout' => 30]);
if (! is_array($data) or \count($data) == 0) {
Notice::note('no data in feed', 'r', 1);
return;
}
foreach ($data as $match) {
$betradar_id = (int) preg_replace('/\D/', '', $match['p']);
$starttime = Carbon::parse($match['dt'])->toDateTimeString();
$event_id = Event::where('betradar_id', $betradar_id)->value('id');
if ($event_id) {
$base = [];
$base['event_id'] = $event_id;
$base['bookmaker_id'] = Nuh::$options['bookmaker_id'];
$base['sport_id'] = $sport_id;
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = preg_replace('/\D/', '', $match['i']);
$base['flag'] = 1;
$base['checked_at'] = now();
$event_id_collector[] = $event_id;
EventBookmaker::updateOrCreate([
'event_id' => $event_id,
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], ['starttime' => $starttime, 'in_feed' => 1, 'bmoid' => $base['bmoid']]);
// if ($event_id == 13913478) {
// dd($match['M']);
// }
foreach ($match['M'] as $magloo_bettype_id => $value) {
switch ($magloo_bettype_id) {
case 1:
// 1x2
$odds = [];
$odds['h3w'] = number_format($value['static'][1], 2) ?? 1;
$odds['d3w'] = number_format($value['static'][2], 2) ?? 1;
$odds['a3w'] = number_format($value['static'][3], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$res = Odds3way::where('event_id', $event_id)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->first();
if (! $res) {
Odds3way::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->a3w = $odds['d3w'];
$res->d3w = $odds['a3w'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
case 2:
// to qalify
$odds = [];
$odds['htq'] = number_format($value['static'][4], 2) ?? 1;
$odds['atq'] = number_format($value['static'][5], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$res = OddsTq::where('event_id', $event_id)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->first();
if (! $res) {
OddsTq::create($odds);
} else {
$res->htq = $odds['htq'];
$res->atq = $odds['atq'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
case 10:
// double chance
$odds = [];
$odds['dc1x'] = number_format($value['static'][9], 2) ?? 1;
$odds['dc12'] = number_format($value['static'][10], 2) ?? 1;
$odds['dcx2'] = number_format($value['static'][11], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$res = OddsDc::where('event_id', $event_id)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->first();
if (! $res) {
OddsDc::create($odds);
} else {
$res->dc1x = $odds['dc1x'];
$res->dc12 = $odds['dc12'];
$res->dcx2 = $odds['dcx2'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
case 27:
// ggng
$odds = [];
$odds['gg'] = number_format($value['static'][74], 2) ?? 1;
$odds['ng'] = number_format($value['static'][76], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$res = OddsGgng::where('event_id', $event_id)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->first();
if (! $res) {
OddsGgng::create($odds);
} else {
$res->gg = $odds['gg'];
$res->ng = $odds['ng'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
case 16:
case 2000:
// points
$odds = FilterHandicap::get($value);
$odds = array_merge($odds, $base);
$res = OddsPoint::where('event_id', $event_id)
->where('bookmaker_id', Nuh::$options['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPoint::create($odds);
} else {
$res->home = $odds['home'];
$res->away = $odds['away'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->difference = $odds['difference'];
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
case 2025:
// points qt
$odds = FilterHandicapQ1::get($value);
$odds = array_merge($odds, $base);
$res = OddsPointQ1::where('event_id', $event_id)
->where('bookmaker_id', Nuh::$options['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPointQ1::create($odds);
} else {
$res->home = $odds['home'];
$res->away = $odds['away'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->difference = $odds['difference'];
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
case 17:
case 2002:
// totals
$odds = FilterTotals::get($value, $sport_id);
$odds = array_merge($odds, $base);
if ($base['sport_id'] == 1) {
$odds['active_spread'] = 1;
}
$res = OddsTotal::where('event_id', $event_id)
->where('bookmaker_id', Nuh::$options['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotal::create($odds);
} else {
$res->over = $odds['over'];
$res->under = $odds['under'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->difference = $odds['difference'];
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
case 2012:
// totals qt
$odds = FilterTotalsQ1::get($value, $sport_id);
$odds = array_merge($odds, $base);
if ($base['sport_id'] == 1) {
$odds['active_spread'] = 1;
}
$res = OddsTotalQ1::where('event_id', $event_id)
->where('bookmaker_id', Nuh::$options['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotalQ1::create($odds);
} else {
$res->over = $odds['over'];
$res->under = $odds['under'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->difference = $odds['difference'];
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
break;
}
}
}
}
}
EventBookmaker::whereNotIn('event_id', $event_id_collector)
->where('bookmaker_id', Nuh::$options['bookmaker_id'])
->update(['in_feed' => 0]);
}
}