🔄 در حال انجام: تست دستی Filament ⏸️ بلاک: مهاجرت ۳۹۵۰ رکورد (منتظر فایل اکسل اصلاحشده) ⏸️ بلاک: پلاگین وردپرس (بعد از تست کامل API)
59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Models\Shipment;
|
|
use App\Services\TrackingService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class TrackController
|
|
{
|
|
public function __construct(protected TrackingService $tracking) {}
|
|
|
|
public function show(string $awb_no): JsonResponse
|
|
{
|
|
$shipment = Shipment::where('awb_no', $awb_no)->firstOrFail();
|
|
|
|
$events = $shipment->trackingEvents()
|
|
->orderByDesc('event_date')
|
|
->orderByDesc('event_time')
|
|
->get();
|
|
|
|
$mappings = $shipment->carrierMappings;
|
|
|
|
return response()->json([
|
|
'awb_no' => $shipment->awb_no,
|
|
'direction' => $shipment->direction->value,
|
|
'type' => $shipment->type->value,
|
|
'status' => $shipment->status->value,
|
|
'sender' => [
|
|
'name' => $shipment->sender_name,
|
|
'company' => $shipment->sender_company,
|
|
'phone' => $shipment->sender_phone,
|
|
'city' => $shipment->sender_city,
|
|
],
|
|
'receiver' => [
|
|
'name' => $shipment->receiver_name,
|
|
'company' => $shipment->receiver_company,
|
|
'phone' => $shipment->receiver_phone,
|
|
'city' => $shipment->receiver_city,
|
|
],
|
|
'carrier_mappings' => $mappings->map(fn ($m) => [
|
|
'carrier_code' => $m->carrier_code->value,
|
|
'tracking_number' => $m->carrier_tracking_number,
|
|
'booking_number' => $m->booking_number,
|
|
'delivery_status' => $m->delivery_status?->value,
|
|
'notes' => $m->notes,
|
|
]),
|
|
'timeline' => $events->map(fn ($e) => [
|
|
'date' => $e->event_date->format('Y-m-d'),
|
|
'time' => $e->event_time->format('H:i'),
|
|
'location' => $e->location,
|
|
'description' => $e->event_description,
|
|
'delivery_status' => $e->delivery_status?->value,
|
|
'source' => $e->source->value,
|
|
]),
|
|
]);
|
|
}
|
|
}
|