migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
<?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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Modules\RestaurantDelivery\Models\Delivery;
|
||||
|
||||
class DeliveryTrackingResource extends JsonResource
|
||||
{
|
||||
protected ?array $trackingData;
|
||||
|
||||
public function __construct(Delivery $delivery, ?array $trackingData = null)
|
||||
{
|
||||
parent::__construct($delivery);
|
||||
$this->trackingData = $trackingData;
|
||||
}
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
$delivery = $this->resource;
|
||||
|
||||
return [
|
||||
'tracking_code' => $delivery->tracking_code,
|
||||
|
||||
// Status
|
||||
'status' => [
|
||||
'code' => $delivery->status->value,
|
||||
'label' => $delivery->status->label(),
|
||||
'description' => $delivery->status->description(),
|
||||
'color' => $delivery->status->color(),
|
||||
'icon' => $delivery->status->icon(),
|
||||
],
|
||||
|
||||
// Restaurant location
|
||||
'restaurant' => [
|
||||
'name' => $delivery->restaurant_name,
|
||||
'address' => $delivery->pickup_address,
|
||||
'latitude' => (float) $delivery->pickup_latitude,
|
||||
'longitude' => (float) $delivery->pickup_longitude,
|
||||
],
|
||||
|
||||
// Customer location
|
||||
'customer' => [
|
||||
'address' => $delivery->drop_address,
|
||||
'latitude' => (float) $delivery->drop_latitude,
|
||||
'longitude' => (float) $delivery->drop_longitude,
|
||||
],
|
||||
|
||||
// Rider info
|
||||
'rider' => $delivery->rider ? [
|
||||
'id' => $delivery->rider->uuid,
|
||||
'name' => $delivery->rider->full_name,
|
||||
'phone' => $delivery->rider->phone,
|
||||
'photo' => $delivery->rider->photo_url,
|
||||
'rating' => (float) $delivery->rider->rating,
|
||||
'rating_count' => $delivery->rider->rating_count,
|
||||
'vehicle_type' => $delivery->rider->vehicle_type->value,
|
||||
'vehicle_number' => $delivery->rider->vehicle_number,
|
||||
] : null,
|
||||
|
||||
// Live tracking data
|
||||
'tracking' => $this->trackingData ? [
|
||||
'rider_location' => $this->trackingData['rider_location'] ?? null,
|
||||
'route' => $this->trackingData['route'] ?? null,
|
||||
'eta' => $this->trackingData['eta'] ?? null,
|
||||
'remaining_distance' => $this->trackingData['remaining_distance'] ?? null,
|
||||
'animation' => $this->trackingData['animation'] ?? null,
|
||||
] : null,
|
||||
|
||||
// Estimated times
|
||||
'estimated_pickup' => $delivery->estimated_pickup_time?->format('H:i'),
|
||||
'estimated_delivery' => $delivery->estimated_delivery_time?->format('H:i'),
|
||||
|
||||
// Distance
|
||||
'distance' => [
|
||||
'total' => (float) $delivery->distance,
|
||||
'unit' => $delivery->distance_unit,
|
||||
],
|
||||
|
||||
// Map config
|
||||
'map_config' => [
|
||||
'default_zoom' => config('restaurant-delivery.tracking.map.default_zoom'),
|
||||
'tracking_zoom' => config('restaurant-delivery.tracking.map.tracking_zoom'),
|
||||
'auto_center' => config('restaurant-delivery.tracking.map.auto_center'),
|
||||
'show_route' => config('restaurant-delivery.tracking.map.show_route_polyline'),
|
||||
'show_eta' => config('restaurant-delivery.tracking.map.show_eta'),
|
||||
],
|
||||
|
||||
// Markers config
|
||||
'markers' => config('restaurant-delivery.tracking.markers'),
|
||||
|
||||
// Polyline config
|
||||
'polyline' => config('restaurant-delivery.tracking.polyline'),
|
||||
|
||||
// Animation config
|
||||
'animation' => config('restaurant-delivery.tracking.animation'),
|
||||
|
||||
// Firebase config for client
|
||||
'firebase_config' => [
|
||||
'path' => "deliveries/{$delivery->id}/tracking",
|
||||
'enabled' => config('restaurant-delivery.firebase.enabled'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RiderResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->uuid,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'full_name' => $this->full_name,
|
||||
'phone' => $this->phone,
|
||||
'email' => $this->email,
|
||||
'photo' => $this->photo_url,
|
||||
|
||||
// Type and Status
|
||||
'type' => $this->type->value,
|
||||
'type_label' => $this->type->label(),
|
||||
'status' => $this->status->value,
|
||||
'status_label' => $this->status->label(),
|
||||
'is_verified' => $this->is_verified,
|
||||
'is_online' => $this->is_online,
|
||||
|
||||
'user_info' => [
|
||||
'restaurant_id' => $this->user?->restaurant_id,
|
||||
'user_id' => $this->user?->id,
|
||||
'email' => $this->user?->email,
|
||||
'phone' => $this->user?->phone,
|
||||
'user_type' => $this->user?->user_type,
|
||||
'fcm_token' => $this->user?->fcm_token,
|
||||
'address' => $this->user?->address,
|
||||
],
|
||||
|
||||
// Vehicle
|
||||
'vehicle' => [
|
||||
'type' => $this->vehicle_type->value,
|
||||
'type_label' => $this->vehicle_type->label(),
|
||||
'number' => $this->vehicle_number,
|
||||
'model' => $this->vehicle_model,
|
||||
'color' => $this->vehicle_color,
|
||||
],
|
||||
|
||||
// Location
|
||||
'location' => $this->when($this->current_latitude && $this->current_longitude, fn () => [
|
||||
'latitude' => (float) $this->current_latitude,
|
||||
'longitude' => (float) $this->current_longitude,
|
||||
'last_update' => $this->last_location_update?->toIso8601String(),
|
||||
]),
|
||||
|
||||
// Distance (only when queried with nearby scope)
|
||||
'distance' => $this->when(isset($this->distance), fn () => round($this->distance, 2)),
|
||||
|
||||
// Stats
|
||||
'stats' => [
|
||||
'rating' => (float) $this->rating,
|
||||
'rating_count' => $this->rating_count,
|
||||
'total_deliveries' => $this->total_deliveries,
|
||||
'successful_deliveries' => $this->successful_deliveries,
|
||||
'acceptance_rate' => (float) $this->acceptance_rate,
|
||||
'completion_rate' => (float) $this->completion_rate,
|
||||
],
|
||||
|
||||
// Commission
|
||||
'commission' => $this->when($request->user()?->isAdmin ?? false, fn () => [
|
||||
'type' => $this->commission_type->value,
|
||||
'rate' => (float) $this->commission_rate,
|
||||
'base' => $this->base_commission ? (float) $this->base_commission : null,
|
||||
'per_km_rate' => $this->per_km_rate ? (float) $this->per_km_rate : null,
|
||||
]),
|
||||
|
||||
// Active deliveries count
|
||||
'active_deliveries_count' => $this->whenLoaded('activeDeliveries', fn () => $this->activeDeliveries->count()),
|
||||
|
||||
// Online status
|
||||
'last_online_at' => $this->last_online_at?->toIso8601String(),
|
||||
|
||||
// Timestamps
|
||||
'created_at' => $this->created_at->toIso8601String(),
|
||||
'verified_at' => $this->verified_at?->toIso8601String(),
|
||||
'verified_by' => $this->verified_by,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user