-
-
+
@@ -341,6 +420,58 @@ $requests = $stmt->fetchAll();
diff --git a/api/admin_recharge.php b/api/admin_recharge.php
index 41aacc9..bf3fc9a 100644
--- a/api/admin_recharge.php
+++ b/api/admin_recharge.php
@@ -11,28 +11,31 @@ if (!isset($_SESSION['admin_id'])) {
}
$action = $_GET['action'] ?? '';
+$order_id = $_REQUEST['id'] ?? null;
$user_id = $_REQUEST['user_id'] ?? null;
$ip_address = $_REQUEST['ip_address'] ?? '';
$session_id = $_REQUEST['session_id'] ?? '';
-if (!isset($user_id) && empty($ip_address)) {
- echo json_encode(['success' => false, 'error' => 'Missing User ID or IP']);
+if (!$order_id && !isset($user_id) && empty($ip_address)) {
+ echo json_encode(['success' => false, 'error' => 'Missing ID, User ID or IP']);
exit;
}
try {
$db = db();
- // Find the latest pending/matching/account_sent recharge for this user
- // We try to match by user_id first, then by IP/Session if user_id is 0
- if ($user_id > 0) {
- $stmt = $db->prepare("SELECT id FROM finance_requests WHERE user_id = ? AND type = 'recharge' AND status IN ('0', '1', '2', 'pending', 'matched', 'account_sent', 'finished') ORDER BY id DESC LIMIT 1");
- $stmt->execute([$user_id]);
- } else {
- $stmt = $db->prepare("SELECT id FROM finance_requests WHERE (ip_address = ? OR payment_details = ?) AND type = 'recharge' AND status IN ('0', '1', '2', 'pending', 'matched', 'account_sent', 'finished') ORDER BY id DESC LIMIT 1");
- $stmt->execute([$ip_address, $session_id]);
+ if (!$order_id) {
+ // Find the latest pending/matching/account_sent recharge for this user
+ // We try to match by user_id first, then by IP/Session if user_id is 0
+ if ($user_id > 0) {
+ $stmt = $db->prepare("SELECT id FROM finance_requests WHERE user_id = ? AND type = 'recharge' AND status IN ('0', '1', '2', 'pending', 'matched', 'account_sent', 'finished') ORDER BY id DESC LIMIT 1");
+ $stmt->execute([$user_id]);
+ } else {
+ $stmt = $db->prepare("SELECT id FROM finance_requests WHERE (ip_address = ? OR payment_details = ?) AND type = 'recharge' AND status IN ('0', '1', '2', 'pending', 'matched', 'account_sent', 'finished') ORDER BY id DESC LIMIT 1");
+ $stmt->execute([$ip_address, $session_id]);
+ }
+ $order_id = $stmt->fetchColumn();
}
- $order_id = $stmt->fetchColumn();
if (!$order_id) {
echo json_encode(['success' => false, 'error' => '未找到该用户的待处理充值订单']);
@@ -47,18 +50,7 @@ try {
$stmt = $db->prepare("UPDATE finance_requests SET status = '1', account_bank = ?, account_name = ?, account_number = ? WHERE id = ?");
$stmt->execute([$bank, $name, $account, $order_id]);
- if ($stmt->rowCount() > 0) {
- echo json_encode(['success' => true]);
- } else {
- // Check if it was already status 1
- $stmt = $db->prepare("SELECT status FROM finance_requests WHERE id = ?");
- $stmt->execute([$order_id]);
- if ($stmt->fetchColumn() == '1') {
- echo json_encode(['success' => true, 'note' => 'Already matched']);
- } else {
- echo json_encode(['success' => false, 'error' => '更新失败']);
- }
- }
+ echo json_encode(['success' => true]);
}
elseif ($action === 'send_account') {
$bank = $_POST['bank'] ?? '';
@@ -72,7 +64,7 @@ try {
echo json_encode(['success' => true]);
}
elseif ($action === 'approve') {
- $confirm_amount = $_POST['confirm_amount'] ?? null;
+ $confirm_amount = $_POST['confirm_amount'] ?? $_POST['final_amount'] ?? null;
if ($confirm_amount === null) {
echo json_encode(['success' => false, 'error' => 'Missing confirmation amount']);
exit;
@@ -81,17 +73,18 @@ try {
$db->beginTransaction();
try {
// Get order details
- $stmt = $db->prepare("SELECT user_id, amount, symbol FROM finance_requests WHERE id = ?");
+ $stmt = $db->prepare("SELECT * FROM finance_requests WHERE id = ?");
$stmt->execute([$order_id]);
$order = $stmt->fetch();
if (!$order) throw new Exception("订单不存在");
+ if ($order['status'] == '3') throw new Exception("订单已审核通过,请勿重复操作");
- // Update order status
- $stmt = $db->prepare("UPDATE finance_requests SET status = 'completed', amount = ? WHERE id = ?");
+ // Update order status to '3' (Approved)
+ $stmt = $db->prepare("UPDATE finance_requests SET status = '3', amount = ? WHERE id = ?");
$stmt->execute([$confirm_amount, $order_id]);
- // Update user balance if user_id > 0
+ // Update user balance
if ($order['user_id'] > 0) {
// Ensure balance record exists
$stmt = $db->prepare("SELECT id FROM user_balances WHERE user_id = ? AND symbol = ?");
@@ -106,7 +99,11 @@ try {
// Record transaction
$stmt = $db->prepare("INSERT INTO transactions (user_id, type, amount, symbol, status, ip_address) VALUES (?, 'recharge', ?, ?, 'completed', ?)");
- $stmt->execute([$order['user_id'], $confirm_amount, $order['symbol'], $ip_address]);
+ $stmt->execute([$order['user_id'], $confirm_amount, $order['symbol'], $order['ip_address']]);
+
+ // Update stats
+ require_once __DIR__ . '/../admin/stats.php'; // For any helper functions if needed, or just do manual updates
+ // The finance.php has some logic for VIP levels, I should probably replicate or call it.
}
$db->commit();
@@ -117,7 +114,7 @@ try {
}
}
elseif ($action === 'reject') {
- $stmt = $db->prepare("UPDATE finance_requests SET status = 'rejected' WHERE id = ?");
+ $stmt = $db->prepare("UPDATE finance_requests SET status = '4' WHERE id = ?");
$stmt->execute([$order_id]);
echo json_encode(['success' => true]);
}
diff --git a/recharge.php b/recharge.php
index 2010c1b..cc70205 100644
--- a/recharge.php
+++ b/recharge.php
@@ -560,7 +560,7 @@ function startStatusPolling(order_id) {
// Ensure data status is treated as string for comparison
const currentStatus = String(data.status);
renderRechargeUI(data);
- if (currentStatus === 'completed' || currentStatus === 'rejected') clearInterval(window.statusPollingInterval);
+ if (currentStatus === 'completed' || currentStatus === '3' || currentStatus === 'rejected' || currentStatus === '4') clearInterval(window.statusPollingInterval);
}
} catch (e) { console.error('Status polling error:', e); }
};
@@ -573,12 +573,12 @@ function renderRechargeUI(data) {
if (!side) return;
const status = String(data.status);
- if (status === 'completed') {
+ if (status === 'completed' || status === '3') {
finishTransferUI();
return;
}
- if (status === 'rejected') {
+ if (status === 'rejected' || status === '4') {
side.innerHTML = `