36 lines
1014 B
PHP
36 lines
1014 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\TxOdds\Odds;
|
|
|
|
use App\Models\OddsDc;
|
|
use App\Utilities\Margin;
|
|
|
|
class _Dc
|
|
{
|
|
public static function grap($odds, $offer)
|
|
{
|
|
foreach ($offer as $value) {
|
|
$odds['dc1x'] = (float) $value->o1;
|
|
$odds['dc12'] = (float) $value->o2;
|
|
$odds['dcx2'] = (float) $value->o3;
|
|
}
|
|
$odds['margin'] = (float) Margin::calculate([$odds['dc1x'], $odds['dc12'], $odds['dcx2']], 1);
|
|
|
|
$res = OddsDc::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
|
|
|
|
if (! $res) {
|
|
OddsDc::create($odds);
|
|
} else {
|
|
$res->dc1x = $odds['dc1x'];
|
|
$res->dc12 = $odds['dc12'];
|
|
$res->dcx2 = $odds['dcx2'];
|
|
if ($res->isDirty()) {
|
|
$res->oddchange_at = now();
|
|
}
|
|
$res->checked_at = $odds['checked_at'];
|
|
$res->margin = $odds['margin'];
|
|
$res->save();
|
|
}
|
|
}
|
|
}
|