migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?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\Delivery;
|
||||
|
||||
class DeliveryStatusNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Delivery $delivery,
|
||||
public readonly string $recipientType = 'customer'
|
||||
) {
|
||||
$this->onQueue(config('restaurant-delivery.queue.queues.notifications', 'restaurant-delivery-notifications'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return array_filter(config('restaurant-delivery.notifications.channels', ['database']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject("Delivery Update: {$this->delivery->status->label()}")
|
||||
->greeting('Hello!')
|
||||
->line("Your delivery #{$this->delivery->tracking_code} status has been updated.")
|
||||
->line("New Status: {$this->delivery->status->label()}")
|
||||
->line($this->delivery->status->description())
|
||||
->action('Track Delivery', $this->getTrackingUrl())
|
||||
->line('Thank you for using our delivery service!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'delivery_status',
|
||||
'delivery_id' => $this->delivery->id,
|
||||
'tracking_code' => $this->delivery->tracking_code,
|
||||
'status' => $this->delivery->status->value,
|
||||
'status_label' => $this->delivery->status->label(),
|
||||
'status_description' => $this->delivery->status->description(),
|
||||
'rider' => $this->delivery->rider ? [
|
||||
'name' => $this->delivery->rider->full_name,
|
||||
'phone' => $this->delivery->rider->phone,
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FCM data for push notification.
|
||||
*/
|
||||
public function toFcm(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Delivery Update',
|
||||
'body' => $this->delivery->status->description(),
|
||||
'data' => [
|
||||
'type' => 'delivery_status',
|
||||
'delivery_id' => (string) $this->delivery->id,
|
||||
'tracking_code' => $this->delivery->tracking_code,
|
||||
'status' => $this->delivery->status->value,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tracking URL.
|
||||
*/
|
||||
protected function getTrackingUrl(): string
|
||||
{
|
||||
return url("/track/{$this->delivery->tracking_code}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Modules\RestaurantDelivery\Models\Delivery;
|
||||
|
||||
class NewDeliveryRequestNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Delivery $delivery,
|
||||
public readonly float $distance,
|
||||
public readonly int $timeout = 30
|
||||
) {
|
||||
$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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'new_delivery_request',
|
||||
'delivery_id' => $this->delivery->id,
|
||||
'tracking_code' => $this->delivery->tracking_code,
|
||||
'restaurant_name' => $this->delivery->restaurant_name,
|
||||
'pickup_address' => $this->delivery->pickup_address,
|
||||
'drop_address' => $this->delivery->drop_address,
|
||||
'distance' => $this->delivery->distance,
|
||||
'distance_to_pickup' => $this->distance,
|
||||
'estimated_earnings' => $this->delivery->total_delivery_charge,
|
||||
'timeout' => $this->timeout,
|
||||
'is_priority' => $this->delivery->is_priority,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FCM data for push notification.
|
||||
*/
|
||||
public function toFcm(): array
|
||||
{
|
||||
$currency = config('restaurant-delivery.pricing.currency_symbol', '৳');
|
||||
|
||||
return [
|
||||
'title' => 'New Delivery Request',
|
||||
'body' => "{$this->delivery->restaurant_name} - ".round($this->distance, 1).' km away',
|
||||
'data' => [
|
||||
'type' => 'delivery_request',
|
||||
'delivery_id' => (string) $this->delivery->id,
|
||||
'tracking_code' => $this->delivery->tracking_code,
|
||||
'restaurant_name' => $this->delivery->restaurant_name,
|
||||
'pickup_address' => $this->delivery->pickup_address,
|
||||
'drop_address' => $this->delivery->drop_address,
|
||||
'distance' => (string) $this->delivery->distance,
|
||||
'distance_to_pickup' => (string) $this->distance,
|
||||
'earnings' => "{$currency}".number_format((float) $this->delivery->total_delivery_charge, 2),
|
||||
'timeout' => (string) $this->timeout,
|
||||
'is_priority' => $this->delivery->is_priority ? 'true' : 'false',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?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\Delivery;
|
||||
|
||||
class RiderAssignedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Delivery $delivery
|
||||
) {
|
||||
$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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$rider = $this->delivery->rider;
|
||||
|
||||
return (new MailMessage)
|
||||
->subject('Rider Assigned to Your Delivery')
|
||||
->greeting('Good news!')
|
||||
->line("A rider has been assigned to your delivery #{$this->delivery->tracking_code}.")
|
||||
->line("Rider: {$rider->full_name}")
|
||||
->line("Vehicle: {$rider->vehicle_type}")
|
||||
->action('Track Your Delivery', $this->getTrackingUrl())
|
||||
->line('You can now track your rider in real-time!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
$rider = $this->delivery->rider;
|
||||
|
||||
return [
|
||||
'type' => 'rider_assigned',
|
||||
'delivery_id' => $this->delivery->id,
|
||||
'tracking_code' => $this->delivery->tracking_code,
|
||||
'rider' => [
|
||||
'id' => $rider->id,
|
||||
'name' => $rider->full_name,
|
||||
'phone' => $rider->phone,
|
||||
'photo' => $rider->photo_url,
|
||||
'rating' => $rider->rating,
|
||||
'vehicle_type' => $rider->vehicle_type,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FCM data for push notification.
|
||||
*/
|
||||
public function toFcm(): array
|
||||
{
|
||||
$rider = $this->delivery->rider;
|
||||
|
||||
return [
|
||||
'title' => 'Rider Assigned',
|
||||
'body' => "{$rider->full_name} is picking up your order",
|
||||
'data' => [
|
||||
'type' => 'rider_assigned',
|
||||
'delivery_id' => (string) $this->delivery->id,
|
||||
'tracking_code' => $this->delivery->tracking_code,
|
||||
'rider_id' => (string) $rider->id,
|
||||
'rider_name' => $rider->full_name,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tracking URL.
|
||||
*/
|
||||
protected function getTrackingUrl(): string
|
||||
{
|
||||
return url("/track/{$this->delivery->tracking_code}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?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.',
|
||||
],
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Modules\RestaurantDelivery\Models\DeliveryTip;
|
||||
|
||||
class TipReceivedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly DeliveryTip $tip
|
||||
) {
|
||||
$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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'tip_received',
|
||||
'tip_id' => $this->tip->id,
|
||||
'delivery_id' => $this->tip->delivery_id,
|
||||
'amount' => $this->tip->amount,
|
||||
'rider_amount' => $this->tip->rider_amount,
|
||||
'currency' => $this->tip->currency,
|
||||
'message' => $this->tip->message,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FCM data for push notification.
|
||||
*/
|
||||
public function toFcm(): array
|
||||
{
|
||||
$currency = config('restaurant-delivery.pricing.currency_symbol', '৳');
|
||||
|
||||
return [
|
||||
'title' => 'You Received a Tip!',
|
||||
'body' => "{$currency}{$this->tip->rider_amount} tip received".
|
||||
($this->tip->message ? " - \"{$this->tip->message}\"" : ''),
|
||||
'data' => [
|
||||
'type' => 'tip_received',
|
||||
'tip_id' => (string) $this->tip->id,
|
||||
'delivery_id' => (string) $this->tip->delivery_id,
|
||||
'amount' => (string) $this->tip->rider_amount,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user