исправлены баги в модуле уведомлений

This commit is contained in:
Thekindbull 2025-05-27 08:53:58 +08:00
parent 57b1c744b9
commit 93a09f63ad
7 changed files with 169 additions and 34 deletions

View File

@ -7,10 +7,12 @@
use App\Models\Deal\Deal;
use App\Models\Deal\DealStatus;
use App\Notifications\UniqueContact;
use App\Notifications\NotUniqueContact;
use Illuminate\Support\Facades\Log;
class ClientsApiController extends Controller
{
public const ACTION_CONFIRM = 'confirm';
@ -35,13 +37,16 @@ public function index(Request $request)
public function confirm(Deal $deal, Request $request)
{
$agent = $deal->agent;
if ((bool) $request->is_unique)
{
$deal->status = DealStatus::UNIQUE;
$agent->user->notify(new UniqueContact($deal));
}
else
{
$deal->status = DealStatus::NOT_UNIQUE;
$agent->user->notify(new NotUniqueContact($deal));
}
Log::build([

View File

@ -9,6 +9,7 @@
use App\Models\Deal\Contract;
use App\Models\Deal\ContractStatus;
use App\Models\Agent\Agent;
use App\Notifications\ContractUpdated;
class ContractApiController
{
public function __invoke(Deal $deal, Request $request)
@ -25,6 +26,8 @@ public function __invoke(Deal $deal, Request $request)
'floor' => $request->floor
]
);
$agent = $deal->agent;
$agent->user->notify(new ContractUpdated($deal->contract));
return true;
}
}

View File

@ -6,12 +6,14 @@
use App\Models\Deal\Deal;
use App\Notifications\UniqueContact;
use App\Notifications\NotUniqueContact;
use App\Notifications\ContractUpdated;
class NotificationProbeController extends Controller
{
public function index()
{
auth()->user()->notify(new UniqueContact(Deal::find(4)));
auth()->user()->notify(new ContractUpdated(Deal::find(4)->contract));
echo auth()->user()->unreadNotifications->count() . '<br>';
die(auth()->user()->notifications);
}

View File

@ -3,7 +3,7 @@
<div class="d-flex justify-content-center align-items-center">
<div class="d-grid gap-1 p-3">
<i class="bi bi-inbox display-5 text-center"></i>
<span class="fs-6 fw-semibold">{{ __('notification.has no notifications') }}</span>
<span class="fs-6 fw-semibold">{{ __('notifications.has no notifications') }}</span>
</div>
</div>
@else

View File

@ -0,0 +1,62 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Models\Deal\Contract;
use App\Models\Deal\DealStatus;
class ContractUpdated extends Notification
{
use Queueable;
private $contract;
/**
* Create a new notification instance.
*/
public function __construct(Contract $contract)
{
/*if ($deal->status != DealStatus::NOT_UNIQUE)
{
throw new \Exception('Notification sending: deal is unique, but request as unique');
}*/
$this->contract = $contract;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'contract' => $this->contract->id,
'text' => __('notifications.' . get_class($this), ['contact' => $this->contract->deal->user->name])
];
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Models\Deal\Deal;
use App\Models\Deal\DealStatus;
class NotUniqueContact extends Notification
{
use Queueable;
private $deal;
/**
* Create a new notification instance.
*/
public function __construct(Deal $deal)
{
if ($deal->status != DealStatus::NOT_UNIQUE)
{
//throw new \Exception('Notification sending: deal is unique, but request as unique');
}
$this->deal = $deal;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'deal' => $this->deal->id,
'text' => __('notifications.' . get_class($this), ['contact' => $this->deal->user->name])
];
}
}

View File

@ -12,7 +12,8 @@
| has failed, such as for an invalid token or invalid new password.
|
*/
'has no notifications' => 'Список уведомлений пуст',
'App\Notifications\UniqueContact' => 'Контакт :contact был проверен, уникальность подтверждена',
'App\Notifications\NotUniqueContact' => 'Контакт :contact был проверен и является не уникальным',
'App\Notifications\ContractUpdated' => 'Информация о договоре для контакта ":contact" обновлен',
];