исправлены баги в модуле уведомлений
This commit is contained in:
parent
57b1c744b9
commit
93a09f63ad
@ -7,10 +7,12 @@
|
|||||||
|
|
||||||
use App\Models\Deal\Deal;
|
use App\Models\Deal\Deal;
|
||||||
use App\Models\Deal\DealStatus;
|
use App\Models\Deal\DealStatus;
|
||||||
|
use App\Notifications\UniqueContact;
|
||||||
|
use App\Notifications\NotUniqueContact;
|
||||||
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
|
||||||
class ClientsApiController extends Controller
|
class ClientsApiController extends Controller
|
||||||
{
|
{
|
||||||
public const ACTION_CONFIRM = 'confirm';
|
public const ACTION_CONFIRM = 'confirm';
|
||||||
@ -35,13 +37,16 @@ public function index(Request $request)
|
|||||||
|
|
||||||
public function confirm(Deal $deal, Request $request)
|
public function confirm(Deal $deal, Request $request)
|
||||||
{
|
{
|
||||||
|
$agent = $deal->agent;
|
||||||
if ((bool) $request->is_unique)
|
if ((bool) $request->is_unique)
|
||||||
{
|
{
|
||||||
$deal->status = DealStatus::UNIQUE;
|
$deal->status = DealStatus::UNIQUE;
|
||||||
|
$agent->user->notify(new UniqueContact($deal));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$deal->status = DealStatus::NOT_UNIQUE;
|
$deal->status = DealStatus::NOT_UNIQUE;
|
||||||
|
$agent->user->notify(new NotUniqueContact($deal));
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::build([
|
Log::build([
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
use App\Models\Deal\Contract;
|
use App\Models\Deal\Contract;
|
||||||
use App\Models\Deal\ContractStatus;
|
use App\Models\Deal\ContractStatus;
|
||||||
use App\Models\Agent\Agent;
|
use App\Models\Agent\Agent;
|
||||||
|
use App\Notifications\ContractUpdated;
|
||||||
class ContractApiController
|
class ContractApiController
|
||||||
{
|
{
|
||||||
public function __invoke(Deal $deal, Request $request)
|
public function __invoke(Deal $deal, Request $request)
|
||||||
@ -25,6 +26,8 @@ public function __invoke(Deal $deal, Request $request)
|
|||||||
'floor' => $request->floor
|
'floor' => $request->floor
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$agent = $deal->agent;
|
||||||
|
$agent->user->notify(new ContractUpdated($deal->contract));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,12 +6,14 @@
|
|||||||
use App\Models\Deal\Deal;
|
use App\Models\Deal\Deal;
|
||||||
|
|
||||||
use App\Notifications\UniqueContact;
|
use App\Notifications\UniqueContact;
|
||||||
|
use App\Notifications\NotUniqueContact;
|
||||||
|
use App\Notifications\ContractUpdated;
|
||||||
|
|
||||||
class NotificationProbeController extends Controller
|
class NotificationProbeController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
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>';
|
echo auth()->user()->unreadNotifications->count() . '<br>';
|
||||||
die(auth()->user()->notifications);
|
die(auth()->user()->notifications);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<div class="d-flex justify-content-center align-items-center">
|
<div class="d-flex justify-content-center align-items-center">
|
||||||
<div class="d-grid gap-1 p-3">
|
<div class="d-grid gap-1 p-3">
|
||||||
<i class="bi bi-inbox display-5 text-center"></i>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
|
|||||||
62
app/Notifications/ContractUpdated.php
Normal file
62
app/Notifications/ContractUpdated.php
Normal 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])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
62
app/Notifications/NotUniqueContact.php
Normal file
62
app/Notifications/NotUniqueContact.php
Normal 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])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,7 +12,8 @@
|
|||||||
| has failed, such as for an invalid token or invalid new password.
|
| has failed, such as for an invalid token or invalid new password.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
'has no notifications' => 'Список уведомлений пуст',
|
||||||
'App\Notifications\UniqueContact' => 'Контакт :contact был проверен, уникальность подтверждена',
|
'App\Notifications\UniqueContact' => 'Контакт :contact был проверен, уникальность подтверждена',
|
||||||
|
'App\Notifications\NotUniqueContact' => 'Контакт :contact был проверен и является не уникальным',
|
||||||
|
'App\Notifications\ContractUpdated' => 'Информация о договоре для контакта ":contact" обновлен',
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user