Files
2026-10-04 15:25:03 +02:00

52 lines
1.6 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Models\OddsPoint;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class LogifutureStorePoints
{
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['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsPoint::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPoint::create($odds);
} else {
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}