نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق». نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا `cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules · .dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore. هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ. ⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../connect.php';
|
|
|
|
$driver_id = filterRequest("driver_id");
|
|
if (empty($driver_id)) {
|
|
jsonError("Missing driver_id");
|
|
exit;
|
|
}
|
|
|
|
global $redis;
|
|
$redisKey = "driver_streak:{$driver_id}";
|
|
|
|
// 1. Try to read from Redis first (Cache-Aside pattern)
|
|
if (isset($redis)) {
|
|
try {
|
|
$cached = $redis->get($redisKey);
|
|
if ($cached) {
|
|
$data = json_decode($cached, true);
|
|
if ($data) {
|
|
// Return immediately if found in cache!
|
|
jsonSuccess($data);
|
|
exit;
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
error_log("Redis read error in get_streak: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// 2. Fallback to Database if not found in Redis
|
|
$stmt = $con->prepare("SELECT current_streak, zero_commission_until FROM driver_streaks WHERE driver_id = ?");
|
|
$stmt->execute([$driver_id]);
|
|
$streak = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($streak) {
|
|
$now = new DateTime();
|
|
$until = new DateTime($streak['zero_commission_until']);
|
|
|
|
$isActive = false;
|
|
if ($streak['zero_commission_until'] !== '2000-01-01 00:00:00' && $now < $until) {
|
|
$isActive = true;
|
|
}
|
|
|
|
$responseData = [
|
|
'streak_count' => intval($streak['current_streak']),
|
|
'is_zero_commission_active' => $isActive,
|
|
'zero_commission_until' => $streak['zero_commission_until']
|
|
];
|
|
} else {
|
|
// Default if no record yet
|
|
$responseData = [
|
|
'streak_count' => 0,
|
|
'is_zero_commission_active' => false,
|
|
'zero_commission_until' => '2000-01-01 00:00:00'
|
|
];
|
|
}
|
|
|
|
// 3. Save the DB result into Redis for future reads
|
|
if (isset($redis)) {
|
|
try {
|
|
// Cache it for 2 hours (7200 seconds)
|
|
$redis->setex($redisKey, 7200, json_encode($responseData));
|
|
} catch (Exception $e) {
|
|
error_log("Redis write error in get_streak: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
jsonSuccess($responseData);
|
|
?>
|