Update: 2026-08-07 01:06:09
This commit is contained in:
@@ -43,23 +43,23 @@ try {
|
||||
// الحالة تُحدَّث والراكب يُشعَر كالمعتاد — لكن لا نختم وقتاً يترتب عليه
|
||||
// مال لا نستطيع إثباته. النتيجة: لا تعويض لهذه الرحلة، وسجلّ واضح.
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// الختم في Redis لا MySQL — قيمة عابرة تُقرأ مرة واحدة عند الإلغاء،
|
||||
// وتُثبَّت في MySQL كتابةً واحدة هناك. hSetNx يجعله ذرّياً: نداء ثانٍ
|
||||
// لا يعيد ضبط عدّاد الانتظار.
|
||||
try {
|
||||
$stmtRide = $con->prepare("SELECT * FROM ride WHERE id = ? AND driver_id = ?");
|
||||
$stmtRide->execute([$rideId, $driverId]);
|
||||
$rideRow = $stmtRide->fetch(PDO::FETCH_ASSOC);
|
||||
$stateKey = "ride:$rideId:state";
|
||||
|
||||
if (is_array($rideRow)
|
||||
&& array_key_exists('driverArrivedAt', $rideRow)
|
||||
&& empty($rideRow['driverArrivedAt'])) {
|
||||
if (isset($redisLocation) && $redisLocation
|
||||
&& !$redisLocation->hExists($stateKey, 'driver_arrived_at')) {
|
||||
|
||||
$stmtPickup = $con->prepare("SELECT start_location FROM ride WHERE id = ? AND driver_id = ?");
|
||||
$stmtPickup->execute([$rideId, $driverId]);
|
||||
[$pLat, $pLng] = array_pad(
|
||||
array_map('trim', explode(',', (string) $rideRow['start_location'], 2)), 2, null
|
||||
array_map('trim', explode(',', (string) $stmtPickup->fetchColumn(), 2)), 2, null
|
||||
);
|
||||
|
||||
$canStamp = false;
|
||||
if (isset($redisLocation) && $redisLocation
|
||||
&& is_numeric($pLat) && is_numeric($pLng)) {
|
||||
|
||||
if (is_numeric($pLat) && is_numeric($pLng)) {
|
||||
$loc = $redisLocation->hGetAll("driver:public:$driverId");
|
||||
if (!empty($loc['lat']) && !empty($loc['lng'])) {
|
||||
$gap = getDistanceBetweenPoints(
|
||||
@@ -75,23 +75,20 @@ try {
|
||||
}
|
||||
|
||||
if ($canStamp) {
|
||||
// WHERE driverArrivedAt IS NULL يجعله ذرّياً: نداء ثانٍ لا
|
||||
// يعيد ضبط عدّاد الانتظار.
|
||||
$sqlStamp = "UPDATE ride SET driverArrivedAt = NOW()
|
||||
WHERE id = ? AND driver_id = ? AND driverArrivedAt IS NULL";
|
||||
$con->prepare($sqlStamp)->execute([$rideId, $driverId]);
|
||||
try {
|
||||
$con_ride->prepare($sqlStamp)->execute([$rideId, $driverId]);
|
||||
} catch (PDOException $e) { /* primary هو المرجع لهذا الحقل */ }
|
||||
$redisLocation->hSetNx($stateKey, 'driver_arrived_at', time());
|
||||
// تأمين TTL: لو وصل هذا الطلب قبل أول update_ride_state من
|
||||
// السوكِت، الهاش يكون بلا انتهاء صلاحية.
|
||||
if ($redisLocation->ttl($stateKey) < 0) {
|
||||
$redisLocation->expire($stateKey, 86400);
|
||||
}
|
||||
} else {
|
||||
error_log("[arrive_ride] تعذّر إثبات الوصول — لا تعويض لهذه"
|
||||
. " الرحلة (ride=$rideId driver=$driverId)");
|
||||
}
|
||||
}
|
||||
} catch (PDOException $eStamp) {
|
||||
// العمود غير مُرحَّل بعد — الوصول يعمل، التعويض معطّل.
|
||||
error_log("[arrive_ride] تعذّر ختم driverArrivedAt (شغّل"
|
||||
. " migrations/2026_08_07_driver_cancel_compensation.sql): " . $eStamp->getMessage());
|
||||
} catch (Throwable $eStamp) {
|
||||
// فشل الختم لا يمنع إشعار الراكب بالوصول.
|
||||
error_log("[arrive_ride] تعذّر ختم وقت الوصول: " . $eStamp->getMessage());
|
||||
}
|
||||
|
||||
// 3. جلب بيانات الراكب للإرسال
|
||||
|
||||
Reference in New Issue
Block a user