From b9dc42166ed6cea36d7c38feb58c793a400764b5 Mon Sep 17 00:00:00 2001 From: Thekindbull Date: Tue, 27 May 2025 09:21:41 +0800 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BB=D0=BE=D0=B3=20=D0=BF=D0=BE=20=D1=81=D1=83=D1=89?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8F=D0=BC=20=D0=BA=D0=BE=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D0=BE=D0=B2=20=D0=B8=20=D0=B4=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bitrix/ClientsApiController.php | 4 ++ .../NotificationProbeController.php | 4 +- app/Models/Deal/Deal.php | 41 ++++++++------ app/Notifications/Deal/ContractUpdated.php | 56 +++++++++++++++++++ app/Notifications/Deal/DealCreated.php | 56 +++++++++++++++++++ app/Notifications/Deal/DealNotUnique.php | 55 ++++++++++++++++++ app/Notifications/Deal/DealUnique.php | 56 +++++++++++++++++++ lang/ru/notifications.php | 14 +++-- 8 files changed, 263 insertions(+), 23 deletions(-) create mode 100644 app/Notifications/Deal/ContractUpdated.php create mode 100644 app/Notifications/Deal/DealCreated.php create mode 100644 app/Notifications/Deal/DealNotUnique.php create mode 100644 app/Notifications/Deal/DealUnique.php diff --git a/app/Http/Controllers/Bitrix/ClientsApiController.php b/app/Http/Controllers/Bitrix/ClientsApiController.php index 8a74095..319ebaf 100644 --- a/app/Http/Controllers/Bitrix/ClientsApiController.php +++ b/app/Http/Controllers/Bitrix/ClientsApiController.php @@ -9,6 +9,8 @@ use App\Models\Deal\DealStatus; use App\Notifications\UniqueContact; use App\Notifications\NotUniqueContact; +use App\Notifications\Deal\DealUnique; +use App\Notifications\Deal\DealNotUnique; use Illuminate\Support\Facades\Log; @@ -42,11 +44,13 @@ public function confirm(Deal $deal, Request $request) { $deal->status = DealStatus::UNIQUE; $agent->user->notify(new UniqueContact($deal)); + $deal->notify(new DealUnique()); } else { $deal->status = DealStatus::NOT_UNIQUE; $agent->user->notify(new NotUniqueContact($deal)); + $deal->notify(new DealNotUnique()); } Log::build([ diff --git a/app/Http/Controllers/NotificationProbeController.php b/app/Http/Controllers/NotificationProbeController.php index e08a947..eaca7e3 100644 --- a/app/Http/Controllers/NotificationProbeController.php +++ b/app/Http/Controllers/NotificationProbeController.php @@ -8,12 +8,14 @@ use App\Notifications\UniqueContact; use App\Notifications\NotUniqueContact; use App\Notifications\ContractUpdated; +use App\Notifications\Deal\DealCreated; + class NotificationProbeController extends Controller { public function index() { - auth()->user()->notify(new ContractUpdated(Deal::find(4)->contract)); + Deal::find(4)->notify(new DealCreated()); echo auth()->user()->unreadNotifications->count() . '
'; die(auth()->user()->notifications); } diff --git a/app/Models/Deal/Deal.php b/app/Models/Deal/Deal.php index ea19228..083e377 100644 --- a/app/Models/Deal/Deal.php +++ b/app/Models/Deal/Deal.php @@ -8,9 +8,11 @@ use App\Models\User\UserRole; use App\Models\User\Role; +use Illuminate\Notifications\Notifiable; + class Deal extends Model - { - use HasFactory; +{ + use HasFactory, Notifiable; protected $fillable = [ 'client_id', 'complex_id', @@ -20,39 +22,42 @@ class Deal extends Model 'confirm_token' ]; public function complex() - { + { return $this->belongsTo(\App\Models\Complex::class); - } + } public function user() - { + { return $this->belongsTo(\App\Models\User::class, 'client_id'); - } + } public function agent() - { + { return $this->belongsTo(\App\Models\Agent\Agent::class, 'agent_id'); - } + } public function contract() - { + { return $this->hasOne(Contract::class, 'deal_id'); - } + } protected static function booted(): void - { + { static::created(function (Deal $deal) - { + { UserRole::create([ 'user_id' => $deal->client_id, 'role_id' => Role::CLIENT ]); - }); + + //$this->notify(); + }); + static::deleted(function (Deal $deal) - { - UserRole::where([ + { + /*UserRole::where([ 'user_id' => $deal->client_id, 'role_id' => Role::CLIENT - ])->delete(); - }); + ])->delete();*/ + }); - } } +} diff --git a/app/Notifications/Deal/ContractUpdated.php b/app/Notifications/Deal/ContractUpdated.php new file mode 100644 index 0000000..567cdd0 --- /dev/null +++ b/app/Notifications/Deal/ContractUpdated.php @@ -0,0 +1,56 @@ + + */ + 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 + */ + public function toArray(object $notifiable): array + { + return [ + 'text' => __('notifications.' . get_class($this)) + ]; + } +} diff --git a/app/Notifications/Deal/DealCreated.php b/app/Notifications/Deal/DealCreated.php new file mode 100644 index 0000000..f3f8956 --- /dev/null +++ b/app/Notifications/Deal/DealCreated.php @@ -0,0 +1,56 @@ + + */ + 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 + */ + public function toArray(object $notifiable): array + { + return [ + 'text' => __('notifications.' . get_class($this)) + ]; + } +} diff --git a/app/Notifications/Deal/DealNotUnique.php b/app/Notifications/Deal/DealNotUnique.php new file mode 100644 index 0000000..9c9b0d7 --- /dev/null +++ b/app/Notifications/Deal/DealNotUnique.php @@ -0,0 +1,55 @@ + + */ + 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 + */ + public function toArray(object $notifiable): array + { + return [ + 'text' => __('notifications.' . get_class($this)) + ]; + } +} diff --git a/app/Notifications/Deal/DealUnique.php b/app/Notifications/Deal/DealUnique.php new file mode 100644 index 0000000..f3f8956 --- /dev/null +++ b/app/Notifications/Deal/DealUnique.php @@ -0,0 +1,56 @@ + + */ + 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 + */ + public function toArray(object $notifiable): array + { + return [ + 'text' => __('notifications.' . get_class($this)) + ]; + } +} diff --git a/lang/ru/notifications.php b/lang/ru/notifications.php index 9f7551e..0ef4ed8 100644 --- a/lang/ru/notifications.php +++ b/lang/ru/notifications.php @@ -12,8 +12,14 @@ | 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" обновлен', + 'has no notifications' => 'Список уведомлений пуст', + 'App\Notifications\UniqueContact' => 'Контакт :contact был проверен, уникальность подтверждена', + 'App\Notifications\NotUniqueContact' => 'Контакт :contact был проверен и является не уникальным', + 'App\Notifications\ContractUpdated' => 'Информация о договоре для контакта ":contact" обновлен', + + 'App\Notifications\Deal\DealCreated' => 'Контакт создан', + 'App\Notifications\Deal\DealUnique' => 'Стутус контакта изменен на "уникальный"', + 'App\Notifications\Deal\DealNotUnique' => 'Стутус контакта изменен на "не уникальный"', + 'App\Notifications\Deal\ContractUpdated' => 'Информация о договоре обновлена', + ];