73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\TxOdds\Odds;
|
|
|
|
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
|
|
use App\Console\Commands\Nuh;
|
|
use App\Models\OddsTotal;
|
|
use App\Utilities\Margin;
|
|
use PDOException;
|
|
|
|
class _Totals
|
|
{
|
|
public static function grap($odds, $offer)
|
|
{
|
|
$block_update = Nuh::$options['b'] ?? 0;
|
|
|
|
foreach ($offer as $value) {
|
|
$odds['over'] = (float) $value->o1;
|
|
$odds['under'] = (float) $value->o2;
|
|
$odds['total'] = (float) $value->o3;
|
|
}
|
|
|
|
if ($odds['sport_id'] == 1) {
|
|
if ((float) $odds['total'] != 2.5) {
|
|
return;
|
|
}
|
|
} else {
|
|
if (fmod((float) $odds['total'], 1) != 0.5) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
|
|
|
|
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
|
|
|
|
$res = OddsTotal::where('event_id', $odds['event_id'])
|
|
->where('bookmaker_id', $odds['bookmaker_id'])
|
|
->where('total', $odds['total'])
|
|
->first();
|
|
|
|
if (! $res) {
|
|
OddsTotal::create($odds);
|
|
} elseif (! $block_update) {
|
|
$res->over = $odds['over'];
|
|
$res->under = $odds['under'];
|
|
$res->flags = 1;
|
|
$res->margin = $odds['margin'];
|
|
|
|
$max_tries = 5;
|
|
$tries = 0;
|
|
do {
|
|
$retry = false;
|
|
try {
|
|
|
|
$res->save();
|
|
|
|
return $res;
|
|
} catch (PDOException $exc) {
|
|
if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) {
|
|
$retry = true;
|
|
sleep(1);
|
|
} else {
|
|
throw $exc;
|
|
}
|
|
}
|
|
} while ($retry);
|
|
}
|
|
|
|
ActiveSpread::collect($odds, 'odds_totals');
|
|
}
|
|
}
|