Update: 2026-08-08 14:09:20

This commit is contained in:
Hamza-Ayed
2026-08-08 14:09:20 +03:00
parent c8e8e481a6
commit 8395436f23
14 changed files with 295 additions and 104 deletions
@@ -1,5 +1,6 @@
<?php
require_once __DIR__ . '/../../connect.php';
require_once __DIR__ . '/referral_code_helper.php';
// Use JWT token variables provided by connect.php
if (!$user_id || $role != 'passenger') {
@@ -8,12 +9,10 @@ if (!$user_id || $role != 'passenger') {
$country_code = $_POST['country_code'] ?? 'Jordan';
// 1. Get the passenger's referral code
$stmtCode = $con->prepare("SELECT referral_code FROM user_referral_codes WHERE user_id = ? AND user_type = 'passenger'");
$stmtCode->execute([$user_id]);
// 1. Get the passenger's referral code — ونُنشئه إن غاب (نفس علّة السائق).
$referralCode = ensureReferralCode($con, (string) $user_id, 'passenger');
if ($stmtCode->rowCount() == 0) {
// If no code exists, return empty stats
if ($referralCode === null) {
printSuccess([
"referral_code" => null,
"total_invited_drivers" => 0,
@@ -23,8 +22,6 @@ if ($stmtCode->rowCount() == 0) {
exit;
}
$referralCode = $stmtCode->fetchColumn();
// 2. Fetch all referrals made by this code
$stmtRefs = $con->prepare("
SELECT id, invited_user_id, invited_user_type, status, trip_count, is_reward_claimed, created_at