49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\Logifuture\Tools;
|
|
|
|
use App\Models\OddsPoint;
|
|
use App\Utilities\Margin;
|
|
|
|
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 = 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);
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|