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

46 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsTotalQ1;
use App\Utilities\Margin;
class StoreTotalsQ1
{
public static function store($data, $base)
{
ActiveHandicap::set($data);
foreach ($data as $total => $value) {
$odds = $value;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['total'] = $total;
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds = array_merge($odds, $base);
$res = OddsTotalQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotalQ1::create($odds);
} else {
$res->over = number_format($odds['over'], 2);
$res->under = number_format($odds['under'], 2);
$res->total = number_format($odds['total'], 2);
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
}
}