исправлены баги в модуле уведомлений
This commit is contained in:
parent
57b1c744b9
commit
93a09f63ad
@ -7,62 +7,67 @@
|
||||
|
||||
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';
|
||||
{
|
||||
public const ACTION_CONFIRM = 'confirm';
|
||||
public const ACTION_UPDATE_CONTRACT = 'contract';
|
||||
public function index(Request $request)
|
||||
{
|
||||
{
|
||||
if ($deal = Deal::where('confirm_token', $request->hash)->first())
|
||||
{
|
||||
{
|
||||
switch ( $request->action )
|
||||
{
|
||||
{
|
||||
case $this::ACTION_CONFIRM:
|
||||
$this->confirm($deal, $request);
|
||||
break;
|
||||
case $this::ACTION_UPDATE_CONTRACT:
|
||||
$this->updateContract($deal, $request);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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([
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/bitrix.log'),
|
||||
'path' => storage_path('logs/bitrix.log'),
|
||||
])->error(
|
||||
json_encode(
|
||||
[
|
||||
'is_unique' => $request->is_unique,
|
||||
'deal' => $deal->id,
|
||||
'status' => $deal->status
|
||||
'deal' => $deal->id,
|
||||
'status' => $deal->status
|
||||
]
|
||||
)
|
||||
);
|
||||
$deal->save();
|
||||
return $deal->id;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateContract(Deal $deal, Request $request)
|
||||
{
|
||||
{
|
||||
$contract = new ContractApiController;
|
||||
$contract($deal, $request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,22 +9,25 @@
|
||||
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)
|
||||
{
|
||||
{
|
||||
$status =
|
||||
Contract::updateOrCreate(
|
||||
['deal_id' => $deal->id],
|
||||
[
|
||||
'status' => constant(ContractStatus::class . "::" . $request->status),
|
||||
'status' => constant(ContractStatus::class . "::" . $request->status),
|
||||
'comment' => $request->comment,
|
||||
'price' => $request->price,
|
||||
'reward' => $request->reward,
|
||||
'square' => $request->square,
|
||||
'floor' => $request->floor
|
||||
'price' => $request->price,
|
||||
'reward' => $request->reward,
|
||||
'square' => $request->square,
|
||||
'floor' => $request->floor
|
||||
]
|
||||
);
|
||||
$agent = $deal->agent;
|
||||
$agent->user->notify(new ContractUpdated($deal->contract));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
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.
|
||||
|
|
||||
*/
|
||||
|
||||
'App\Notifications\UniqueContact' => 'Контакт :contact был проверен, уникальность подтверждена',
|
||||
|
||||
'has no notifications' => 'Список уведомлений пуст',
|
||||
'App\Notifications\UniqueContact' => 'Контакт :contact был проверен, уникальность подтверждена',
|
||||
'App\Notifications\NotUniqueContact' => 'Контакт :contact был проверен и является не уникальным',
|
||||
'App\Notifications\ContractUpdated' => 'Информация о договоре для контакта ":contact" обновлен',
|
||||
];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user