Files
nuhodds_fi4/app/Console/Commands/Grapper/Logifuture/Icehockey.php
T
2026-10-04 15:25:03 +02:00

185 lines
6.0 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Grapper\Logifuture\Tools\FilterHandicap;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStorePoints;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStorePointsQ1;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStoreTotals;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStoreTotalsQ1;
use App\Console\Commands\Nuh;
use App\Models\Odds2way;
use App\Models\Odds2wayS1;
use App\Models\Odds3way;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class Icehockey
{
public static function get(&$event, $match)
{
$ml = [];
$mls1 = [];
$_3way = [];
$n_totals = [];
$n_points = [];
$c_totals = [];
$c_points = [];
foreach ($match['odds'] as $name => $value) {
switch ($name) {
case 'IH_1X2_1':
$_3way['h3w'] = number_format($value, 2);
break;
case 'IH_1X2_X':
$_3way['d3w'] = number_format($value, 2);
break;
case 'IH_1X2_2':
$_3way['a3w'] = number_format($value, 2);
break;
case 'IH_12_1':
$ml['h2w'] = number_format($value, 2);
break;
case 'IH_12_2':
$ml['a2w'] = number_format($value, 2);
break;
case 'IH_12OTAP_1':
$mls1['h2w'] = number_format($value, 2);
break;
case 'IH_12OTAP_2':
$mls1['a2w'] = number_format($value, 2);
break;
}
if (strpos($name, '@') !== false) {
$pos = strpos($name, '@');
$market = substr($name, 0, $pos);
switch ($market) {
// NIGERIA
case 'IH_TF':
$n_totals[$name] = $value;
break;
case 'IH_HR1':
$n_points[$name] = $value;
break;
// COLOMBIA
case 'IH_OUHND':
$c_totals[$name] = $value;
break;
case 'IH_12HND':
$c_points[$name] = $value;
break;
}
}
}
$base = [];
$base['event_id'] = $event['id'];
$base['bookmaker_id'] = $event['bookmaker_id'];
$base['sport_id'] = $event['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event['event_id'];
$base['flags'] = 1;
// 1x2
if (\count($_3way) == 3) {
$_3way['margin'] = (float) Margin::calculate($_3way, 1);
$_3way = array_merge($_3way, $base);
$res = Odds3way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds3way::create($_3way);
} else {
$res->h3w = number_format($_3way['h3w'], 2);
$res->d3w = number_format($_3way['d3w'], 2);
$res->a3w = number_format($_3way['a3w'], 2);
$res->flags = 1;
$res->margin = $_3way['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// ML
if (\count($ml) == 2) {
$ml['margin'] = (float) Margin::calculate($ml, 1);
$ml = array_merge($ml, $base);
$res = Odds2way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds2way::create($ml);
} else {
$res->h2w = number_format($ml['h2w'], 2);
$res->a2w = number_format($ml['a2w'], 2);
$res->flags = 1;
$res->margin = $ml['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
if (\count($mls1) == 2) {
$mls1['margin'] = (float) Margin::calculate($mls1, 1);
$mls1 = array_merge($mls1, $base);
$res = Odds2wayS1::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds2wayS1::create($mls1);
} else {
$res->h2w = number_format($mls1['h2w'], 2);
$res->a2w = number_format($mls1['a2w'], 2);
$res->flags = 1;
$res->margin = $mls1['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// COLUMBIA
if ($c_totals) {
FilterHandicap::filter($_spreads['total'], 'IH_OUHND@', $c_totals, ['over', 'under', 'total']);
}
if ($c_points) {
FilterHandicap::filter($_spreads['point'], 'IH_12HND@', $c_points, ['hth1', 'hth2', 'hcap']);
}
// NIGERIA
if ($n_totals) {
FilterHandicap::filter($_spreads['total'], 'IH_TF@', $n_totals, ['over', 'under', 'total']);
}
if ($n_points) {
FilterHandicap::filter($_spreads['point'], 'IH_HR1@', $n_points, ['hth1', 'hth2', 'hcap']);
}
if (isset($_spreads['total'])) {
LogifutureStoreTotals::store($_spreads['total'], $base);
}
if (isset($_spreads['total_qt'])) {
LogifutureStoreTotalsQ1::store($_spreads['total_qt'], $base);
}
if (isset($_spreads['point'])) {
LogifutureStorePoints::store($_spreads['point'], $base);
}
if (isset($_spreads['point_qt'])) {
LogifutureStorePointsQ1::store($_spreads['point_qt'], $base);
}
}
}