Files
nuhodds_fi4/app/Console/Commands/Grapper/Logifuture/Tools/StorePointsQ1.php
T
2026-01-19 18:36:07 +01:00

50 lines
1.6 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Logifuture\Odds;
use App\Console\Commands\Grapper\Logifuture\Tools\ActiveHandicap;
use App\Models\OddsPointQ1;
use App\Utilities\Margin;
class StorePointsQ1
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $handicap => $value) {
// code...
$odds = [];
$odds['home'] = $value['ele1'];
$odds['away'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['handicap'] = $handicap;
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds = array_merge($odds, $base);
$res = OddsPointQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPointQ1::create($odds);
} else {
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 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();
}
}
}
}