logged_in == 1 && isAdmin($user->login_username)) { setStep($from_id, "list_users:page:1"); $page = 1; $limit = 10; $offset = 0; $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `accounts` WHERE `is_admin` = 0"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT `username`, `full_name`, `base_investment`, `current_profit` FROM `accounts` WHERE `is_admin` = 0 ORDER BY `id` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $users = $stmt->fetchAll(); if (empty($users)) { sendMessage($from_id, "❌ *هیچ کاربری یافت نشد*\n\nدر حال حاضر هیچ کاربری در سیستم ثبت نشده است.", $adminMainKeyboard); setStep($from_id, "home"); die; } $responseText = "📋 *لیست کاربران*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "👥 تعداد کل: *{$totalCount}* کاربر\n\n"; $inlineKeyboard = []; foreach ($users as $index => $u) { $fullName = ($u->full_name && $u->full_name != "") ? $u->full_name : $u->username; $baseInvestment = number_format($u->base_investment); $currentProfit = number_format($u->current_profit); $responseText .= "*#" . ($index + 1) . "*\n"; $responseText .= "👤 *{$fullName}*\n"; $responseText .= "📱 `{$u->username}`\n"; $responseText .= "💰 *{$baseInvestment}* تومان | 📈 *{$currentProfit}* تومان\n\n"; $inlineKeyboard[] = [ [ "text" => "👤 {$fullName}", "callback_data" => "admin_view_user:{$u->username}" ] ]; } // دکمه‌های pagination $paginationButtons = []; if ($totalPages > 1) { if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_users:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } } $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); sendMessage($from_id, $responseText, $keyboard); die; } // مشاهده درخواست‌های برداشت در انتظار با pagination if ($text == "⏳ درخواست‌های در انتظار" && $user->logged_in == 1 && isAdmin($user->login_username)) { setStep($from_id, "list_pending:page:1"); $page = 1; $limit = 10; $offset = 0; $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `withdraw_requests` WHERE `status` = 'pending'"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT * FROM `withdraw_requests` WHERE `status` = 'pending' ORDER BY `id` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $requests = $stmt->fetchAll(); if (empty($requests)) { sendMessage($from_id, "✅ *هیچ درخواستی در انتظار نیست*\n\nدر حال حاضر هیچ درخواست برداشتی در صف انتظار وجود ندارد.", $adminMainKeyboard); setStep($from_id, "home"); die; } $responseText = "⏳ *درخواست‌های در انتظار*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "📋 تعداد کل: *{$totalCount}* درخواست\n\n"; $inlineKeyboard = []; foreach ($requests as $index => $req) { $amountFormatted = number_format($req->amount); $timestamp = strtotime($req->created_at ?? date('Y-m-d H:i:s')); $shamsiTime = jdate('H:i', $timestamp); $shamsiDateOnly = jdate('Y/m/d', $timestamp); $shamsiDate = "{$shamsiTime} - {$shamsiDateOnly}"; $responseText .= "*#" . ($index + 1) . "*\n"; $responseText .= "🔹 `{$req->tracking_code}`\n"; $responseText .= "👤 *{$req->username}*\n"; $responseText .= "💰 *{$amountFormatted}* تومان\n"; $responseText .= "📅 *{$shamsiDate}*\n\n"; $inlineKeyboard[] = [ [ "text" => "🔍 {$req->tracking_code}", "callback_data" => "admin_view_request:{$req->id}" ] ]; } // دکمه‌های pagination $paginationButtons = []; if ($totalPages > 1) { if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_pending:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } } $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); sendMessage($from_id, $responseText, $keyboard); die; } // مشاهده کاربران با بیشترین سود با pagination if ($text == "🏆 برترین کاربران" && $user->logged_in == 1 && isAdmin($user->login_username)) { setStep($from_id, "list_top:page:1"); $page = 1; $limit = 10; $offset = 0; $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `accounts` WHERE `is_admin` = 0"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT `username`, `full_name`, `current_profit`, `base_investment` FROM `accounts` WHERE `is_admin` = 0 ORDER BY `current_profit` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $users = $stmt->fetchAll(); if (empty($users)) { sendMessage($from_id, "❌ *هیچ کاربری یافت نشد*", $adminMainKeyboard); setStep($from_id, "home"); die; } $responseText = "🏆 *برترین کاربران*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "👥 تعداد کل: *{$totalCount}* کاربر\n\n"; $inlineKeyboard = []; foreach ($users as $index => $u) { $fullName = ($u->full_name && $u->full_name != "") ? $u->full_name : $u->username; $currentProfit = number_format($u->current_profit); $baseInvestment = number_format($u->base_investment); $total = number_format($u->current_profit + $u->base_investment); $medal = ""; if ($index == 0) $medal = "🥇"; elseif ($index == 1) $medal = "🥈"; elseif ($index == 2) $medal = "🥉"; else $medal = "🔹"; $responseText .= "{$medal} *رتبه " . ($index + 1) . "*\n"; $responseText .= "👤 *{$fullName}*\n"; $responseText .= "📱 `{$u->username}`\n"; $responseText .= "📈 *{$currentProfit}* تومان\n"; $responseText .= "💰 *{$baseInvestment}* تومان\n"; $responseText .= "💼 *{$total}* تومان\n\n"; $inlineKeyboard[] = [ [ "text" => "👤 {$fullName}", "callback_data" => "admin_view_user:{$u->username}" ] ]; } // دکمه‌های pagination $paginationButtons = []; if ($totalPages > 1) { if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_top:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } } $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); sendMessage($from_id, $responseText, $keyboard); die; } // مشاهده آخرین تراکنش‌های سود با pagination if ($text == "📊 آخرین تراکنش‌ها" && $user->logged_in == 1 && isAdmin($user->login_username)) { setStep($from_id, "list_transactions:page:1"); $page = 1; $limit = 10; $offset = 0; $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `profit_transactions`"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT * FROM `profit_transactions` ORDER BY `id` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $transactions = $stmt->fetchAll(); if (empty($transactions)) { sendMessage($from_id, "❌ *هیچ تراکنشی یافت نشد*", $adminMainKeyboard); setStep($from_id, "home"); die; } $responseText = "📊 *آخرین تراکنش‌ها*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "📋 تعداد کل: *{$totalCount}* تراکنش\n\n"; $inlineKeyboard = []; foreach ($transactions as $index => $t) { $amount = (int)$t->amount; $amountFormatted = number_format(abs($amount)); $type = $amount > 0 ? "افزودن" : "کاهش"; $emoji = $amount > 0 ? "➕" : "➖"; $timestamp = strtotime($t->created_at); $shamsiTime = jdate('H:i', $timestamp); $shamsiDateOnly = jdate('Y/m/d', $timestamp); $shamsiDate = "{$shamsiTime} - {$shamsiDateOnly}"; $responseText .= "*#" . ($index + 1) . "*\n"; $responseText .= "{$emoji} *{$type}*\n"; $responseText .= "👤 `{$t->username}`\n"; $responseText .= "💰 *{$amountFormatted}* تومان\n"; $responseText .= "📌 `{$t->tracking_code}`\n"; $responseText .= "📅 *{$shamsiDate}*\n\n"; $inlineKeyboard[] = [ [ "text" => "🔍 {$t->tracking_code}", "callback_data" => "admin_view_transaction:{$t->tracking_code}" ] ]; } // دکمه‌های pagination $paginationButtons = []; if ($totalPages > 1) { if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_transactions:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } } $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); sendMessage($from_id, $responseText, $keyboard); die; } // مدیریت pagination callbacks if (isset($callback_query) && isset($data)) { // لیست کاربران if (strpos($data, "admin_list_users:page:") === 0) { $page = (int)str_replace("admin_list_users:page:", "", $data); $limit = 10; $offset = ($page - 1) * $limit; $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `accounts` WHERE `is_admin` = 0"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT `username`, `full_name`, `base_investment`, `current_profit` FROM `accounts` WHERE `is_admin` = 0 ORDER BY `id` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $users = $stmt->fetchAll(); if (empty($users)) { answerCallback($callback_query->id, "❌ هیچ کاربری یافت نشد", true); die; } $responseText = "📋 *لیست کاربران*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "👥 تعداد کل: *{$totalCount}* کاربر\n\n"; $inlineKeyboard = []; foreach ($users as $index => $u) { $fullName = ($u->full_name && $u->full_name != "") ? $u->full_name : $u->username; $baseInvestment = number_format($u->base_investment); $currentProfit = number_format($u->current_profit); $responseText .= "*#" . ($offset + $index + 1) . "*\n"; $responseText .= "👤 *{$fullName}*\n"; $responseText .= "📱 `{$u->username}`\n"; $responseText .= "💰 *{$baseInvestment}* تومان | 📈 *{$currentProfit}* تومان\n\n"; $inlineKeyboard[] = [ [ "text" => "👤 {$fullName}", "callback_data" => "admin_view_user:{$u->username}" ] ]; } $paginationButtons = []; if ($page > 1) { $paginationButtons[] = [ "text" => "◀️ قبلی", "callback_data" => "admin_list_users:page:" . ($page - 1) ]; } if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_users:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } $inlineKeyboard[] = [ [ "text" => "🔙 بازگشت", "callback_data" => "admin_back_to_main" ] ]; $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); editMessage($chat_id, $message_id, $responseText, $keyboard); answerCallback($callback_query->id, "📋 صفحه {$page}", false); setStep($from_id, "list_users:page:{$page}"); die; } // لیست درخواست‌های در انتظار if (strpos($data, "admin_list_pending:page:") === 0) { $page = (int)str_replace("admin_list_pending:page:", "", $data); $limit = 10; $offset = ($page - 1) * $limit; $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `withdraw_requests` WHERE `status` = 'pending'"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT * FROM `withdraw_requests` WHERE `status` = 'pending' ORDER BY `id` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $requests = $stmt->fetchAll(); if (empty($requests)) { answerCallback($callback_query->id, "✅ هیچ درخواستی در انتظار نیست", true); die; } $responseText = "⏳ *درخواست‌های در انتظار*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "📋 تعداد کل: *{$totalCount}* درخواست\n\n"; $inlineKeyboard = []; foreach ($requests as $index => $req) { $amountFormatted = number_format($req->amount); $timestamp = strtotime($req->created_at ?? date('Y-m-d H:i:s')); $shamsiTime = jdate('H:i', $timestamp); $shamsiDateOnly = jdate('Y/m/d', $timestamp); $shamsiDate = "{$shamsiTime} - {$shamsiDateOnly}"; $responseText .= "*#" . ($offset + $index + 1) . "*\n"; $responseText .= "🔹 `{$req->tracking_code}`\n"; $responseText .= "👤 *{$req->username}*\n"; $responseText .= "💰 *{$amountFormatted}* تومان\n"; $responseText .= "📅 *{$shamsiDate}*\n\n"; $inlineKeyboard[] = [ [ "text" => "🔍 {$req->tracking_code}", "callback_data" => "admin_view_request:{$req->id}" ] ]; } $paginationButtons = []; if ($page > 1) { $paginationButtons[] = [ "text" => "◀️ قبلی", "callback_data" => "admin_list_pending:page:" . ($page - 1) ]; } if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_pending:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } $inlineKeyboard[] = [ [ "text" => "🔙 بازگشت", "callback_data" => "admin_back_to_main" ] ]; $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); editMessage($chat_id, $message_id, $responseText, $keyboard); answerCallback($callback_query->id, "⏳ صفحه {$page}", false); setStep($from_id, "list_pending:page:{$page}"); die; } // لیست برترین کاربران if (strpos($data, "admin_list_top:page:") === 0) { $page = (int)str_replace("admin_list_top:page:", "", $data); $limit = 10; $offset = ($page - 1) * $limit; $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `accounts` WHERE `is_admin` = 0"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT `username`, `full_name`, `current_profit`, `base_investment` FROM `accounts` WHERE `is_admin` = 0 ORDER BY `current_profit` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $users = $stmt->fetchAll(); if (empty($users)) { answerCallback($callback_query->id, "❌ هیچ کاربری یافت نشد", true); die; } $responseText = "🏆 *برترین کاربران*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "👥 تعداد کل: *{$totalCount}* کاربر\n\n"; $inlineKeyboard = []; foreach ($users as $index => $u) { $fullName = ($u->full_name && $u->full_name != "") ? $u->full_name : $u->username; $currentProfit = number_format($u->current_profit); $baseInvestment = number_format($u->base_investment); $total = number_format($u->current_profit + $u->base_investment); $medal = ""; if ($offset + $index == 0) $medal = "🥇"; elseif ($offset + $index == 1) $medal = "🥈"; elseif ($offset + $index == 2) $medal = "🥉"; else $medal = "🔹"; $responseText .= "{$medal} *رتبه " . ($offset + $index + 1) . "*\n"; $responseText .= "👤 *{$fullName}*\n"; $responseText .= "📱 `{$u->username}`\n"; $responseText .= "📈 *{$currentProfit}* تومان\n"; $responseText .= "💰 *{$baseInvestment}* تومان\n"; $responseText .= "💼 *{$total}* تومان\n\n"; $inlineKeyboard[] = [ [ "text" => "👤 {$fullName}", "callback_data" => "admin_view_user:{$u->username}" ] ]; } $paginationButtons = []; if ($page > 1) { $paginationButtons[] = [ "text" => "◀️ قبلی", "callback_data" => "admin_list_top:page:" . ($page - 1) ]; } if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_top:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } $inlineKeyboard[] = [ [ "text" => "🔙 بازگشت", "callback_data" => "admin_back_to_main" ] ]; $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); editMessage($chat_id, $message_id, $responseText, $keyboard); answerCallback($callback_query->id, "🏆 صفحه {$page}", false); setStep($from_id, "list_top:page:{$page}"); die; } // لیست آخرین تراکنش‌ها if (strpos($data, "admin_list_transactions:page:") === 0) { $page = (int)str_replace("admin_list_transactions:page:", "", $data); $limit = 10; $offset = ($page - 1) * $limit; $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } $stmt = $pdo->prepare("SELECT COUNT(*) as total FROM `profit_transactions`"); $stmt->execute(); $totalCount = $stmt->fetch()->total; $totalPages = ceil($totalCount / $limit); $stmt = $pdo->prepare("SELECT * FROM `profit_transactions` ORDER BY `id` DESC LIMIT {$limit} OFFSET {$offset}"); $stmt->execute(); $transactions = $stmt->fetchAll(); if (empty($transactions)) { answerCallback($callback_query->id, "❌ هیچ تراکنشی یافت نشد", true); die; } $responseText = "📊 *آخرین تراکنش‌ها*\n\n"; $responseText .= "📄 صفحه *{$page}* از *{$totalPages}*\n"; $responseText .= "📋 تعداد کل: *{$totalCount}* تراکنش\n\n"; $inlineKeyboard = []; foreach ($transactions as $index => $t) { $amount = (int)$t->amount; $amountFormatted = number_format(abs($amount)); $type = $amount > 0 ? "افزودن" : "کاهش"; $emoji = $amount > 0 ? "➕" : "➖"; $timestamp = strtotime($t->created_at); $shamsiTime = jdate('H:i', $timestamp); $shamsiDateOnly = jdate('Y/m/d', $timestamp); $shamsiDate = "{$shamsiTime} - {$shamsiDateOnly}"; $responseText .= "*#" . ($offset + $index + 1) . "*\n"; $responseText .= "{$emoji} *{$type}*\n"; $responseText .= "👤 `{$t->username}`\n"; $responseText .= "💰 *{$amountFormatted}* تومان\n"; $responseText .= "📌 `{$t->tracking_code}`\n"; $responseText .= "📅 *{$shamsiDate}*\n\n"; $inlineKeyboard[] = [ [ "text" => "🔍 {$t->tracking_code}", "callback_data" => "admin_view_transaction:{$t->tracking_code}" ] ]; } $paginationButtons = []; if ($page > 1) { $paginationButtons[] = [ "text" => "◀️ قبلی", "callback_data" => "admin_list_transactions:page:" . ($page - 1) ]; } if ($page < $totalPages) { $paginationButtons[] = [ "text" => "▶️ بعدی", "callback_data" => "admin_list_transactions:page:" . ($page + 1) ]; } if (!empty($paginationButtons)) { $inlineKeyboard[] = $paginationButtons; } $inlineKeyboard[] = [ [ "text" => "🔙 بازگشت", "callback_data" => "admin_back_to_main" ] ]; $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); editMessage($chat_id, $message_id, $responseText, $keyboard); answerCallback($callback_query->id, "📊 صفحه {$page}", false); setStep($from_id, "list_transactions:page:{$page}"); die; } // بازگشت به منوی اصلی if ($data == "admin_back_to_main") { $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } setStep($from_id, "home"); answerCallback($callback_query->id, "🔙 بازگشت به منوی اصلی", false); $responseText = "🎛 *پنل مدیریت*\n\nلطفاً یکی از گزینه‌های زیر را انتخاب نمایید:"; sendMessage($from_id, $responseText, $adminMainKeyboard); die; } // مشاهده کاربر if (strpos($data, "admin_view_user:") === 0) { $username = str_replace("admin_view_user:", "", $data); $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } // استفاده از کد جستجوی کاربر موجود $stmt = $pdo->prepare("SELECT * FROM `accounts` WHERE `username` = ?"); $stmt->execute([$username]); $account = $stmt->fetch(); if (!$account) { answerCallback($callback_query->id, "❌ کاربر یافت نشد", true); die; } // شمارش تراکنش‌ها $stmtProfit = $pdo->prepare("SELECT COUNT(*) as total, SUM(`amount`) as total_amount FROM `profit_transactions` WHERE `username` = ?"); $stmtProfit->execute([$username]); $profitStats = $stmtProfit->fetch(); $stmtBase = $pdo->prepare("SELECT COUNT(*) as total, SUM(`amount`) as total_amount FROM `base_investment_transactions` WHERE `username` = ?"); $stmtBase->execute([$username]); $baseStats = $stmtBase->fetch(); $stmtWithdraw = $pdo->prepare("SELECT COUNT(*) as total, SUM(`amount`) as total_amount FROM `withdraw_requests` WHERE `username` = ?"); $stmtWithdraw->execute([$username]); $withdrawStats = $stmtWithdraw->fetch(); $stmtCards = $pdo->prepare("SELECT COUNT(*) as total FROM `cards` WHERE `username` = ?"); $stmtCards->execute([$username]); $cardsCount = $stmtCards->fetch()->total; $roleText = ($account->is_admin == 1) ? "👑 مدیر" : "👤 کاربر"; $fullName = ($account->full_name && $account->full_name != "") ? $account->full_name : "—"; $baseInvestment = number_format($account->base_investment); $currentProfit = number_format($account->current_profit); $startDate = ($account->start_date && $account->start_date != "") ? $account->start_date : "—"; $endDate = ($account->end_date && $account->end_date != "") ? $account->end_date : "—"; $description = ($account->description && $account->description != "") ? $account->description : "—"; $totalProfitAdded = number_format($profitStats->total_amount ?? 0); $totalBaseAdded = number_format($baseStats->total_amount ?? 0); $totalWithdrawAmount = number_format($withdrawStats->total_amount ?? 0); $responseText = "👤 *اطلاعات کاربر*\n\n" . "📋 *اطلاعات شخصی*\n\n" . "👤 نام: *{$fullName}*\n" . "📱 نام کاربری: `{$account->username}`\n" . "🔹 سطح: {$roleText}\n" . "📝 توضیحات: {$description}\n\n\n" . "💼 *وضعیت مالی*\n\n" . "💰 سرمایه پایه: *{$baseInvestment}* تومان\n" . "📈 سود فعلی: *{$currentProfit}* تومان\n" . "📊 جمع سودها: *{$totalProfitAdded}* تومان\n" . "📊 جمع مبالغ پایه: *{$totalBaseAdded}* تومان\n" . "💸 جمع برداشت‌ها: *{$totalWithdrawAmount}* تومان\n\n\n" . "📅 *دوره سرمایه‌گذاری*\n\n" . "🟢 شروع: *{$startDate}*\n" . "🔴 پایان: *{$endDate}*\n\n\n" . "📊 *آمار*\n\n" . "💳 کارت‌ها: *{$cardsCount}*\n" . "📈 تراکنش‌های سود: *" . ($profitStats->total ?? 0) . "*\n" . "💰 تراکنش‌های پایه: *" . ($baseStats->total ?? 0) . "*\n" . "💸 درخواست‌های برداشت: *" . ($withdrawStats->total ?? 0) . "*"; // ایجاد inline keyboard برای ویرایش $inlineKeyboard = [ [ [ "text" => "🔐 ویرایش رمز", "callback_data" => "admin_edit_password:{$account->username}" ], [ "text" => "✏️ ویرایش نام", "callback_data" => "admin_edit_name:{$account->username}" ] ], [ [ "text" => "📝 ویرایش توضیحات", "callback_data" => "admin_edit_description:{$account->username}" ], [ "text" => "📱 ویرایش نام کاربری", "callback_data" => "admin_edit_username:{$account->username}" ] ], [ [ "text" => "🗑 حذف کاربر", "callback_data" => "admin_delete_user:{$account->username}" ] ], ]; $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); editMessage($chat_id, $message_id, $responseText, $keyboard); answerCallback($callback_query->id, "👤 اطلاعات کاربر", false); die; } // مشاهده درخواست if (strpos($data, "admin_view_request:") === 0) { $requestId = (int)str_replace("admin_view_request:", "", $data); $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } $stmt = $pdo->prepare("SELECT * FROM `withdraw_requests` WHERE `id` = ?"); $stmt->execute([$requestId]); $request = $stmt->fetch(); if (!$request) { answerCallback($callback_query->id, "❌ درخواست یافت نشد", true); die; } // استفاده از کد موجود در withdraw_requests.php برای نمایش جزئیات $stmtAccount = $pdo->prepare("SELECT `full_name`, `base_investment`, `current_profit` FROM `accounts` WHERE `username` = ?"); $stmtAccount->execute([$request->username]); $accountInfo = $stmtAccount->fetch(); $stmtCard = $pdo->prepare("SELECT `full_name`, `card_number` FROM `cards` WHERE `username` = ? ORDER BY `id` DESC LIMIT 1"); $stmtCard->execute([$request->username]); $cardInfo = $stmtCard->fetch(); $fullName = $accountInfo->full_name ?? $request->username; $baseInvestment = number_format($accountInfo->base_investment ?? 0); $currentProfit = number_format($accountInfo->current_profit ?? 0); $amountFormatted = number_format($request->amount); $cardNumber = $cardInfo ? substr($cardInfo->card_number, -4) : "—"; $cardOwner = $cardInfo->full_name ?? "—"; $timestamp = strtotime($request->created_at ?? date('Y-m-d H:i:s')); $shamsiTime = jdate('H:i', $timestamp); $shamsiDateOnly = jdate('Y/m/d', $timestamp); $shamsiDate = "{$shamsiTime} - {$shamsiDateOnly}"; $responseText = "🔎 *جزئیات درخواست*\n\n" . "📋 *اطلاعات تراکنش*\n\n" . "🔹 کد: `{$request->tracking_code}`\n" . "💰 مبلغ: *{$amountFormatted}* تومان\n" . "📊 وضعیت: ⏳ در انتظار\n" . "📅 تاریخ: *{$shamsiDate}*\n\n\n" . "👤 *اطلاعات کاربر*\n\n" . "👤 نام: *{$fullName}*\n" . "📱 کاربری: `{$request->username}`\n" . "🆔 تلگرام: `{$request->telegram_id}`\n\n\n" . "💼 *وضعیت مالی کاربر*\n\n" . "💰 سرمایه: *{$baseInvestment}* تومان\n" . "📈 سود: *{$currentProfit}* تومان\n\n\n" . "💳 *اطلاعات کارت*\n\n" . "💳 کارت: `****{$cardNumber}`\n" . "👤 صاحب: *{$cardOwner}*"; $inlineKeyboard = [ [ [ "text" => "✅ تایید", "callback_data" => "admin_withdraw_approve:{$requestId}" ], [ "text" => "❌ رد", "callback_data" => "admin_withdraw_reject:{$requestId}" ] ], ]; $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); editMessage($chat_id, $message_id, $responseText, $keyboard); answerCallback($callback_query->id, "🔎 جزئیات درخواست", false); die; } // مشاهده تراکنش if (strpos($data, "admin_view_transaction:") === 0) { $trackingCode = str_replace("admin_view_transaction:", "", $data); $checkUser = $pdo->prepare("SELECT * FROM `users` WHERE `telegram_id` = ?"); $checkUser->execute([$from_id]); $adminUser = $checkUser->fetch(); if (!$adminUser || !isAdmin($adminUser->login_username ?? "")) { answerCallback($callback_query->id, "⚠️ دسترسی غیرمجاز!", true); die; } $stmt = $pdo->prepare("SELECT * FROM `profit_transactions` WHERE `tracking_code` = ?"); $stmt->execute([$trackingCode]); $transaction = $stmt->fetch(); if (!$transaction) { answerCallback($callback_query->id, "❌ تراکنش یافت نشد", true); die; } $amount = (int)$transaction->amount; $amountFormatted = number_format(abs($amount)); $type = $amount > 0 ? "افزودن" : "کاهش"; $emoji = $amount > 0 ? "➕" : "➖"; $timestamp = strtotime($transaction->created_at); $shamsiTime = jdate('H:i', $timestamp); $shamsiDateOnly = jdate('Y/m/d', $timestamp); $shamsiDate = "{$shamsiTime} - {$shamsiDateOnly}"; $responseText = "🔎 *جزئیات تراکنش*\n\n" . "🔹 کد: `{$transaction->tracking_code}`\n" . "{$emoji} نوع: *{$type}*\n" . "👤 کاربر: `{$transaction->username}`\n" . "💰 مبلغ: *{$amountFormatted}* تومان\n" . "📅 تاریخ: *{$shamsiDate}*\n\n" . "📌 این تراکنش در سیستم ثبت شده است.\n"; "📌 این تراکنش در سیستم ثبت شده است."; $inlineKeyboard = [ ]; $keyboard = json_encode(["inline_keyboard" => $inlineKeyboard]); editMessage($chat_id, $message_id, $responseText, $keyboard); answerCallback($callback_query->id, "🔎 جزئیات تراکنش", false); die; } }