alarm messages

This commit is contained in:
salam committed 2026-02-06 15:49:18 +01:00
1 parent 5a35b90b0d
commit 004e87e6b5
16 files changed
+452 -28

No files matched your search

@@ -0,0 +1,24 @@
<?php
namespace App\Console\Commands\Services\Tasks\Notification;
use App\Models\PersonalNotificationSend;
class CheckSend
{
public static function check($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, $sendtype)
{
$res = PersonalNotificationSend::where('event_id', $event_id)
->where('user_id', $user_id)
->where('bookmaker_id', $bookmaker_id)
->where('alarm_level_id', $alarm_level_id)
->where('fieldname', $fieldname)
->where($sendtype, 1)
->first();
if (! $res) {
return false;
}
return $res->id;
}
}
@@ -0,0 +1,40 @@
<?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;
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands\Services\Tasks\Notification;
use App\Models\PersonalNotificationSend;
class StoreSend
{
public static function store($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, $sendtype)
{
return PersonalNotificationSend::create([
'event_id' => $event_id,
'user_id' => $user_id,
'bookmaker_id' => $bookmaker_id,
'alarm_level_id' => $alarm_level_id,
'fieldname' => $fieldname,
$sendtype => 1,
]);
}
}
@@ -3,8 +3,19 @@
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Console\Commands\Services\Tasks\Notification\CheckSend;
use App\Console\Commands\Services\Tasks\Notification\LoadAlarmEvents;
use App\Console\Commands\Services\Tasks\Notification\StoreSend;
use App\Mail\AlarmNotification;
use App\Models\Bookmaker;
use App\Models\Event;
use App\Models\OddsName;
use App\Models\PersonalNotificationSend;
use App\Models\User;
use App\Utilities\Notice;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
class NotifyAlarms
{
@@ -16,13 +27,101 @@ class NotifyAlarms
Notice::note('Notify Alarms', 'b');
}
/**
* USER
*/
$users = User::all();
$stored_alarms = [];
foreach ($users as $user) {
dd($user);
$alarms = LoadAlarmEvents::load();
foreach ($alarms as $event_id => $alarm) {
$event = Event::with('competition_group')->with('home')->with('away')->find($event_id);
foreach ($alarm as $user_id => $alarm_user) {
$user = User::find($user_id);
foreach ($alarm_user as $bookmaker_id => $alarm_user_bookmaker) {
$bookmaker = Bookmaker::find($bookmaker_id);
foreach ($alarm_user_bookmaker as $mode => $alarm_user_bookmaker_mode) {
foreach ($alarm_user_bookmaker_mode as $fieldname => $alarm_level_id) {
$bet = OddsName::where('alarm', $fieldname)->select('table', 'bettype', 'name')->first()->toArray();
$quote = DB::table($bet['table'])->where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->value($bet['name']);
switch ($mode) {
case 'mail':
$send = CheckSend::check($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, 'notify_by_email');
if (! $send) {
$send = StoreSend::store($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, 'notify_by_mail');
$message = 'ALARM LEVEL '.$alarm_level_id;
$table = [
['key' => 'League', 'value' => $event->competition_group->name],
['key' => 'Event', 'value' => $event->home.' vs '.$event->away],
['key' => 'Startime', 'value' => $event->starttime],
['key' => 'Bookmaker', 'value' => $bookmaker->name],
['key' => 'Bettype', 'value' => $bet['bettype']],
['key' => 'Odd Name', 'value' => strtoupper($bet['name'])],
['key' => 'Value', 'value' => $quote],
];
Mail::to($user)
->send(new AlarmNotification($message, $table));
}
$stored_alarms[] = $send;
break;
case 'system':
$send = CheckSend::check($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, 'notify_by_system');
if (! $send) {
$send = StoreSend::store($event_id, $user_id, $bookmaker_id, $alarm_level_id, $fieldname, 'notify_by_system');
switch ($alarm_level_id) {
case 1:
$title = '<div class="text-green-500">ALARM LEVEL '.$alarm_level_id.'</div>';
break;
case 2:
$title = '<div class="text-blue-500">ALARM LEVEL '.$alarm_level_id.'</div>';
break;
default:
$title = '<div class="text-red-500">ALARM LEVEL '.$alarm_level_id.'</div>';
break;
}
$message = '<a href="/events?search='.$event_id.'"><div class="grid grid-cols-2 gap-1">';
$message .= '<div>League</div><div>'.$event->competition_group->name.'</div>';
$message .= '<div>Event</div><div>'.$event->home->name.' vs '.$event->away->name.'</div>';
$message .= '<div>Startime</div><div>'.$event->starttime.'</div>';
$message .= '<div>Bookmaker</div><div>'.$bookmaker->name.'</div>';
$message .= '<div>Bettype</div><div>'.$bet['bettype'].'</div>';
$message .= '<div>Odd Name</div><div>'.$bet['name'].'</div>';
$message .= '<div>Value</div><div>'.$quote.'</div></div></a>';
Notification::make()
->title($title)
->icon('phosphor-envelope-duotone')
->body($message)
->sendToDatabase($user);
break;
}
$stored_alarms[] = $send;
}
}
}
}
}
}
if ($stored_alarms) {
PersonalNotificationSend::whereNotIn('id', $stored_alarms)->delete();
}
}
}