40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\Magloo\Odds;
|
|
|
|
use App\Models\OddsDc;
|
|
use App\Utilities\Margin;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MaglooStoreDc
|
|
{
|
|
public static function store($value, $base)
|
|
{
|
|
$odds = [];
|
|
$odds['dc1x'] = number_format($value['static'][9], 2) ?? 1;
|
|
$odds['dc12'] = number_format($value['static'][10], 2) ?? 1;
|
|
$odds['dcx2'] = number_format($value['static'][11], 2) ?? 1;
|
|
$odds['margin'] = (float) Margin::calculate($odds, 1);
|
|
$odds['flags'] = 1;
|
|
$odds = array_merge($odds, $base);
|
|
|
|
$res = OddsDc::where('event_id', $base['event_id'])->where('bookmaker_id', $base['bookmaker_id'])->first();
|
|
|
|
if (! $res) {
|
|
OddsDc::create($odds);
|
|
} else {
|
|
$res->dc1x = $odds['dc1x'];
|
|
$res->dc12 = $odds['dc12'];
|
|
$res->dcx2 = $odds['dcx2'];
|
|
$res->flags = 1;
|
|
$res->margin = $odds['margin'];
|
|
DB::transaction(function () use ($res) {
|
|
$res->save();
|
|
usleep(250000);
|
|
}, 5);
|
|
|
|
}
|
|
|
|
}
|
|
}
|