153 lines
5.0 KiB
PHP
153 lines
5.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Modules\RestaurantDelivery\Notifications;
|
||
|
|
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
||
|
|
use Illuminate\Notifications\Notification;
|
||
|
|
use Modules\RestaurantDelivery\Models\Rider;
|
||
|
|
|
||
|
|
class RiderWarningNotification extends Notification implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Queueable;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a new notification instance.
|
||
|
|
*/
|
||
|
|
public function __construct(
|
||
|
|
public readonly Rider $rider,
|
||
|
|
public readonly string $warningType,
|
||
|
|
public readonly ?array $details = null
|
||
|
|
) {
|
||
|
|
$this->onQueue(config('restaurant-delivery.queue.queues.notifications', 'restaurant-delivery-notifications'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the notification's delivery channels.
|
||
|
|
*/
|
||
|
|
public function via(object $notifiable): array
|
||
|
|
{
|
||
|
|
return ['database', 'mail'];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the mail representation of the notification.
|
||
|
|
*/
|
||
|
|
public function toMail(object $notifiable): MailMessage
|
||
|
|
{
|
||
|
|
$message = (new MailMessage)
|
||
|
|
->subject($this->getSubject())
|
||
|
|
->greeting("Hello {$this->rider->first_name},");
|
||
|
|
|
||
|
|
$content = $this->getContent();
|
||
|
|
foreach ($content['lines'] as $line) {
|
||
|
|
$message->line($line);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($content['action'])) {
|
||
|
|
$message->action($content['action']['text'], $content['action']['url']);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $message->line('If you have any questions, please contact support.');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the array representation of the notification.
|
||
|
|
*/
|
||
|
|
public function toArray(object $notifiable): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'type' => 'rider_warning',
|
||
|
|
'warning_type' => $this->warningType,
|
||
|
|
'rider_id' => $this->rider->id,
|
||
|
|
'details' => $this->details,
|
||
|
|
'message' => $this->getMessage(),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get FCM data for push notification.
|
||
|
|
*/
|
||
|
|
public function toFcm(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'title' => $this->getSubject(),
|
||
|
|
'body' => $this->getMessage(),
|
||
|
|
'data' => [
|
||
|
|
'type' => 'rider_warning',
|
||
|
|
'warning_type' => $this->warningType,
|
||
|
|
],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get subject based on warning type.
|
||
|
|
*/
|
||
|
|
protected function getSubject(): string
|
||
|
|
{
|
||
|
|
return match ($this->warningType) {
|
||
|
|
'low_rating' => 'Warning: Your Rating is Getting Low',
|
||
|
|
'high_cancellation' => 'Warning: High Cancellation Rate',
|
||
|
|
'late_deliveries' => 'Warning: Multiple Late Deliveries',
|
||
|
|
'suspension_risk' => 'Warning: Account Suspension Risk',
|
||
|
|
default => 'Important Notice',
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get message based on warning type.
|
||
|
|
*/
|
||
|
|
protected function getMessage(): string
|
||
|
|
{
|
||
|
|
return match ($this->warningType) {
|
||
|
|
'low_rating' => "Your current rating is {$this->rider->rating}. Please work on improving your service quality.",
|
||
|
|
'high_cancellation' => 'Your cancellation rate is higher than acceptable. Please try to complete assigned deliveries.',
|
||
|
|
'late_deliveries' => 'You have had multiple late deliveries recently. Please plan your routes better.',
|
||
|
|
'suspension_risk' => 'Your account is at risk of suspension. Please improve your performance immediately.',
|
||
|
|
default => 'Please review your account status.',
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get content for email.
|
||
|
|
*/
|
||
|
|
protected function getContent(): array
|
||
|
|
{
|
||
|
|
return match ($this->warningType) {
|
||
|
|
'low_rating' => [
|
||
|
|
'lines' => [
|
||
|
|
"We've noticed that your rating has dropped to {$this->rider->rating}.",
|
||
|
|
'Customer ratings are important for maintaining quality service.',
|
||
|
|
'Here are some tips to improve your rating:',
|
||
|
|
'• Be polite and professional with customers',
|
||
|
|
'• Handle food with care to avoid spills',
|
||
|
|
'• Communicate any delays promptly',
|
||
|
|
'• Ensure deliveries are complete and accurate',
|
||
|
|
],
|
||
|
|
'action' => [
|
||
|
|
'text' => 'View My Ratings',
|
||
|
|
'url' => url('/rider/ratings'),
|
||
|
|
],
|
||
|
|
],
|
||
|
|
'high_cancellation' => [
|
||
|
|
'lines' => [
|
||
|
|
'Your cancellation rate has exceeded acceptable limits.',
|
||
|
|
'Frequent cancellations affect your earnings and account standing.',
|
||
|
|
'Please only accept orders you can complete.',
|
||
|
|
'If you face issues with specific deliveries, contact support before cancelling.',
|
||
|
|
],
|
||
|
|
],
|
||
|
|
default => [
|
||
|
|
'lines' => [
|
||
|
|
$this->getMessage(),
|
||
|
|
'Please take this warning seriously.',
|
||
|
|
'Contact support if you need assistance.',
|
||
|
|
],
|
||
|
|
],
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|