logged_in == 1) { $stmt = $pdo->prepare("SELECT * FROM `accounts` WHERE `username` = ?"); $stmt->execute([$user->login_username]); $account = $stmt->fetch(); if (!$account) { $pdo->prepare("UPDATE `users` SET `logged_in` = 0, `login_username` = NULL WHERE `telegram_id` = ?") ->execute([$from_id]); setStep($from_id, "home"); $responseText = "⚠️ *خطا در دسترسی به حساب کاربری*\n\n" . "متأسفانه اطلاعات حساب کاربری شما در سیستم یافت نشد.\n\n" . "🔐 لطفاً برای ادامه کار، مجدداً وارد حساب کاربری خود شوید."; sendMessage($from_id, $responseText, $enterUserKeyboard); die; } $currentProfit = number_format($account->current_profit); $baseInvestment = number_format($account->base_investment); // بررسی درخواست‌های در انتظار $stmtPending = $pdo->prepare("SELECT SUM(`amount`) as total FROM `withdraw_requests` WHERE `username` = ? AND `status` = 'pending'"); $stmtPending->execute([$user->login_username]); $pendingAmount = $stmtPending->fetch()->total ?? 0; $availableProfit = $account->current_profit - $pendingAmount; $availableProfitFormatted = number_format($availableProfit); $responseText = "💵 *موجودی قابل برداشت*\n\n" . "📈 سود فعلی: *{$currentProfit}* تومان\n" . "⏳ در انتظار بررسی: *" . number_format($pendingAmount) . "* تومان\n\n" . "✅ موجودی قابل برداشت: *{$availableProfitFormatted}* تومان\n\n" . "💡 توجه: فقط از سود خود می‌توانید برداشت کنید.\n" . "💰 سرمایه پایه ({$baseInvestment} تومان) قابل برداشت نیست."; sendMessage($from_id, $responseText, $walletKeyboard); die; } // مشاهده اطلاعات کارت‌ها if ($text == "💳 اطلاعات کارت‌ها" && $user->logged_in == 1) { $stmt = $pdo->prepare("SELECT * FROM `accounts` WHERE `username` = ?"); $stmt->execute([$user->login_username]); $account = $stmt->fetch(); if (!$account) { $pdo->prepare("UPDATE `users` SET `logged_in` = 0, `login_username` = NULL WHERE `telegram_id` = ?") ->execute([$from_id]); setStep($from_id, "home"); $responseText = "⚠️ *خطا در دسترسی به حساب کاربری*\n\n" . "متأسفانه اطلاعات حساب کاربری شما در سیستم یافت نشد.\n\n" . "🔐 لطفاً برای ادامه کار، مجدداً وارد حساب کاربری خود شوید."; sendMessage($from_id, $responseText, $enterUserKeyboard); die; } $queryCards = "SELECT `full_name`, `card_number` FROM `cards` WHERE `username` = ? ORDER BY id DESC"; $stmtCards = $pdo->prepare($queryCards); $stmtCards->execute([$user->login_username]); $cards = $stmtCards->fetchAll(); if (empty($cards)) { $responseText = "💳 *اطلاعات کارت‌ها*\n\n" . "❌ هیچ کارت بانکی ثبت نشده است.\n\n" . "➕ می‌توانید از بخش *کارت‌های من* کارت جدید اضافه کنید."; sendMessage($from_id, $responseText, $cardsKeyboard); die; } $responseText = "💳 *اطلاعات کارت‌ها*\n\n"; $responseText .= "📊 تعداد کارت‌ها: *" . count($cards) . "*\n\n"; foreach ($cards as $index => $c) { $cardDisplay = substr($c->card_number, -4); $responseText .= "*#" . ($index + 1) . "*\n"; $responseText .= "👤 نام: *{$c->full_name}*\n"; $responseText .= "💳 شماره: `****{$cardDisplay}`\n\n"; } sendMessage($from_id, $responseText, $cardsKeyboard); die; } // مشاهده وضعیت حساب if ($text == "📊 وضعیت حساب" && $user->logged_in == 1) { $stmt = $pdo->prepare("SELECT * FROM `accounts` WHERE `username` = ?"); $stmt->execute([$user->login_username]); $account = $stmt->fetch(); if (!$account) { $pdo->prepare("UPDATE `users` SET `logged_in` = 0, `login_username` = NULL WHERE `telegram_id` = ?") ->execute([$from_id]); setStep($from_id, "home"); $responseText = "⚠️ *خطا در دسترسی به حساب کاربری*\n\n" . "متأسفانه اطلاعات حساب کاربری شما در سیستم یافت نشد.\n\n" . "🔐 لطفاً برای ادامه کار، مجدداً وارد حساب کاربری خود شوید."; sendMessage($from_id, $responseText, $enterUserKeyboard); die; } $baseInvestment = number_format($account->base_investment); $currentProfit = number_format($account->current_profit); $totalBalance = number_format($account->base_investment + $account->current_profit); $startDate = $account->start_date ?? "—"; $endDate = $account->end_date ?? "—"; // محاسبه درصد سود $profitPercent = $account->base_investment > 0 ? round(($account->current_profit / $account->base_investment) * 100, 2) : 0; $responseText = "📊 *وضعیت حساب*\n\n" . "💰 موجودی کل: *{$totalBalance}* تومان\n" . "💵 سرمایه پایه: *{$baseInvestment}* تومان\n" . "📈 سود فعلی: *{$currentProfit}* تومان\n" . "📊 درصد سود: *{$profitPercent}*%\n\n" . "📅 شروع: *{$startDate}*\n" . "📅 پایان: *{$endDate}*"; sendMessage($from_id, $responseText, $userMainKeyboard); die; }