Alllplmpliedl manual JWT check and restored all driver fields68j2
This commit is contained in:
127
app/Http/Controllers/OverlayController.php
Normal file
127
app/Http/Controllers/OverlayController.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* OverlayController — إدارة بيانات الرحلة المقبولة من الخلفية
|
||||
*
|
||||
* الغرض:
|
||||
* عندما يقبل السائق رحلة وهو في الخلفية (Background)، يتم تخزين بيانات الرحلة
|
||||
* في جدول write_argument_after_applied_from_background حتى يتمكن التطبيق من
|
||||
* استرجاعها عند العودة للواجهة (Foreground).
|
||||
*
|
||||
* يعادل: intaleq_v1/ride/overLay/getArgumentAfterAppliedFromBackground.php
|
||||
* intaleq_v1/ride/overLay/add.php
|
||||
*/
|
||||
class OverlayController extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /v2/overlay/background-args
|
||||
* جلب بيانات الرحلة المقبولة من الخلفية (آخر دقيقتين فقط)
|
||||
*/
|
||||
public function getBackgroundArgs(Request $request): JsonResponse
|
||||
{
|
||||
$driverId = $request->attributes->get('_jwt_user_id');
|
||||
|
||||
if (empty($driverId)) {
|
||||
return response()->json(['status' => 'failure', 'message' => 'Missing driver ID']);
|
||||
}
|
||||
|
||||
$row = DB::connection('primary')
|
||||
->table('write_argument_after_applied_from_background')
|
||||
->where('driver_id', $driverId)
|
||||
->whereRaw('TIMESTAMPDIFF(MINUTE, time_of_order, NOW()) <= 2')
|
||||
->orderBy('time_of_order', 'desc')
|
||||
->first();
|
||||
|
||||
if ($row) {
|
||||
return response()->json(['status' => 'success', 'message' => (array) $row]);
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'failure', 'message' => 'No data found']);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /v2/overlay/background-args
|
||||
* تخزين بيانات الرحلة المقبولة من الخلفية
|
||||
*/
|
||||
public function storeBackgroundArgs(Request $request): JsonResponse
|
||||
{
|
||||
$driverId = $request->attributes->get('_jwt_user_id');
|
||||
|
||||
$rideId = $request->input('rideId');
|
||||
$passengerLocation = $request->input('passengerLocation');
|
||||
$passengerDestination = $request->input('passengerDestination');
|
||||
|
||||
if (empty($rideId) || empty($driverId) || empty($passengerLocation) || empty($passengerDestination)) {
|
||||
return response()->json([
|
||||
'status' => 'failure',
|
||||
'message' => 'Missing required fields (rideId, driver_id, or locations)'
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::connection('primary')
|
||||
->table('write_argument_after_applied_from_background')
|
||||
->insert([
|
||||
'ride_id' => $rideId,
|
||||
'driver_id' => $driverId,
|
||||
'passenger_id' => $request->input('passengerId'),
|
||||
'passenger_location' => $passengerLocation,
|
||||
'passenger_destination' => $passengerDestination,
|
||||
'duration' => (int) $request->input('Duration', 0),
|
||||
'duration_to_passenger' => (int) $request->input('DurationToPassenger', 0),
|
||||
'duration_of_ride' => (int) $request->input('durationOfRideValue', 0),
|
||||
'distance' => (float) $request->input('Distance', 0),
|
||||
'total_cost' => (float) $request->input('totalCost', 0),
|
||||
'payment_amount' => (float) $request->input('paymentAmount', 0),
|
||||
'payment_method' => $request->input('paymentMethod'),
|
||||
'wallet_checked' => $request->input('WalletChecked') === 'true' ? 1 : 0,
|
||||
'has_steps' => !empty($request->input('isHaveSteps')) ? 1 : 0,
|
||||
'step0' => $request->input('step0'),
|
||||
'step1' => $request->input('step1'),
|
||||
'step2' => $request->input('step2'),
|
||||
'step3' => $request->input('step3'),
|
||||
'step4' => $request->input('step4'),
|
||||
'passenger_wallet_burc' => (float) $request->input('passengerWalletBurc', 0),
|
||||
'token_passenger' => $request->input('tokenPassenger'),
|
||||
'name' => $request->input('name'),
|
||||
'phone' => $request->input('phone'),
|
||||
'email' => $request->input('email'),
|
||||
'start_name_location' => $request->input('startNameLocation'),
|
||||
'end_name_location' => $request->input('endNameLocation'),
|
||||
'car_type' => $request->input('carType'),
|
||||
'kazan' => (float) $request->input('kazan', 0),
|
||||
'direction_url' => $request->input('direction'),
|
||||
'time_of_order' => $request->input('timeOfOrder', now()),
|
||||
'total_passenger' => (int) $request->input('totalPassenger', 0),
|
||||
]);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => 'Background args saved']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('OverlayController Error: ' . $e->getMessage());
|
||||
return response()->json(['status' => 'failure', 'message' => 'Database error']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /v2/overlay/background-args
|
||||
* حذف بيانات الرحلة المقبولة بعد استلامها
|
||||
*/
|
||||
public function deleteBackgroundArgs(Request $request): JsonResponse
|
||||
{
|
||||
$driverId = $request->attributes->get('_jwt_user_id');
|
||||
|
||||
DB::connection('primary')
|
||||
->table('write_argument_after_applied_from_background')
|
||||
->where('driver_id', $driverId)
|
||||
->delete();
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => 'Background args deleted']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user