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();
}
}
}
@@ -114,11 +114,11 @@ class SupervisorsTable
Stack::make([
TextInputColumn::make('days_from')->prefix('Days Fr')
->hidden(function (ListSupervisors $livewire) {
return $livewire->tableFilters['provider_id']['value'] == 8;
return in_array($livewire->tableFilters['provider_id']['value'], [7, 8]);
}),
TextInputColumn::make('days_to')->prefix('Days To')
->hidden(function (ListSupervisors $livewire) {
return $livewire->tableFilters['provider_id']['value'] == 8;
return in_array($livewire->tableFilters['provider_id']['value'], [7, 8]);
}),
])->space(3),
Stack::make([
@@ -149,7 +149,6 @@ class SupervisorsTable
->relationship('provider', 'name')
->label('Provider'),
SelectFilter::make('sport_id')
->default(1)
->relationship('sport', 'name')
->label('Sport'),
TernaryFilter::make('is_supervisor')->label('Run by supervisor'),
-16
View File
@@ -3,7 +3,6 @@
namespace App\Livewire;
use App\Mail\UserNotification;
use App\Models\PersonalNotification;
use App\Models\User;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
@@ -14,7 +13,6 @@ use Filament\Notifications\Notification;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Support\Enums\Width;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
@@ -78,20 +76,6 @@ class UserNotifications extends Component implements HasActions, HasSchemas, Has
]);
}
public function table2(Table $table): Table
{
return $table
->query(PersonalNotification::query()->where('user_id', auth()->user()->id))
->columns([
IconColumn::make('sport.icon')
->label('')
->icon(fn ($record) => $record->sport->icon)
->tooltip(fn ($record) => $record->id)
->visibleFrom('lg'),
]);
}
public function render(): View
{
return view('livewire.user-notifications');
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class AlarmNotification extends Mailable
{
use Queueable, SerializesModels;
protected string $message;
protected string $table;
/**
* Create a new message instance.
*/
public function __construct($message, $table)
{
$this->message = $message;
$this->table = $table;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'NUH-Odds Alarm',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
markdown: 'mail.user.alarm',
with: [
'table' => $this->table,
'message' => $this->message,
],
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OddsName extends Model
{
protected $fillable = [
'name',
'alarm',
'table',
'bettype',
];
}
+51
View File
@@ -6,6 +6,26 @@ use Illuminate\Database\Eloquent\Model;
class OddsTable extends Model
{
// public static function tmp()
// {
// $res = OddsTable::get();
// $arr = [];
// foreach ($res as $value) {
// $names = explode(',', $value->oddnames);
// $fields = explode(',', $value->fieldnames);
// $base = [];
// $base['table'] = $value->name;
// $base['bettype'] = $value->fulltitle;
// $tmp = array_combine($fields, $names);
// foreach ($tmp as $alarm => $name) {
// $base['name'] = $name;
// $base['alarm'] = $alarm;
// $arr[] = $base;
// }
// }
// return $arr;
// }
public static function oddnames()
{
$res = OddsTable::get();
@@ -20,6 +40,37 @@ class OddsTable extends Model
return $arr;
}
public static function alarm_fieldnames_by_sport()
{
$arr = [];
$arr[1] = [];
$arr[2] = [];
$arr[3] = [];
$arr[5] = [];
$res = OddsTable::get();
foreach ($res as $value) {
$fields = explode(',', $value->fieldnames);
$selectfields = implode("'", $fields);
if ($value->soccer == 1) {
$arr[1] = array_merge($arr[1], $fields);
}
if ($value->icehockey == 1) {
$arr[2] = array_merge($arr[2], $fields);
}
if ($value->basketball == 1) {
$arr[3] = array_merge($arr[3], $fields);
}
if ($value->tennis == 1) {
$arr[5] = array_merge($arr[5], $fields);
}
}
return $arr;
}
public static function fields()
{
$res = OddsTable::get();
+9 -1
View File
@@ -6,5 +6,13 @@ use Illuminate\Database\Eloquent\Model;
class PersonalNotificationSend extends Model
{
//
protected $fillable = [
'event_id',
'user_id',
'bookmaker_id',
'alarm_level_id',
'fieldname',
'notify_by_system',
'notify_by_email',
];
}
@@ -17,6 +17,9 @@ return new class extends Migration
$table->integer('user_id')->index()->references('id')->on('users');
$table->integer('bookmaker_id')->index()->references('id')->on('bookmakers');
$table->integer('alarm_level_id')->default(0);
$table->string('fieldname');
$table->boolean('notify_by_system')->default(0);
$table->boolean('notify_by_email')->default(0);
$table->timestamps();
});
}
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('odds_names', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('alarm');
$table->string('table');
$table->string('bettype');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('odds_names');
}
};
+1
View File
@@ -25,6 +25,7 @@ class DatabaseSeeder extends Seeder
CountryItalianSeeder::class,
OddsTableSeeder::class,
AlarmLevelSeeder::class,
OddsNameSeeder::class,
]);
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class OddsNameSeeder extends Seeder
{
public function run(): void
{
/**
* Provoider
*/
$sql = "INSERT INTO `odds_names` (`id`, `name`, `alarm`, `table`, `bettype`, `created_at`, `updated_at`)
VALUES
(1, 'h2w', 'alarm_2w_h2w', 'odds_2ways', 'Money Line', NULL, NULL),
(2, 'a2w', 'alarm_2w_a2w', 'odds_2ways', 'Money Line', NULL, NULL),
(3, 'h2w', 'alarm_2ws1_h2w', 'odds_2ways_s1', 'Money Line Set1', NULL, NULL),
(4, 'a2w', 'alarm_2ws1_a2w', 'odds_2ways_s1', 'Money Line Set1', NULL, NULL),
(5, 'h3w', 'alarm_3w_h3w', 'odds_3ways', '1X2', NULL, NULL),
(6, 'd3w', 'alarm_3w_d3w', 'odds_3ways', '1X2', NULL, NULL),
(7, 'a3w', 'alarm_3w_a3w', 'odds_3ways', '1X2', NULL, NULL),
(8, 'h3w', 'alarm_3wht_h3w', 'odds_3ways_ht', '1X2 Halftime', NULL, NULL),
(9, 'd3w', 'alarm_3wht_d3w', 'odds_3ways_ht', '1X2 Halftime', NULL, NULL),
(10, 'a3w', 'alarm_3wht_a3w', 'odds_3ways_ht', '1X2 Halftime', NULL, NULL),
(11, 'dc1x', 'alarm_dc_dc1x', 'odds_dc', 'Double Chance', NULL, NULL),
(12, 'dc12', 'alarm_dc_dc12', 'odds_dc', 'Double Chance', NULL, NULL),
(13, 'dcx2', 'alarm_dc_dcx2', 'odds_dc', 'Double Chance', NULL, NULL),
(14, 'dnb1', 'alarm_dbn_dnb1', 'odds_dnb', 'Draw no bet', NULL, NULL),
(15, 'dnb2', 'alarm_dbn_dnb2', 'odds_dnb', 'Draw no bet', NULL, NULL),
(16, 'gg', 'alarm_ggng_gg', 'odds_ggng', 'Goal No Goal', NULL, NULL),
(17, 'ng', 'alarm_ggng_ng', 'odds_ggng', 'Goal No Goal', NULL, NULL),
(18, 'home', 'alarm_po_home', 'odds_points', 'Points', NULL, NULL),
(19, 'away', 'alarm_po_away', 'odds_points', 'Points', NULL, NULL),
(20, 'home', 'alarm_poht_home', 'odds_points_ht', 'Points Halftime', NULL, NULL),
(21, 'away', 'alarm_poht_away', 'odds_points_ht', 'Points Halftime', NULL, NULL),
(22, 'home', 'alarm_poq1_home', 'odds_points_q1', 'Points First Quarter', NULL, NULL),
(23, 'away', 'alarm_poq1_away', 'odds_points_q1', 'Points First Quarter', NULL, NULL),
(24, 'over', 'alarm_to_over', 'odds_totals', 'Totals', NULL, NULL),
(25, 'under', 'alarm_to_under', 'odds_totals', 'Totals', NULL, NULL),
(26, 'over', 'alarm_toht_over', 'odds_totals_ht', 'Totals Halftime', NULL, NULL),
(27, 'under', 'alarm_toht_under', 'odds_totals_ht', 'Totals Halftime', NULL, NULL),
(28, 'over', 'alarm_toq1_over', 'odds_totals_q1', 'Totals First Quarter', NULL, NULL),
(29, 'under', 'alarm_toq1_under', 'odds_totals_q1', 'Totals First Quarter', NULL, NULL),
(30, 'htq', 'alarm_tq_htq', 'odds_tq', 'To Qualify', NULL, NULL),
(31, 'atq', 'alarm_tq_atq', 'odds_tq', 'To Qualify', NULL, NULL);
";
DB::unprepared($sql);
}
}
+3 -2
View File
@@ -68,8 +68,9 @@ class SupervisorSeeder extends Seeder
(52, '', 10, 0, NULL, 30, 0, NULL, NULL, 30, 0, 0, 0, 0, 10, 10, '2026-01-16 12:05:14', '2026-01-16 12:05:14'),
(53, 'Generate Setting', 7, 0, NULL, 30, 0, '0.02', NULL, 30, 0, 0, 0, 0, 10, 10, '2026-01-16 12:05:14', '2026-01-27 13:39:46'),
(54, 'Generate Alarms', 7, 1, NULL, 30, 0, '0', NULL, 30, 0, 0, 0, 0, 10, 10, '2026-01-16 12:05:14', '2026-01-27 13:42:39'),
(55, 'Txodds Flags', 7, NULL, NULL, 30, 0, NULL, NULL, 30, 0, 0, 0, 0, 10, 10, '2026-01-27 11:25:56', '2026-01-27 11:26:05');
";
(55, 'Txodds Flags', 7, NULL, NULL, 30, 0, NULL, NULL, 30, 0, 0, 0, 0, 10, 10, '2026-01-27 11:25:56', '2026-01-27 11:26:05'),
(56, 'Notify Alarms', 7, NULL, NULL, 30, 0, NULL, NULL, 30, 0, 0, 0, 0, 10, 10, '2026-01-27 11:25:56', '2026-01-27 11:26:05');
";
DB::unprepared($sql);
}
}
+34
View File
@@ -0,0 +1,34 @@
<x-mail::message>
<em>Message from NUH-Odds Alarm Monitoring</em>
<br><br>
{{ $message }}
<x-mail::table>
{{ $table[0]['key'] }}
${{ $table[0]['value'] }}
{{ $table[1]['key'] }}
${{ $table[1]['value'] }}
{{ $table[2]['key'] }}
${{ $table[2]['value'] }}
{{ $table[3]['key'] }}
${{ $table[3]['value'] }}
{{ $table[4]['key'] }}
${{ $table[4]['value'] }}
{{ $table[5]['key'] }}
${{ $table[5]['value'] }}
{{ $table[6]['key'] }}
${{ $table[6]['value'] }}
</x-mail::table>
Thanks,<br>
Alarm Monitoring Team
</x-mail::message>