Update: 2026-07-10 03:04:06
This commit is contained in:
@@ -226,6 +226,17 @@ try {
|
||||
|
||||
error_log("[add_ride] ride DB insert success. RideID=$insertedId");
|
||||
|
||||
// 🆕 Seed initial ride state in Redis — fired as early as possible so
|
||||
// getRideStatus polling has a cache entry from the first poll onward.
|
||||
// Uses $status/$driver_id/$passenger_id, the exact values just written
|
||||
// to MySQL above, not hardcoded literals.
|
||||
sendToLocationServer('update_ride_state', [
|
||||
'ride_id' => $insertedId,
|
||||
'status' => $status,
|
||||
'driver_id' => $driver_id,
|
||||
'passenger_id' => $passenger_id,
|
||||
]);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// STEP B — primary DB ثانياً (نسخة أرشيفية بنفس الـ ID)
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
@@ -212,10 +212,12 @@ try {
|
||||
|
||||
$con->commit();
|
||||
|
||||
// 🆕 Cache ride state in Redis
|
||||
// 🆕 Cache ride state in Redis — use $statusText (the exact value just
|
||||
// written to MySQL above), not a hardcoded label, so a cache hit can
|
||||
// never disagree with the row it was seeded from.
|
||||
sendToLocationServer('update_ride_state', [
|
||||
'ride_id' => $rideId,
|
||||
'status' => 'cancelled_by_driver',
|
||||
'status' => $statusText,
|
||||
'driver_id' => $driverId,
|
||||
'passenger_id' => $passenger_id ?? '',
|
||||
]);
|
||||
|
||||
@@ -313,6 +313,17 @@ try {
|
||||
// ✅ Payment succeeded — COMMIT
|
||||
$con->commit();
|
||||
|
||||
// 🆕 Cache ride state in Redis — placed immediately after commit(), before
|
||||
// the best-effort remote-DB sync / streak / notification code below, so a
|
||||
// later exception in any of those non-critical steps can never suppress
|
||||
// this write for a ride that's genuinely finished in MySQL.
|
||||
sendToLocationServer('update_ride_state', [
|
||||
'ride_id' => $rideId,
|
||||
'status' => $newStatus,
|
||||
'driver_id' => $driver_id,
|
||||
'passenger_id' => $passengerId,
|
||||
]);
|
||||
|
||||
// 🔥 [Fix Split-Brain] تحديث القاعدة البعيدة الآن فقط، بعد أن أصبح الدفع
|
||||
// والتحديث المحلي مؤكدَين نجاحهما — يبقي الحالتين متطابقتين دائماً.
|
||||
// فشل هذا التحديث best-effort فقط (لا يُرجع الرحلة المحلية المُنجَزة فعلاً).
|
||||
|
||||
@@ -134,6 +134,17 @@ try {
|
||||
':id' => $rideId,
|
||||
]);
|
||||
|
||||
// 🆕 Refresh Redis cache — this UPDATE just reset status back to 'waiting'
|
||||
// and driver_id to 0. Without this, a passenger polling during a retry
|
||||
// round would keep seeing a stale prior state (e.g. 'arrived') cached
|
||||
// from before the reset.
|
||||
sendToLocationServer('update_ride_state', [
|
||||
'ride_id' => $rideId,
|
||||
'status' => 'waiting',
|
||||
'driver_id' => '0',
|
||||
'passenger_id' => $passengerId,
|
||||
]);
|
||||
|
||||
// 3. حساب العمولة (Kazan) المُحدَّثة بعد الـ bonus
|
||||
$kazan = (float)$price - (float)$priceForDriver;
|
||||
if ($kazan < 0) $kazan = 0; // Floor protection
|
||||
|
||||
@@ -142,10 +142,12 @@ try {
|
||||
|
||||
$con->commit();
|
||||
|
||||
// 🆕 Cache ride state in Redis
|
||||
// 🆕 Cache ride state in Redis — use $status (the exact value just
|
||||
// written to MySQL above), not a hardcoded label, so a cache hit can
|
||||
// never disagree with the row it was seeded from.
|
||||
sendToLocationServer('update_ride_state', [
|
||||
'ride_id' => $ride_id,
|
||||
'status' => 'started',
|
||||
'status' => $status,
|
||||
'driver_id' => $driver_id,
|
||||
'passenger_id' => $passenger_id ?? '',
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user