add alarm level from db

This commit is contained in:
salam committed 2026-02-06 10:29:49 +01:00
1 parent 4e77862aa7
commit 40f40db63c
28 files changed
+248 -251

No files matched your search

+123
View File
@@ -0,0 +1,123 @@
<?php
namespace App\Actions;
use App\Models\AlarmLevel;
use App\Models\AlarmSetting;
use App\Models\Bookmaker;
use App\Models\ComparingBookmaker;
use App\Models\MultilineClient;
use App\Models\MultilineSetting;
use App\Models\Sport;
use Filament\Notifications\Notification;
class SettingGeneratorClient
{
public static function run($record)
{
/**************************************************
* 1) ALARM SETTING (client_bookmaker_id)
**************************************************/
$alarm_levels = AlarmLevel::get();
foreach ($record->sport as $sport_id) {
foreach ($record->bookmaker as $client_bookmaker_id) {
$multilines = MultilineSetting::where('sport_id', $sport_id)->get()->pluck('id');
foreach ($multilines as $multiline_id) {
foreach ($alarm_levels as $alarm_level) {
AlarmSetting::firstOrCreate(
['client_bookmaker_id' => $client_bookmaker_id, 'sport_id' => $sport_id, 'multiline_setting_id' => $multiline_id, 'alarm_level_id' => $alarm_level->id],
['alarm_threshold' => $alarm_level->default_threshold]
);
}
}
}
}
/**************************************************
* 2) MULTILINE SLOTS (client_bookmaker_id)
**************************************************/
$bookmaker_slots = [1 => 6, 2 => 30, 3 => 649, 4 => 126];
foreach ($record->sport as $sport_id) {
foreach ($record->bookmaker as $client_bookmaker_id) {
$multilines = MultilineSetting::where('sport_id', $sport_id)->get()->pluck('id');
foreach ($multilines as $multiline_id) {
foreach ($bookmaker_slots as $slot => $bookmaker_id) {
MultilineClient::firstOrCreate(
['client_bookmaker_id' => $client_bookmaker_id, 'sport_id' => $sport_id, 'multiline_setting_id' => $multiline_id, 'position' => $slot],
['bookmaker_id' => $bookmaker_id, 'sort' => $slot, 'disabled' => 0]
);
}
}
}
}
/**************************************************
* 4) COMPARING BOOKMAKER (client_bookmaker_id)
**************************************************/
$bookmakers_soccer = Bookmaker::where('in_soccer', 1)->orderBy('name')->pluck('id')->toArray();
ComparingBookmaker::where('method_id', 1)->where('sport_id', 1)->whereNotIn('bookmaker_id', $bookmakers_soccer)->delete();
foreach ($record as $client) {
foreach ($record->bookmaker as $client_bookmaker_id) {
$i = 1;
foreach ($bookmakers_soccer as $bookmaker_id) {
$margin_threshold = $bookmaker_id == 110 ? 103 : 115;
ComparingBookmaker::updateOrCreate(
['method_id' => 1, 'sport_id' => 1, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id],
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => $margin_threshold, 'sorting' => $i]
);
$i++;
}
}
}
$sports = Sport::getActiveSports();
if (($key = array_search(1, $sports)) !== false) {
unset($sports[$key]);
}
$bookmakers_other = Bookmaker::where('in_other', 1)->orderBy('name')->pluck('id')->toArray();
ComparingBookmaker::where('method_id', 1)->whereIn('sport_id', $sports)->whereNotIn('bookmaker_id', $bookmakers_other)->delete();
foreach ($record as $client) {
foreach ($record->bookmaker as $client_bookmaker_id) {
foreach ($sports as $sport_id) {
$i = 1;
foreach ($bookmakers_other as $bookmaker_id) {
ComparingBookmaker::updateOrCreate(
['method_id' => 1, 'sport_id' => $sport_id, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id],
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => 110, 'sorting' => $i]
);
$i++;
}
}
}
}
Notification::make()
->title('Settings generated successfully')
->success()
->send();
}
}