добавлен лог по сущностям контактов и договоров

This commit is contained in:
Thekindbull 2025-05-27 09:21:41 +08:00
parent 93a09f63ad
commit b9dc42166e
8 changed files with 263 additions and 23 deletions

View File

@ -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([

View File

@ -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() . '<br>';
die(auth()->user()->notifications);
}

View File

@ -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();*/
});
}
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Notifications\Deal;
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 ContractUpdated extends Notification
{
use Queueable;
private $deal;
/**
* Create a new notification instance.
*/
public function __construct()
{
}
/**
* 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 [
'text' => __('notifications.' . get_class($this))
];
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Notifications\Deal;
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 DealCreated extends Notification
{
use Queueable;
private $deal;
/**
* Create a new notification instance.
*/
public function __construct()
{
}
/**
* 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 [
'text' => __('notifications.' . get_class($this))
];
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace App\Notifications\Deal;
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 DealNotUnique extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct()
{
}
/**
* 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 [
'text' => __('notifications.' . get_class($this))
];
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Notifications\Deal;
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 DealCreated extends Notification
{
use Queueable;
private $deal;
/**
* Create a new notification instance.
*/
public function __construct()
{
}
/**
* 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 [
'text' => __('notifications.' . get_class($this))
];
}
}

View File

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