1) { $nav_buttons[] = ['text' => '◀️ قبلی', 'callback_data' => "history_{$type}_page-" . ($page - 1)]; } if ($page < $total_pages) { $nav_buttons[] = ['text' => '▶️ بعدی', 'callback_data' => "history_{$type}_page-" . ($page + 1)]; } if (!empty($nav_buttons)) { $keyboard[] = $nav_buttons; } if ($total_pages > 1) { $keyboard[] = [['text' => "📄 صفحه $page از $total_pages", 'callback_data' => '0']]; } return json_encode(['inline_keyboard' => $keyboard]); } if ($text == '📊 تاریخچه تراکنش‌ها' || $text == '📜 تراکنش های اخیر') { $response_text = "📊 *تاریخچه تراکنش‌ها*\n\n"; $response_text .= "لطفاً یکی از گزینه‌های زیر را انتخاب کنید:"; $bot->sendMessage($from_id, $response_text, json_encode([ 'resize_keyboard' => true, 'keyboard' => [ [['text' => '💸 تاریخچه برداشت‌ها'], ['text' => '💰 تاریخچه واریزها']], [['text' => '🔙 بازگشت به منوی اصلی']] ] ])); die; } if (strpos($data, 'history_deposits_page-') !== false) { if (isset($query_id)) { $bot->answerCallbackQuery($query_id, '⏳ در حال بارگذاری...', false); } $page = (int) explode('-', $data)[1]; $per_page = 2; $offset = ($page - 1) * $per_page; $query = "SELECT COUNT(*) FROM `transactions` WHERE `chat_id` = ? AND `status` = 1"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->editMessage($from_id, "📭 *تاریخچه واریزها خالی است*\n\nهیچ واریزی توسط شما انجام نشده است.", $message_id); die; } $total_pages = ceil($total / $per_page); if ($page > $total_pages) $page = $total_pages; if ($page < 1) $page = 1; $query = "SELECT * FROM `transactions` WHERE `chat_id` = ? AND `status` = 1 ORDER BY `updated_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); $response_text = "💰 *تاریخچه واریزها*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $transaction) { $amount_formatted = $transaction->amount; $card_number = !empty($transaction->card) ? $transaction->card : 'نامشخص'; $date_formatted = jdate("H:i:s - Y/m/d", strtotime($transaction->updated_at), tr_num: 'en'); $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "💳 کارت: `$card_number`\n"; $response_text .= "🔑 کد پیگیری: `{$transaction->support_code}`\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total واریز | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('deposits', $page, $total_pages); $bot->editMessage($from_id, $response_text, $message_id, $keyboard); die; } if ($text == '💰 تاریخچه واریزها' || $text == '💰 واریزها') { $per_page = 2; // دریافت کل تعداد $query = "SELECT COUNT(*) FROM `transactions` WHERE `chat_id` = ? AND `status` = 1"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->sendMessage($from_id, "📭 *تاریخچه واریزها خالی است*\n\nهیچ واریزی توسط شما انجام نشده است."); die; } $total_pages = ceil($total / $per_page); $page = 1; $offset = 0; $query = "SELECT * FROM `transactions` WHERE `chat_id` = ? AND `status` = 1 ORDER BY `updated_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); $response_text = "💰 *تاریخچه واریزها*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $transaction) { $amount_formatted = $transaction->amount; $card_number = !empty($transaction->card) ? $transaction->card : 'نامشخص'; $date_formatted = jdate("H:i:s - Y/m/d", strtotime($transaction->updated_at), tr_num: 'en'); $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "💳 کارت: `$card_number`\n"; $response_text .= "🔑 کد پیگیری: `{$transaction->support_code}`\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total واریز | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('deposits', $page, $total_pages); $bot->sendMessage($from_id, $response_text, $keyboard); die; } if (strpos($data, 'history_withdrawals_page-') !== false) { if (isset($query_id)) { $bot->answerCallbackQuery($query_id, '⏳ در حال بارگذاری...', false); } $page = (int) explode('-', $data)[1]; $per_page = 2; $offset = ($page - 1) * $per_page; // دریافت کل تعداد try { $query = "SELECT COUNT(*) FROM `withdraw` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->editMessage($from_id, "📭 *تاریخچه برداشت‌ها خالی است*\n\nهیچ برداشتی توسط شما انجام نشده است.", $message_id); die; } $total_pages = ceil($total / $per_page); if ($page > $total_pages) $page = $total_pages; if ($page < 1) $page = 1; $query = "SELECT * FROM `withdraw` WHERE `chat_id` = ? ORDER BY `created_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); if (empty($result)) { $bot->editMessage($from_id, "📭 *تاریخچه برداشت‌ها خالی است*\n\nهیچ برداشتی توسط شما انجام نشده است.", $message_id); die; } } catch (Exception $e) { $bot->editMessage($from_id, "❌ *خطا در دریافت اطلاعات*\n\nمتأسفانه خطایی در دریافت تاریخچه برداشت‌ها رخ داد. لطفاً دوباره تلاش کنید.", $message_id); die; } $response_text = "💸 *تاریخچه برداشت‌ها*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $withdrawal) { try { $amount_formatted = isset($withdrawal->amount) ? number_format($withdrawal->amount) : '0'; $card_formatted = !empty($withdrawal->card) ? $withdrawal->card : 'نامشخص'; $date_to_use = !empty($withdrawal->updated_at) ? $withdrawal->updated_at : (isset($withdrawal->created_at) ? $withdrawal->created_at : null); $timestamp = $date_to_use ? strtotime($date_to_use) : false; $date_formatted = $timestamp ? jdate("H:i:s - Y/m/d", $timestamp, tr_num: 'en') : 'نامشخص'; $status_text = ($withdrawal->status == 'confirm' ? '✅ واریز شده' : ($withdrawal->status == 'pending' ? '⏳ در صف واریز' : '❌ رد شده')); $support_code = isset($withdrawal->support_code) ? $withdrawal->support_code : 'نامشخص'; $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "💳 کارت: `$card_formatted`\n"; $response_text .= "🔑 کد پیگیری: `$support_code`\n"; $response_text .= "📊 وضعیت: $status_text\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } catch (Exception $e) { continue; } } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total برداشت | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('withdrawals', $page, $total_pages); $bot->editMessage($from_id, $response_text, $message_id, $keyboard); die; } if ($text == '💸 تاریخچه برداشت‌ها') { $per_page = 2; // دریافت کل تعداد try { $query = "SELECT COUNT(*) FROM `withdraw` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->sendMessage($from_id, "📭 *تاریخچه برداشت‌ها خالی است*\n\nهیچ برداشتی توسط شما انجام نشده است."); die; } $total_pages = ceil($total / $per_page); $page = 1; $offset = 0; $query = "SELECT * FROM `withdraw` WHERE `chat_id` = ? ORDER BY `created_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); if (empty($result)) { $bot->sendMessage($from_id, "📭 *تاریخچه برداشت‌ها خالی است*\n\nهیچ برداشتی توسط شما انجام نشده است."); die; } } catch (Exception $e) { $bot->sendMessage($from_id, "❌ *خطا در دریافت اطلاعات*\n\nمتأسفانه خطایی در دریافت تاریخچه برداشت‌ها رخ داد. لطفاً دوباره تلاش کنید."); die; } $response_text = "💸 *تاریخچه برداشت‌ها*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $withdrawal) { try { $amount_formatted = isset($withdrawal->amount) ? number_format($withdrawal->amount) : '0'; $card_formatted = !empty($withdrawal->card) ? $withdrawal->card : 'نامشخص'; $date_to_use = !empty($withdrawal->updated_at) ? $withdrawal->updated_at : (isset($withdrawal->created_at) ? $withdrawal->created_at : null); $timestamp = $date_to_use ? strtotime($date_to_use) : false; $date_formatted = $timestamp ? jdate("H:i:s - Y/m/d", $timestamp, tr_num: 'en') : 'نامشخص'; $status_text = ($withdrawal->status == 'confirm' ? '✅ واریز شده' : ($withdrawal->status == 'pending' ? '⏳ در صف واریز' : '❌ رد شده')); $support_code = isset($withdrawal->support_code) ? $withdrawal->support_code : 'نامشخص'; $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "💳 کارت: `$card_formatted`\n"; $response_text .= "🔑 کد پیگیری: `$support_code`\n"; $response_text .= "📊 وضعیت: $status_text\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } catch (Exception $e) { continue; } } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total برداشت | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('withdrawals', $page, $total_pages); $bot->sendMessage($from_id, $response_text, $keyboard); die; } if ($text == '📋 تاریخچه سفارشات') { $response_text = "📋 *تاریخچه سفارشات*\n\n"; $response_text .= "لطفاً یکی از گزینه‌های زیر را انتخاب کنید:"; $bot->sendMessage($from_id, $response_text, json_encode([ 'resize_keyboard' => true, 'keyboard' => [ [['text' => '🎫 ووچرهای خریداری شده'], ['text' => '💵 ووچرهای فروخته شده']], [['text' => '🔙 بازگشت به منوی اصلی']] ] ])); die; } if (strpos($data, 'history_purchased_vouchers_page-') !== false) { if (isset($query_id)) { $bot->answerCallbackQuery($query_id, '⏳ در حال بارگذاری...', false); } $page = (int) explode('-', $data)[1]; $per_page = 2; $offset = ($page - 1) * $per_page; // دریافت کل تعداد $query = "SELECT COUNT(*) FROM `sold_vouchers` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->editMessage($from_id, "📭 *تاریخچه خرید خالی است*\n\nهیچ ووچری خریداری نشده است.", $message_id); die; } $total_pages = ceil($total / $per_page); if ($page > $total_pages) $page = $total_pages; if ($page < 1) $page = 1; $query = "SELECT * FROM `sold_vouchers` WHERE `chat_id` = ? ORDER BY `created_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); $response_text = "🎫 *ووچرهای خریداری شده*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $voucher) { $amount_formatted = number_format($voucher->amount); $date_formatted = jdate("H:i:s - Y/m/d", strtotime($voucher->created_at), tr_num: 'en'); $status_text = ($voucher->status == 'Confirm' ? '✅ تایید شده' : '⏳ در انتظار'); $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "🔑 کد ووچر: `{$voucher->code}`\n"; $response_text .= "🛒 نوع: {$voucher->type}\n"; $response_text .= "🔖 کد رهگیری: `{$voucher->support_code}`\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "📊 وضعیت: $status_text\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total خرید | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('purchased_vouchers', $page, $total_pages); $bot->editMessage($from_id, $response_text, $message_id, $keyboard); die; } if ($text == '🎫 ووچرهای خریداری شده') { $per_page = 2; // دریافت کل تعداد $query = "SELECT COUNT(*) FROM `sold_vouchers` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->sendMessage($from_id, "📭 *تاریخچه خرید خالی است*\n\nهیچ ووچری خریداری نشده است."); die; } $total_pages = ceil($total / $per_page); $page = 1; $offset = 0; $query = "SELECT * FROM `sold_vouchers` WHERE `chat_id` = ? ORDER BY `created_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); $response_text = "🎫 *ووچرهای خریداری شده*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $voucher) { $amount_formatted = number_format($voucher->amount); $date_formatted = jdate("H:i:s - Y/m/d", strtotime($voucher->created_at), tr_num: 'en'); $status_text = ($voucher->status == 'Confirm' ? '✅ تایید شده' : '⏳ در انتظار'); $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "🔑 کد ووچر: `{$voucher->code}`\n"; $response_text .= "🛒 نوع: {$voucher->type}\n"; $response_text .= "🔖 کد رهگیری: `{$voucher->support_code}`\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "📊 وضعیت: $status_text\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total خرید | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('purchased_vouchers', $page, $total_pages); $bot->sendMessage($from_id, $response_text, $keyboard); die; } if (strpos($data, 'history_sold_vouchers_page-') !== false) { if (isset($query_id)) { $bot->answerCallbackQuery($query_id, '⏳ در حال بارگذاری...', false); } $page = (int) explode('-', $data)[1]; $per_page = 2; $offset = ($page - 1) * $per_page; // دریافت کل تعداد $query = "SELECT COUNT(*) FROM `purchased_vouchers` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->editMessage($from_id, "📭 *تاریخچه فروش خالی است*\n\nهیچ ووچری به ربات فروخته نشده است.", $message_id); die; } $total_pages = ceil($total / $per_page); if ($page > $total_pages) $page = $total_pages; if ($page < 1) $page = 1; $query = "SELECT * FROM `purchased_vouchers` WHERE `chat_id` = ? ORDER BY `created_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); $response_text = "💵 *ووچرهای فروخته شده*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $voucher) { $amount_formatted = $voucher->amount ? number_format($voucher->amount) : 'نامشخص'; $date_formatted = jdate("H:i:s - Y/m/d", strtotime($voucher->created_at), tr_num: 'en'); $status_text = ($voucher->status == 'confirm' ? '✅ تایید شده' : ($voucher->status == 'pending' ? '⏳ در انتظار تایید' : '❌ رد شده')); $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "🔑 کد ووچر: `{$voucher->code}`\n"; $response_text .= "🛒 نوع: {$voucher->type}\n"; $response_text .= "🔖 کد رهگیری: `{$voucher->support_code}`\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "📊 وضعیت: $status_text\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total فروش | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('sold_vouchers', $page, $total_pages); $bot->editMessage($from_id, $response_text, $message_id, $keyboard); die; } if ($text == '💵 ووچرهای فروخته شده' || $text == '💳 ووچرهای فروخته شده') { $per_page = 2; // دریافت کل تعداد $query = "SELECT COUNT(*) FROM `purchased_vouchers` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $total = $stmt->fetchColumn(); if ($total == 0) { $bot->sendMessage($from_id, "📭 *تاریخچه فروش خالی است*\n\nهیچ ووچری به ربات فروخته نشده است."); die; } $total_pages = ceil($total / $per_page); $page = 1; $offset = 0; $query = "SELECT * FROM `purchased_vouchers` WHERE `chat_id` = ? ORDER BY `created_at` DESC LIMIT ? OFFSET ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $per_page, $offset]); $result = $stmt->fetchAll(); $response_text = "💵 *ووچرهای فروخته شده*\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; foreach ($result as $voucher) { $amount_formatted = $voucher->amount ? number_format($voucher->amount) : 'نامشخص'; $date_formatted = jdate("H:i:s - Y/m/d", strtotime($voucher->created_at), tr_num: 'en'); $status_text = ($voucher->status == 'confirm' ? '✅ تایید شده' : ($voucher->status == 'pending' ? '⏳ در انتظار تایید' : '❌ رد شده')); $response_text .= "💰 مبلغ: `$amount_formatted` تومان\n"; $response_text .= "🔑 کد ووچر: `{$voucher->code}`\n"; $response_text .= "🛒 نوع: {$voucher->type}\n"; $response_text .= "🔖 کد رهگیری: `{$voucher->support_code}`\n"; $response_text .= "📅 تاریخ: $date_formatted\n"; $response_text .= "📊 وضعیت: $status_text\n\n"; $response_text .= "━━━━━━━━━━━━━━━━━━━━\n\n"; } $response_text .= "📊 *جمع‌بندی:*\n"; $response_text .= "نمایش $per_page از $total فروش | صفحه $page از $total_pages"; $keyboard = buildPaginationKeyboard('sold_vouchers', $page, $total_pages); $bot->sendMessage($from_id, $response_text, $keyboard); die; }