52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\Logifuture\Tools;
|
|
|
|
use App\Models\OddsPointQ1;
|
|
use App\Utilities\Margin;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class LogifutureStorePointsQ1
|
|
{
|
|
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['flags'] = 1;
|
|
$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);
|
|
$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);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|