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' => 'Информация о договоре обновлена',
+
];