Files
kulakpos_web/public/restaurant/Modules/RestaurantDelivery/app/Notifications/NewDeliveryRequestNotification.php

81 lines
2.8 KiB
PHP

<?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',
],
];
}
}