value_ ?: 0; $cardStatus = getSettingsBot('cardStatus')->value_ ?: 0; if ($gatewayStatus == 0 && $cardStatus == 0) { $bot->sendMessage($from_id, "⚠️ *بخش افزایش موجودی غیرفعال*\n\nمتأسفانه در حال حاضر امکان افزایش موجودی وجود ندارد.\n\n💬 لطفاً با پشتیبانی تماس بگیرید."); } else { $keyboard = []; if ($cardStatus == 1 && $gatewayStatus == 1) { $keyboard[] = [ [['text' => '💳 پرداخت کارت به کارت'], ['text' => '🔗 پرداخت از درگاه']] ]; } else { if ($cardStatus == 1) { $keyboard[] = [['text' => '💳 پرداخت کارت به کارت']]; } if ($gatewayStatus == 1) { $keyboard[] = [['text' => '🔗 پرداخت از درگاه']]; } } $keyboard[] = [['text' => '🔙 بازگشت به منوی اصلی']]; $response_text = "💰 *افزایش موجودی حساب*\n\n"; $response_text .= "لطفاً یکی از روش‌های زیر را برای افزایش موجودی انتخاب کنید:\n\n"; $response_text .= "💡 *نکات مهم:*\n"; $response_text .= "• پرداخت از طریق درگاه: سریع و آنی\n"; $response_text .= "• پرداخت کارت به کارت: نیاز به تایید ادمین\n"; $response_text .= "• مبلغ باید مطابق محدودیت سطح شما باشد"; $bot->sendMessage($from_id, $response_text, json_encode([ 'resize_keyboard' => true, 'keyboard' => $keyboard ])); } die; } if ($text == '🔗 پرداخت از درگاه' || $text == '🔗 درگاه پرداخت') { $response_text = "🔗 *پرداخت از طریق درگاه*\n\n"; $response_text .= "💵 لطفاً مبلغ مورد نظر خود را به تومان وارد کنید:\n\n"; $response_text .= "💡 *نکات:*\n"; $response_text .= "• مبلغ باید مضربی از 100,000 تومان باشد\n"; $response_text .= "• پرداخت به صورت آنی انجام می‌شود\n"; $response_text .= "• مثال: 100000 یا 500000"; $bot->sendMessage($from_id, $response_text, $back_keyboard); setStep($from_id, 'charging-balance-gateway'); die; } if ($currentUser->step == 'charging-balance-gateway') { if (!is_numeric($text)) { $bot->sendMessage($from_id, "❌ لطفاً فقط عدد وارد کنید.\nمثال: 50000"); die; } if ($text % 100000 !== 0) { $bot->sendMessage($from_id, "⚠️ مبلغ وارد شده باید مضربی از 100,000 تومان باشد.\n\n🔸 مثال‌های صحیح:\n▪️ 100,000\n▪️ 200,000\n▪️ 500,000\n▪️ 1,000,000"); die; } $user_level = 'level_' . $currentUser->auth_level; $query = "SELECT * FROM `limits` WHERE `level` = ?"; $stmt = $db->prepare($query); $stmt->execute([$user_level]); $result = $stmt->fetch(); $min_amount = $result->min_amount ?? 0; $max_amount = $result->max_amount ?? 0; $query = "SELECT SUM(`amount`) AS `total_amount` FROM `transactions` WHERE `chat_id` = ? AND status = 1 AND DATE(`updated_at`) = CURDATE()"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $result = $stmt->fetch(); $total_amount = $result->total_amount ?? 0; $min_amount_formatted = number_format($min_amount); $max_amount_formatted = number_format($max_amount); $total_amount_formatted = number_format($total_amount); $text_formatted = number_format($text); if ($total_amount == 0 && $text < $min_amount) { $error_text = "⚠️ *مبلغ کمتر از حد مجاز*\n\n"; $error_text .= "حداقل مبلغ شارژ روزانه در سطح شما `$min_amount_formatted` تومان می‌باشد.\n\n"; $error_text .= "💡 برای افزایش سقف شارژ، لطفاً حساب کاربری خود را از بخش ارتقا سطح ارتقا دهید."; $bot->sendMessage($from_id, $error_text); die; } if ($total_amount + $text > $max_amount) { $error_text = "⚠️ *مبلغ بیشتر از حد مجاز*\n\n"; $error_text .= "حداکثر مبلغ شارژ روزانه در سطح شما `$max_amount_formatted` تومان می‌باشد.\n\n"; $error_text .= "📊 *وضعیت امروز:*\n"; $error_text .= "• شارژ شده: `$total_amount_formatted` تومان\n"; $error_text .= "• باقیمانده: `" . number_format($max_amount - $total_amount) . "` تومان\n\n"; $error_text .= "💡 برای افزایش سقف شارژ، لطفاً حساب کاربری خود را از بخش ارتقا سطح ارتقا دهید."; $bot->sendMessage($from_id, $error_text); die; } $query = "SELECT number FROM `cards` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $cards = $stmt->fetchAll(); if ($cards) { $keyboard = []; foreach ($cards as $card) { $keyboard[] = [['text' => $card->number, 'callback_data' => $card->number]]; } $response_text = "💳 *انتخاب کارت بانکی*\n\n"; $response_text .= "لطفاً شماره کارت خود را برای پرداخت انتخاب کنید:\n\n"; $response_text .= "⚠️ *توجه:* فقط از کارت‌های ثبت شده می‌توانید استفاده کنید."; $bot->sendMessage($from_id, $response_text, json_encode([ 'inline_keyboard' => $keyboard ])); setStep($from_id, 'startPay-' . $text); } else { $error_text = "⚠️ *کارت بانکی ثبت نشده*\n\n"; $error_text .= "شما هیچ شماره کارت ثبت شده‌ای ندارید.\n\n"; $error_text .= "💡 لطفاً از بخش پروفایل کاربری اقدام به ثبت شماره کارت خود کنید."; $bot->sendMessage($from_id, $error_text, $main_keyboard); setStep($from_id, 'home'); } die; } if (strpos($currentUser->step, 'startPay-') !== false && !$text) { $selected_card = $data; $selected_amount = explode('-', $currentUser->step)[1]; $bot->editMessage($from_id, '⏳ در حال ایجاد فاکتور ...', message_id: $message_id); $paymentResult = setPayment('E9BB85D1FBEDA1D4B2AF', $selected_amount, 'https://giftanoshop.ir/gateway/callback.php', $selected_card); if ($paymentResult->status == "error") { $bot->editMessage($from_id, "❌ خطا: " . $paymentResult->code, $message_id + 1); $bot->sendMessage($from_id, '🔙 به منوی اصلی برگشتید.', $main_keyboard); setStep($from_id, 'home'); die; } $transactionStatus = $paymentResult->status; $transactionId = $paymentResult->transid; do { $support_code = rand(10000, 50000); $query = "SELECT COUNT(*) FROM `transactions` WHERE `support_code` = ?"; $stmt = $db->prepare($query); $stmt->execute([$support_code]); $rowCount = $stmt->fetchColumn(); } while ($rowCount > 0); $query = "INSERT INTO `transactions` (`chat_id`, `amount`, `track_id`, `card`, `support_code`) VALUES (?,?,?,?,?)"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $selected_amount, $transactionId, $selected_card, $support_code]); $amount_formatted = number_format($selected_amount); $response_text = "✅ *فاکتور پرداخت ایجاد شد*\n\n"; $response_text .= "💰 *مبلغ پرداخت:* `$amount_formatted` تومان\n"; $response_text .= "💳 *کارت مجاز:* `$selected_card`\n"; $response_text .= "🆔 *شناسه تراکنش:* `$transactionId`\n\n"; $response_text .= "⚠️ *توجه:*\n"; $response_text .= "• فقط از کارت مشخص شده می‌توانید پرداخت کنید\n"; $response_text .= "• پس از پرداخت موفق، موجودی شما به‌صورت خودکار افزایش می‌یابد\n\n"; $response_text .= "برای پرداخت، روی دکمه زیر کلیک کنید:"; $bot->editMessage($from_id, $response_text, $message_id, json_encode([ 'inline_keyboard' => [ [['text' => '💳 پرداخت از طریق درگاه', 'url' => "https://giftanoshop.ir/gateway/payment.php?amount=$selected_amount&paymentNumber=$transactionId"]] ] ])); $bot->sendMessage($from_id, '✅ به منوی اصلی بازگشتید', $main_keyboard); setStep($from_id, 'home'); die; } if ($text == '💳 پرداخت کارت به کارت' || $text == '💳 کارت به کارت') { $response_text = "💳 *پرداخت کارت به کارت*\n\n"; $response_text .= "💵 لطفاً مبلغ مورد نظر خود را به تومان وارد کنید:\n\n"; $response_text .= "💡 *نکات:*\n"; $response_text .= "• پس از واریز، عکس رسید را ارسال کنید\n"; $response_text .= "• پس از تایید ادمین، موجودی شما افزایش می‌یابد\n"; $response_text .= "• زمان تایید معمولاً کمتر از 30 دقیقه است"; $bot->sendMessage($from_id, $response_text, $back_keyboard); setStep($from_id, 'charging-balance-card'); die; } if ($currentUser->step == 'charging-balance-card') { $user_level = 'level_' . $currentUser->auth_level; $query = "SELECT * FROM `limits` WHERE `level` = ?"; $stmt = $db->prepare($query); $stmt->execute([$user_level]); $result = $stmt->fetch(); $min_amount = $result->min_amount ?? 0; $max_amount = $result->max_amount ?? 0; $query = "SELECT SUM(`amount`) AS `total_amount` FROM `transactions` WHERE `chat_id` = ? AND status = 1 AND DATE(`updated_at`) = CURDATE()"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $result = $stmt->fetch(); $total_amount = $result->total_amount ?? 0; $min_amount_formatted = number_format($min_amount); $max_amount_formatted = number_format($max_amount); $total_amount_formatted = number_format($total_amount); $text_formatted = number_format($text); if ($total_amount == 0 && $text < $min_amount) { $bot->sendMessage($from_id, "🫵 کاربر گرامی، حداقل شارژ حساب در سطح شما‌ $min_amount_formatted تومان است.\n\n🔰 برای افزایش سقف شارژ، لطفاً حساب کاربری خود را ارتقا دهید."); die; } if ($total_amount + $text > $max_amount) { $bot->sendMessage($from_id, "🫵 کاربر گرامی، حداکثر مبلغ شارژ روزانه در سطح شما **$max_amount_formatted تومان** می‌باشد.\n\n👀 شما امروز **$total_amount_formatted تومان** حساب خود را شارژ کرده‌اید.\n\n🔰 برای افزایش سقف شارژ، لطفاً حساب کاربری خود را ارتقا دهید."); die; } $query = "SELECT number FROM `cards` WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$from_id]); $cards = $stmt->fetchAll(); if ($cards) { $keyboard = []; foreach ($cards as $card) { $keyboard[] = [['text' => $card->number, 'callback_data' => $card->number]]; } $response_text = "🔸 لطفاً شماره کارت خود را برای شارژ موجودی انتخاب کنید:"; $bot->sendMessage($from_id, $response_text, json_encode([ 'inline_keyboard' => $keyboard ])); setStep($from_id, 'charge-with-card-' . $text); } else { $bot->sendMessage($from_id, '⚠️ شما هیچ شماره کارت ثبت شده‌ای ندارید. لطفاً از بخش حساب کاربری اقدام به ثبت شماره کارت خود کنید.', $main_keyboard); setStep($from_id, 'home'); } die; } if (strpos($currentUser->step, 'charge-with-card-') !== false && !$text) { $selected_card = $data; $selected_amount = explode('-', $currentUser->step)[3]; $bot->editMessage($from_id, '⏳ در حال ایجاد فاکتور ...', message_id: $message_id); $transactionId = 'INC-' . substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 8); do { $support_code = rand(10000, 50000); $query = "SELECT COUNT(*) FROM `transactions` WHERE `support_code` = ?"; $stmt = $db->prepare($query); $stmt->execute([$support_code]); $rowCount = $stmt->fetchColumn(); } while ($rowCount > 0); $query = "INSERT INTO `transactions` (`chat_id`, `amount`, `track_id`, `card`, `support_code`) VALUES (?,?,?,?,?)"; $stmt = $db->prepare($query); $stmt->execute([$from_id, $selected_amount, $transactionId, $selected_card, $support_code]); $cardDetails = getSettingsBot('card')->value_ ?? "نامشخص\n0000000000000000"; [$accountName, $cardNumber] = explode("\n", $cardDetails); $amount_formatted = number_format($selected_amount); $response_text = "✅ *فاکتور پرداخت ایجاد شد*\n\n"; $response_text .= "💰 *مبلغ واریز:* `$amount_formatted` تومان\n"; $response_text .= "🆔 *کد رهگیری:* `$transactionId`\n\n"; $response_text .= "🏦 *اطلاعات حساب دریافت کننده:*\n"; $response_text .= "• شماره کارت: `$cardNumber`\n"; $response_text .= "• نام صاحب حساب: *$accountName*\n\n"; $response_text .= "⚠️ *توجه مهم:*\n"; $response_text .= "• فقط از کارت `$selected_card` واریز کنید\n"; $response_text .= "• مبلغ دقیقاً `$amount_formatted` تومان باشد\n"; $response_text .= "• پس از واریز، عکس رسید را ارسال کنید\n\n"; $response_text .= "📸 *مرحله بعد:*\n"; $response_text .= "لطفاً عکس رسید واریز خود را ارسال کنید:"; $bot->editMessage($from_id, $response_text, $message_id); setStep($from_id, $transactionId); die; } if (strpos($currentUser->step, 'INC-') !== false && !$text) { $response_text = "✅ *رسید دریافت شد*\n\n"; $response_text .= "عکس رسید واریز شما با موفقیت دریافت شد.\n\n"; $response_text .= "⏳ *وضعیت:*\n"; $response_text .= "در حال بررسی و تایید توسط ادمین...\n\n"; $response_text .= "💡 پس از تایید (معمولاً کمتر از 30 دقیقه)، موجودی حساب شما افزایش خواهد یافت.\n\n"; $response_text .= "📬 نتیجه تایید به شما اطلاع داده خواهد شد."; $bot->sendMessage($from_id, $response_text, $main_keyboard, $message_id); $query = "SELECT * FROM `transactions` WHERE `track_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$currentUser->step]); $thisTransaction = $stmt->fetch(); $amount = $thisTransaction->amount; $track_id = $thisTransaction->track_id; $card = $thisTransaction->card; $time = $thisTransaction->created_at; $caption = "🆕 یک تایید واریز جدید دریافت شد!\n"; $caption .= "💰 مبلغ: " . number_format($amount) . " تومان\n"; $caption .= "📅 تاریخ: " . jdate("H:i:s - Y/m/d", strtotime($time), tr_num: 'en') . "\n"; $caption .= "🔖 شماره پیگیری: " . $track_id . "\n"; $caption .= "💳 شماره کارت: " . $card . "\n"; $channel = 5910225814; $bot->sendPhoto($channel, $photo_id, $caption, json_encode([ 'inline_keyboard' => [ [['text' => '✅ تایید واریز', 'callback_data' => 'confirme:amount-' . $currentUser->step]], [['text' => '❌ عدم تایید واریز', 'callback_data' => 'reject:amount-' . $currentUser->step]] ] ])); setStep($from_id, 'home'); die; } if (strpos($data, 'confirme:amount-') !== false) { $transId = explode('-', $data, 2)[1]; $query = "SELECT * FROM `transactions` WHERE `track_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$transId]); $thisTransaction = $stmt->fetch(); $query = "UPDATE `transactions` SET status = ?,`updated_at` = ? WHERE `track_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([1, date("Y-m-d H:i:s"), $transId]); $amount = $thisTransaction->amount; $user = $thisTransaction->chat_id; $query = "UPDATE `users` SET `balance` = `balance` + ? WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$amount, $user]); $amount_formatted = number_format($amount); $response_text = "✅ *شارژ حساب موفق*\n\n"; $response_text .= "حساب کاربری شما به مبلغ `$amount_formatted` تومان شارژ شد.\n\n"; $response_text .= "💰 موجودی جدید شما: `" . number_format(selectUser($user)->balance) . "` تومان"; $bot->sendMessage($user, $response_text); $query = "SELECT * FROM `affiliates` WHERE `user_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$user]); $result = $stmt->fetch(); if ($result->parent_id) { $parent_id = $result->parent_id; $stmt = $db->prepare("SELECT * FROM `settings` WHERE `key_` = ?"); $stmt->execute(['bonus_percent']); $result = $stmt->fetch(); $percent = $result->value_ ?? 0; $calculate = $amount * ($percent / 100); $query = "UPDATE `users` SET `balance` = `balance` + ? WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$calculate, $parent_id]); $calculate_formatted = number_format($calculate); $response_text = "🎁 *هدیه زیرمجموعه*\n\n"; $response_text .= "مبلغ `$calculate_formatted` تومان هدیه شارژ حساب زیرمجموعه شما به حساب کاربری شما افزوده گردید.\n\n"; $response_text .= "💰 موجودی جدید شما: `" . number_format(selectUser($parent_id)->balance) . "` تومان"; $bot->sendMessage($parent_id, $response_text); } $bot->editMessageReplyMarkup($chat_id, $message_id, json_encode([ 'inline_keyboard' => [ [['text' => 'وضعیت: تایید شد ✅', 'callback_data' => 0]] ] ])); die; } if (strpos($data, 'reject:amount-') !== false) { $transId = explode('-', $data, 2)[1]; $query = "SELECT * FROM `transactions` WHERE `track_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$transId]); $thisTransaction = $stmt->fetch(); $query = "UPDATE `transactions` SET `status` = ?,`updated_at`= ? WHERE `track_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([0, date("Y-m-d H:i:s"), $transId]); $amount = $thisTransaction->amount; $user = $thisTransaction->chat_id; $amount_formatted = number_format($amount); $response_text = "❌ *درخواست شارژ رد شد*\n\n"; $response_text .= "درخواست شارژ شما به مبلغ `$amount_formatted` تومان رد شد.\n\n"; $response_text .= "💬 لطفاً برای بررسی بیشتر با پشتیبانی تماس بگیرید."; $bot->sendMessage($user, $response_text); $bot->editMessageReplyMarkup($chat_id, $message_id, json_encode([ 'inline_keyboard' => [ [['text' => 'وضعیت: رد شد ❌', 'callback_data' => 0]] ] ])); die; }