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

48 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
use App\Models\OddsPoint;
use App\Utilities\Margin;
class _Points
{
public static function grap($odds, $offer)
{
foreach ($offer as $value) {
$odds['home'] = (float) $value->o1;
$odds['away'] = (float) $value->o2;
$odds['handicap'] = (float) $value->o3;
}
if (fmod((float) $odds['handicap'], 1) != 0.5) {
return;
}
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
$res = OddsPoint::where('event_id', $odds['event_id'])
->where('bookmaker_id', $odds['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->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
ActiveSpread::collect($odds, 'odds_points');
}
}