Files
nuhodds_fi4/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php
T

49 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsPoint;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStorePoints
{
public static function store($data, $base)
{
ActiveHandicap::set($data);
foreach ($data as $handicap => $value) {
$odds = $value;
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 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->flags = 1;
$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->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}