41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Services\Tasks\Notification;
|
|
|
|
use App\Models\EventBookmaker;
|
|
use App\Models\OddsTable;
|
|
use App\Models\PersonalNotification;
|
|
|
|
class LoadAlarmEvents
|
|
{
|
|
public static function load()
|
|
{
|
|
$map = OddsTable::alarm_fieldnames_by_sport();
|
|
|
|
$users = PersonalNotification::where('notify_by_system', 1)->orwhere('notify_by_email', 1)->orderby('bookmaker_id')->get();
|
|
|
|
$alarms = [];
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$events = EventBookmaker::where('bookmaker_id', $user->bookmaker_id)->get();
|
|
|
|
foreach ($events as $event) {
|
|
|
|
foreach ($map[$user->sport_id] as $field) {
|
|
if ($event[$field] == $user->alarm_level_id) {
|
|
if ($user->notify_by_system) {
|
|
$alarms[$event->event_id][$user->user_id][$user->bookmaker_id]['system'][$field] = $event[$field];
|
|
}
|
|
if ($user->notify_by_email) {
|
|
$alarms[$event->event_id][$user->user_id][$user->bookmaker_id]['mail'][$field] = $event[$field];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $alarms;
|
|
}
|
|
}
|