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