Editing: /home/goacom/public_html/scratch_extract/bonus.php
<?php /* * 1. START SESSION & CHECK LOGIN */ session_start(); // If not logged in, redirect if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit(); } // Database Config $host = 'localhost'; $db = 'tishanw1_melbets'; $user = 'tishanw1_melbets'; $pass = 'tishanw1_melbets'; $user_id = $_SESSION['user_id']; // Connect $conn = new mysqli($host, $user, $pass, $db); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // --- HANDLE BONUS CLAIM --- $message = ""; $msg_type = ""; // success or error if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'claim') { $bonus_amount = $_POST['bonus_amount']; $bonus_desc = $_POST['bonus_desc']; // Double check if already claimed to prevent double submission $check = $conn->prepare("SELECT id FROM user_rewards WHERE user_id = ? AND description = ?"); $check->bind_param("is", $user_id, $bonus_desc); $check->execute(); if ($check->get_result()->num_rows > 0) { $message = "You have already claimed this bonus."; $msg_type = "error"; } else { // 1. Add to User Balance $update = $conn->prepare("UPDATE users SET balance = balance + ? WHERE id = ?"); $update->bind_param("di", $bonus_amount, $user_id); $update->execute(); // 2. Log Reward $insert = $conn->prepare("INSERT INTO user_rewards (user_id, type, amount, description) VALUES (?, 'bonus', ?, ?)"); $insert->bind_param("ids", $user_id, $bonus_amount, $bonus_desc); $insert->execute(); // 3. Log Transaction (Optional but good practice) $insert_trx = $conn->prepare("INSERT INTO transactions (user_id, type, amount, status) VALUES (?, 'bonus', ?, 'completed')"); $insert_trx->bind_param("id", $user_id, $bonus_amount); $insert_trx->execute(); $message = "Bonus claimed successfully! Added to wallet."; $msg_type = "success"; } } // --- FETCH USER DATA & STATS --- // 1. User Info $stmt_user = $conn->prepare("SELECT phone, balance FROM users WHERE id = ?"); $stmt_user->bind_param("i", $user_id); $stmt_user->execute(); $user_result = $stmt_user->get_result(); $user_data = $user_result->fetch_assoc(); $phone = $user_data['phone']; $balance = number_format($user_data['balance'], 2); // 2. Calculate Total Deposits (Approved only) $stmt_dep = $conn->prepare("SELECT COALESCE(SUM(amount), 0) as total_deposit FROM deposit_withdrawal_history WHERE user_id = ? AND type = 'deposit' AND status = 'approved'"); $stmt_dep->bind_param("i", $user_id); $stmt_dep->execute(); $dep_result = $stmt_dep->get_result(); $dep_data = $dep_result->fetch_assoc(); $total_deposit = $dep_data['total_deposit']; // 3. Determine Level & Bonus $vip_level = 0; $bonus_amount = 0; $bonus_desc = ""; $bonus_text = ""; if ($total_deposit >= 50000) { $vip_level = 2; $bonus_amount = 3999; $bonus_desc = "VIP Level 2 Bonus"; $bonus_text = "3999 BDT"; } elseif ($total_deposit >= 10000) { $vip_level = 1; $bonus_amount = 1999; $bonus_desc = "VIP Level 1 Bonus"; $bonus_text = "1999 BDT"; } // 4. Check if Bonus Already Claimed $claimed = false; if ($vip_level > 0) { $check_claim = $conn->prepare("SELECT id FROM user_rewards WHERE user_id = ? AND description = ?"); $check_claim->bind_param("is", $user_id, $bonus_desc); $check_claim->execute(); if ($check_claim->get_result()->num_rows > 0) { $claimed = true; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="MELBETE - Official Gaming & Betting Platform." /> <title>MELBETE - Bonus</title> <link rel="stylesheet" href="index.css" /> <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800;900&display=swap" rel="stylesheet" /> <!-- Swiper CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" /> </head> <body> <div id="root"> <div class="w-full bg-bodyColor"> <div class="max-w-[1000px] mx-auto"> <div class="w-full bg-[#f5f5f9] min-h-screen"> <!-- Header --> <div class="bg-black w-full"> <div class="flex justify-between items-center h-12" style="background: rgb(240, 104, 39);"> <a href="reward-center.php" class="text-white cursor-pointer text-[26px] w-16 flex items-center justify-center"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M217.9 256L345 129c9.4-9.4 9.4-24.6 0-33.9-9.4-9.4-24.6-9.3-34 0L167 239c-9.1 9.1-9.3 23.7-.7 33.1L310.9 417c4.7 4.7 10.9 7 17 7s12.3-2.3 17-7c9.4-9.4 9.4-24.6 0-33.9L217.9 256z"></path></svg> </a> <div class="w-full text-white text-[19px] text-center"> Bonus </div> </div> </div> <!-- Profile Header Area --> <div class="w-full h-[158px]" style="background-image: url("/assets/mall-bg-DpNY8vgf.jpg"); background-size: cover; background-repeat: no-repeat;"> <div class="pt-7 pl-6 flex items-center w-full"> <img alt="profile" class="w-14 h-14 rounded-full border-2 border-white" src="./assets/img/user.png"> <div class="ml-3"> <h3 class="font-medium text-white"> <?php echo $phone; ?> </h3> <p class="text-base font-bold text-white"> ৳ <?php echo $balance; ?> </p> </div> </div> </div> <!-- Alert Message --> <?php if($message): ?> <div class="p-4 mx-4 mt-4 rounded text-center text-white font-bold <?php echo $msg_type == 'success' ? 'bg-green-600' : 'bg-red-600'; ?>"> <?php echo $message; ?> </div> <?php endif; ?> <!-- BONUS CONTENT LOGIC --> <div class="p-4"> <?php if($vip_level == 0): ?> <!-- Level 0: No Bonus --> <div class="bg-white p-6 rounded-xl shadow-md text-center"> <div class="w-20 h-20 bg-gray-200 rounded-full flex items-center justify-center mx-auto mb-4"> <span class="text-3xl">🔒</span> </div> <h2 class="text-xl font-bold text-gray-700 mb-2">Unlock Bonus</h2> <p class="text-sm text-gray-500 mb-4"> Deposit 10,000 BDT to unlock Level 1 Bonus (1999 BDT).<br> Deposit 50,000 BDT to unlock Level 2 Bonus (3999 BDT). </p> <a href="deposit.php" class="inline-block bg-orange-500 text-white px-6 py-2 rounded-lg font-bold hover:bg-orange-600"> Deposit Now </a> </div> <?php elseif(!$claimed): ?> <!-- Level Reached & Not Claimed: Show Claim Box --> <div class="bg-gradient-to-r from-yellow-400 to-orange-500 p-1 rounded-xl shadow-lg"> <div class="bg-white p-6 rounded-lg text-center"> <div class="w-20 h-20 bg-orange-100 rounded-full flex items-center justify-center mx-auto mb-4"> <span class="text-3xl">🎁</span> </div> <h2 class="text-xl font-bold text-gray-800 mb-2"> Congratulations! </h2> <p class="text-sm text-gray-600 mb-2"> You have reached VIP Level <?php echo $vip_level; ?>. </p> <div class="bg-gray-100 rounded-lg p-4 mb-6"> <p class="text-xs text-gray-500 uppercase tracking-wide">Bonus Amount</p> <p class="text-3xl font-bold text-orange-600"> <?php echo $bonus_text; ?> </p> </div> <form method="POST"> <input type="hidden" name="action" value="claim"> <input type="hidden" name="bonus_amount" value="<?php echo $bonus_amount; ?>"> <input type="hidden" name="bonus_desc" value="<?php echo $bonus_desc; ?>"> <button type="submit" class="w-full bg-orange-500 text-white py-3 rounded-lg font-bold text-lg shadow hover:bg-orange-600 transition-colors"> Claim Bonus </button> </form> </div> </div> <?php else: ?> <!-- Already Claimed --> <div class="bg-white p-6 rounded-xl shadow-md text-center border-2 border-gray-200"> <div class="w-20 h-20 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4"> <span class="text-3xl">✅</span> </div> <h2 class="text-xl font-bold text-gray-700 mb-2">Bonus Claimed</h2> <p class="text-sm text-gray-500 mb-4"> You have successfully claimed your VIP Level <?php echo $vip_level; ?> bonus of <?php echo $bonus_text; ?>. </p> <a href="reward-center.php" class="inline-block text-orange-500 font-bold"> Back to Reward Center </a> </div> <?php endif; ?> </div> </div> </div> </div> </div> <section class="Toastify" aria-live="polite" aria-atomic="false" aria-relevant="additions text" aria-label="Notifications Alt+T"></section> </body> </html> <?php $conn->close(); ?>
💾 Save