145 lines
5.8 KiB
PHP
145 lines
5.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\RestaurantDelivery\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class DeliveryResource extends JsonResource
|
|
{
|
|
public function toArray($request): array
|
|
{
|
|
return [
|
|
'id' => $this->uuid,
|
|
'tracking_code' => $this->tracking_code,
|
|
|
|
// Status
|
|
'status' => $this->status,
|
|
'status_label' => $this->status->label(),
|
|
'status_description' => $this->status->description(),
|
|
'status_color' => $this->status->color(),
|
|
'is_active' => $this->status->isActive(),
|
|
'is_trackable' => $this->status->isTrackable(),
|
|
|
|
// Restaurant/Pickup
|
|
'pickup' => [
|
|
'restaurant_name' => $this->restaurant_name,
|
|
'address' => $this->pickup_address,
|
|
'latitude' => (float) $this->pickup_latitude,
|
|
'longitude' => (float) $this->pickup_longitude,
|
|
'contact_name' => $this->pickup_contact_name,
|
|
'contact_phone' => $this->pickup_contact_phone,
|
|
'instructions' => $this->pickup_instructions,
|
|
],
|
|
|
|
// Customer/Drop
|
|
'drop' => [
|
|
'customer_name' => $this->customer_name,
|
|
'address' => $this->drop_address,
|
|
'latitude' => (float) $this->drop_latitude,
|
|
'longitude' => (float) $this->drop_longitude,
|
|
'contact_name' => $this->drop_contact_name,
|
|
'contact_phone' => $this->drop_contact_phone,
|
|
'instructions' => $this->drop_instructions,
|
|
'floor' => $this->drop_floor,
|
|
'apartment' => $this->drop_apartment,
|
|
],
|
|
|
|
// Distance and Time
|
|
'distance' => [
|
|
'value' => (float) $this->distance,
|
|
'unit' => $this->distance_unit,
|
|
],
|
|
'estimated_duration' => $this->estimated_duration,
|
|
'estimated_pickup_time' => $this->estimated_pickup_time?->toIso8601String(),
|
|
'estimated_delivery_time' => $this->estimated_delivery_time?->toIso8601String(),
|
|
|
|
// Pricing
|
|
'pricing' => [
|
|
'base_fare' => (float) $this->base_fare,
|
|
'distance_charge' => (float) $this->distance_charge,
|
|
'surge_charge' => (float) $this->surge_charge,
|
|
'surge_multiplier' => (float) $this->surge_multiplier,
|
|
'peak_hour_charge' => (float) $this->peak_hour_charge,
|
|
'late_night_charge' => (float) $this->late_night_charge,
|
|
'small_order_fee' => (float) $this->small_order_fee,
|
|
'total' => (float) $this->total_delivery_charge,
|
|
'breakdown' => $this->charge_breakdown,
|
|
'currency' => config('restaurant-delivery.pricing.currency'),
|
|
'currency_symbol' => config('restaurant-delivery.pricing.currency_symbol'),
|
|
],
|
|
|
|
// Tip
|
|
'tip' => [
|
|
'amount' => (float) $this->tip_amount,
|
|
'type' => $this->tip_type,
|
|
'paid_at' => $this->tip_paid_at?->toIso8601String(),
|
|
],
|
|
|
|
// Rider
|
|
'rider' => $this->when($this->rider, fn () => [
|
|
'id' => $this->rider->uuid,
|
|
'name' => $this->rider->full_name,
|
|
'phone' => $this->rider->phone,
|
|
'photo' => $this->rider->photo_url,
|
|
'rating' => (float) $this->rider->rating,
|
|
'rating_count' => $this->rider->rating_count,
|
|
'vehicle_type' => $this->rider->vehicle_type,
|
|
'vehicle_number' => $this->rider->vehicle_number,
|
|
]),
|
|
|
|
// Zone
|
|
'zone' => $this->when($this->zone, fn () => [
|
|
'id' => $this->zone->uuid,
|
|
'name' => $this->zone->name,
|
|
]),
|
|
|
|
// Rating
|
|
'rating' => $this->when($this->rating, fn () => [
|
|
'overall' => $this->rating->overall_rating,
|
|
'star_display' => $this->rating->star_display,
|
|
'review' => $this->rating->review,
|
|
'created_at' => $this->rating->created_at->toIso8601String(),
|
|
]),
|
|
'can_rate' => $this->canBeRated(),
|
|
'can_tip' => $this->canReceiveTip(),
|
|
|
|
// Timestamps
|
|
'timestamps' => [
|
|
'created_at' => $this->created_at->toIso8601String(),
|
|
'food_ready_at' => $this->food_ready_at?->toIso8601String(),
|
|
'rider_assigned_at' => $this->rider_assigned_at?->toIso8601String(),
|
|
'picked_up_at' => $this->picked_up_at?->toIso8601String(),
|
|
'delivered_at' => $this->delivered_at?->toIso8601String() ?? null,
|
|
'cancelled_at' => $this->cancelled_at?->toIso8601String(),
|
|
],
|
|
|
|
// Cancellation
|
|
'cancellation' => $this->when($this->status->isCancelled(), fn () => [
|
|
'reason' => $this->cancellation_reason,
|
|
'cancelled_by' => $this->cancelled_by,
|
|
'notes' => $this->cancellation_notes,
|
|
]),
|
|
|
|
// Failure
|
|
'failure' => $this->when($this->status->isFailed(), fn () => [
|
|
'reason' => $this->failure_reason,
|
|
'notes' => $this->failure_notes,
|
|
]),
|
|
|
|
// Proof of delivery
|
|
'proof' => $this->when($this->status->isCompleted(), fn () => [
|
|
'photo' => $this->delivery_photo,
|
|
'signature' => $this->signature,
|
|
'recipient_name' => $this->recipient_name,
|
|
]),
|
|
|
|
// Priority
|
|
'is_priority' => $this->is_priority,
|
|
'is_scheduled' => $this->is_scheduled,
|
|
'scheduled_for' => $this->scheduled_for?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|