alarm messages
This commit is contained in:
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'),
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OddsName extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'alarm',
|
||||
'table',
|
||||
'bettype',
|
||||
];
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
}
|
||||
Reference in new issue
Block a user