Files
nuhodds_fi4/app/Console/Commands/Services/Tasks/Alarm/AlarmStore.php
T
2026-02-06 17:55:18 +01:00

66 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Models\EventBookmaker;
use PDOException;
class AlarmStore
{
public static function get($event_id, $oddnames, $client_bookmaker_id, $alarm_threshold, $compare_odds, $client_odds)
{
if (! $compare_odds) {
return;
}
if (! $client_odds) {
return;
}
$favorit = min($client_odds);
$update_array = [];
foreach ($oddnames as $fieldname => $oddname) {
if ($client_odds[$oddname] == $favorit) {
$threshold = $client_odds[$oddname] - $compare_odds[$oddname];
if ($threshold > $alarm_threshold[3]) {
// ROT
$update_array[$fieldname] = 3;
} elseif ($threshold > $alarm_threshold[2]) {
// ORANGE
$update_array[$fieldname] = 2;
} elseif ($threshold > $alarm_threshold[1]) {
// GRÜNE
$update_array[$fieldname] = 1;
} else {
// Reset Alarm
$update_array[$fieldname] = 0;
}
} else {
$update_array[$fieldname] = 0;
}
}
$max_tries = 5;
$tries = 0;
do {
$retry = false;
try {
$res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $client_bookmaker_id)->update($update_array);
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);
}
}