Update: 2026-05-15 03:09:36

This commit is contained in:
Hamza-Ayed
2026-05-15 03:09:36 +03:00
parent 9fc1319946
commit dd4fcb9bee
93 changed files with 766 additions and 55 deletions

View File

@@ -55,6 +55,51 @@ $latitude = $input['latitude'] ?? null;
$longitude = $input['longitude'] ?? null;
try {
// --- Subscription Quota Check ---
if ($isAccepted === 1) {
$today = date('Y-m-d');
// Get active subscription
$stmt = $pdo->prepare("SELECT plan, expires_at FROM subscriptions WHERE fingerprint = :fingerprint AND is_active = 1 ORDER BY id DESC LIMIT 1");
$stmt->execute([':fingerprint' => $fingerprint]);
$sub = $stmt->fetch(PDO::FETCH_ASSOC);
$plan = 'free';
if ($sub) {
$plan = $sub['plan'];
if ($sub['expires_at'] && strtotime($sub['expires_at']) < time()) {
$plan = 'free'; // Expired
}
}
// Get daily usage
$stmt = $pdo->prepare("SELECT rides_accepted FROM daily_usage WHERE fingerprint = :fingerprint AND usage_date = :today");
$stmt->execute([':fingerprint' => $fingerprint, ':today' => $today]);
$usage = $stmt->fetch(PDO::FETCH_ASSOC);
$ridesToday = $usage ? (int)$usage['rides_accepted'] : 0;
// Determine limit
$limit = 1; // free
if ($plan === 'basic') $limit = 10;
if ($plan === 'pro' || $plan === 'annual') $limit = -1;
if ($limit !== -1 && $ridesToday >= $limit) {
http_response_code(403);
echo json_encode([
'success' => false,
'message' => 'Daily limit reached',
'plan' => $plan,
'upgrade_required' => true
]);
exit;
}
// Update daily usage
$stmt = $pdo->prepare("INSERT INTO daily_usage (fingerprint, usage_date, rides_accepted) VALUES (:fingerprint, :today, 1) ON DUPLICATE KEY UPDATE rides_accepted = rides_accepted + 1");
$stmt->execute([':fingerprint' => $fingerprint, ':today' => $today]);
}
// --------------------------------
$sql = "INSERT INTO rides (fingerprint, platform, price, pickup_distance, dropoff_distance, time_to_pickup, pickup_address, dropoff_address, is_accepted, raw_text, latitude, longitude, created_at)
VALUES (:fingerprint, :platform, :price, :pickup_distance, :dropoff_distance, :time_to_pickup, :pickup_address, :dropoff_address, :is_accepted, :raw_text, :latitude, :longitude, NOW())";