function distribute_referral_bonus($new_user_id, $referrer_id, $amount) { global $mysqli; $levels = [0.20, 0.05, 0.02]; // 20%, 5%, 2% $current = $referrer_id; for ($i = 0; $i < 3; $i++) { if (!$current) break; $comm = $amount * $levels[$i]; $mysqli->query("INSERT INTO ref_commissions (user_id, from_user_id, amount, level) VALUES ($current, $new_user_id, $comm, ".($i+1).")"); $mysqli->query("UPDATE users SET balance = balance + $comm WHERE id=$current"); $next = $mysqli->query("SELECT ref_id FROM users WHERE id=$current")->fetch_assoc(); $current = $next ? $next['ref_id'] : null; } }
By using this platform you agree to our terms. Must be 18+.