o1; $odds['away'] = (float) $value->o2; $odds['handicap'] = (float) $value->o3; } if (fmod((float) $odds['handicap'], 1) != 0.5) { return; } $odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']); $odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1); $res = OddsPoint::where('event_id', $odds['event_id']) ->where('bookmaker_id', $odds['bookmaker_id']) ->where('handicap', $odds['handicap']) ->first(); if (! $res) { OddsPoint::create($odds); } elseif (! $block_update) { $res->home = $odds['home']; $res->away = $odds['away']; $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_points'); } }