From 93a09f63ade37eaca025f42eb0af07bfb4c65310 Mon Sep 17 00:00:00 2001 From: Thekindbull Date: Tue, 27 May 2025 08:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=B1=D0=B0=D0=B3=D0=B8=20=D0=B2=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D1=83=D0=BB=D0=B5=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bitrix/ClientsApiController.php | 45 ++++++++------ .../Bitrix/ContractApiController.php | 21 ++++--- .../NotificationProbeController.php | 4 +- .../Notice/Views/user-notifications.blade.php | 2 +- app/Notifications/ContractUpdated.php | 62 +++++++++++++++++++ app/Notifications/NotUniqueContact.php | 62 +++++++++++++++++++ lang/ru/notifications.php | 7 ++- 7 files changed, 169 insertions(+), 34 deletions(-) create mode 100644 app/Notifications/ContractUpdated.php create mode 100644 app/Notifications/NotUniqueContact.php diff --git a/app/Http/Controllers/Bitrix/ClientsApiController.php b/app/Http/Controllers/Bitrix/ClientsApiController.php index dcbe8b5..8a74095 100644 --- a/app/Http/Controllers/Bitrix/ClientsApiController.php +++ b/app/Http/Controllers/Bitrix/ClientsApiController.php @@ -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); - } } +} diff --git a/app/Http/Controllers/Bitrix/ContractApiController.php b/app/Http/Controllers/Bitrix/ContractApiController.php index 88dfe1b..4e827b9 100644 --- a/app/Http/Controllers/Bitrix/ContractApiController.php +++ b/app/Http/Controllers/Bitrix/ContractApiController.php @@ -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; - } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/app/Http/Controllers/NotificationProbeController.php b/app/Http/Controllers/NotificationProbeController.php index 841f609..e08a947 100644 --- a/app/Http/Controllers/NotificationProbeController.php +++ b/app/Http/Controllers/NotificationProbeController.php @@ -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() . '
'; die(auth()->user()->notifications); } diff --git a/app/Modules/Notice/Views/user-notifications.blade.php b/app/Modules/Notice/Views/user-notifications.blade.php index 6213474..6bd3c44 100644 --- a/app/Modules/Notice/Views/user-notifications.blade.php +++ b/app/Modules/Notice/Views/user-notifications.blade.php @@ -3,7 +3,7 @@
- {{ __('notification.has no notifications') }} + {{ __('notifications.has no notifications') }}
@else diff --git a/app/Notifications/ContractUpdated.php b/app/Notifications/ContractUpdated.php new file mode 100644 index 0000000..cbdb740 --- /dev/null +++ b/app/Notifications/ContractUpdated.php @@ -0,0 +1,62 @@ +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 + */ + 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 [ + 'contract' => $this->contract->id, + 'text' => __('notifications.' . get_class($this), ['contact' => $this->contract->deal->user->name]) + ]; + } +} diff --git a/app/Notifications/NotUniqueContact.php b/app/Notifications/NotUniqueContact.php new file mode 100644 index 0000000..97b2596 --- /dev/null +++ b/app/Notifications/NotUniqueContact.php @@ -0,0 +1,62 @@ +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 + */ + 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 [ + 'deal' => $this->deal->id, + 'text' => __('notifications.' . get_class($this), ['contact' => $this->deal->user->name]) + ]; + } +} diff --git a/lang/ru/notifications.php b/lang/ru/notifications.php index 7646881..9f7551e 100644 --- a/lang/ru/notifications.php +++ b/lang/ru/notifications.php @@ -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" обновлен', ];