📂 FileMgr
📍
/
home
/
u517669692
/
domains
/
siccs.in
/
public_html
/
app
/
Http
/
Controllers
/
Api
✏️ ookingApiController.php
⬅ Kembali
<?php namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; use App\Models\Booking; use App\Models\Customer; use App\Models\VehicleCategory; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; class BookingApiController extends Controller { public function store(Request $request): JsonResponse { $validated = $request->validate([ 'name' => 'required|string|max:100', 'mobile' => 'required|string|max:15|regex:/^[6-9]\d{9}$/', 'email' => 'nullable|email', 'pickup_location' => 'required|string|max:255', 'drop_location' => 'nullable|string|max:255', 'pickup_date' => 'required|date|after_or_equal:today', 'pickup_time' => 'required', 'trip_type' => 'required|in:one_way,round_trip,local,airport_pickup,airport_drop', 'vehicle_category_id'=> 'nullable|exists:vehicle_categories,id', ]); $customer = Customer::firstOrCreate( ['mobile' => $validated['mobile']], ['name' => $validated['name'], 'email' => $validated['email'] ?? null] ); $booking = Booking::create(array_merge($validated, [ 'customer_id' => $customer->id, 'source' => 'api', 'ip_address' => $request->ip(), ])); return response()->json([ 'success' => true, 'message' => 'Booking created successfully.', 'booking_id' => $booking->booking_id, 'data' => [ 'booking_id' => $booking->booking_id, 'status' => $booking->status, 'pickup_location' => $booking->pickup_location, 'pickup_date' => $booking->pickup_date->format('d M Y'), 'pickup_time' => $booking->pickup_time, ], ], 201); } public function show(string $bookingId): JsonResponse { $booking = Booking::where('booking_id', $bookingId) ->with(['vehicleCategory']) ->first(); if (!$booking) { return response()->json(['success' => false, 'message' => 'Booking not found.'], 404); } return response()->json([ 'success' => true, 'data' => [ 'booking_id' => $booking->booking_id, 'status' => $booking->status, 'name' => $booking->name, 'mobile' => $booking->mobile, 'pickup_location' => $booking->pickup_location, 'drop_location' => $booking->drop_location, 'pickup_date' => $booking->pickup_date->format('d M Y'), 'pickup_time' => $booking->pickup_time, 'trip_type' => $booking->trip_type_label, 'vehicle' => $booking->vehicleCategory?->name, 'driver_name' => $booking->driver_name, 'driver_mobile' => $booking->driver_mobile, 'vehicle_number' => $booking->vehicle_number, 'total_amount' => $booking->total_amount, ], ]); } public function verifyOtp(Request $request): JsonResponse { $request->validate([ 'booking_id' => 'required|string', 'otp' => 'required|string|size:6', ]); $booking = Booking::where('booking_id', $request->booking_id)->first(); if (!$booking) { return response()->json(['success' => false, 'message' => 'Booking not found.'], 404); } $customer = $booking->customer; if ($customer && $customer->verifyOtp($request->otp)) { $customer->update(['is_verified' => true, 'otp' => null]); return response()->json(['success' => true, 'message' => 'OTP verified successfully.']); } return response()->json(['success' => false, 'message' => 'Invalid or expired OTP.'], 422); } public function calculateFare(Request $request): JsonResponse { $request->validate([ 'vehicle_category_id' => 'required|exists:vehicle_categories,id', 'distance_km' => 'required|numeric|min:1', 'trip_type' => 'required|string', ]); $category = VehicleCategory::find($request->vehicle_category_id); $distance = $request->distance_km; $tripType = $request->trip_type; $baseFare = $category->base_price + ($category->price_per_km * $distance); if (in_array($tripType, ['round_trip'])) { $baseFare = $baseFare * 1.8; // 80% discount on return } // Night surcharge (11 PM - 5 AM) $hour = (int) date('H'); $nightSurcharge = ($hour >= 23 || $hour < 5) ? $baseFare * 0.15 : 0; $totalFare = $baseFare + $nightSurcharge; return response()->json([ 'success' => true, 'data' => [ 'vehicle' => $category->name, 'distance_km' => $distance, 'base_fare' => round($baseFare), 'night_surcharge'=> round($nightSurcharge), 'total_fare' => round($totalFare), 'currency' => 'INR', 'note' => 'Toll, parking extra. Final fare at trip completion.', ], ]); } }
💾 Simpan
Batal
⬅ Controllers
3 item
Nama
Tipe
Ukuran
Diubah
Aksi
🐘
BookingApiController.php
php
5.5 KB
2026-08-13 07:11
✏️
👁️
🔤
🗑
🐘
ContactApiController.php
php
922 B
2026-08-13 07:11
✏️
👁️
🔤
🗑
🐘
FleetApiController.php
php
2.5 KB
2026-08-13 07:11
✏️
👁️
🔤
🗑
✏️ Rename
Nama Baru
Simpan
Batal