38301-vm/withdraw.php
2026-02-09 05:52:15 +00:00

108 lines
4.6 KiB
PHP

<?php
require_once 'includes/header.php';
if (!$user) {
header('Location: login.php');
exit;
}
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$amount = (float)($_POST['amount'] ?? 0);
$address = $_POST['address'] ?? '';
$security_password = $_POST['security_password'] ?? '';
if ($amount <= 0) {
$error = 'Invalid amount.';
} elseif ($amount > $user['balance_usdt']) {
$error = 'Insufficient balance.';
} elseif (empty($address)) {
$error = 'Please enter withdrawal address.';
} elseif (!password_verify($security_password, $user['security_password'])) {
$error = 'Incorrect trading password.';
} else {
try {
db()->beginTransaction();
// Deduct balance
$stmt = db()->prepare("UPDATE users SET balance_usdt = balance_usdt - ? WHERE id = ?");
$stmt->execute([$amount, $user['id']]);
// Record transaction (assuming a transactions table exists or just for mock)
// For now just success message
db()->commit();
$success = 'Withdrawal request submitted successfully.';
$user['balance_usdt'] -= $amount;
} catch (Exception $e) {
db()->rollBack();
$error = 'Withdrawal failed: ' . $e->getMessage();
}
}
}
?>
<div class="container my-5 py-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card bg-dark border-secondary p-4 shadow-lg" style="border-radius: 24px;">
<h3 class="fw-bold mb-4 text-white"><i class="fas fa-arrow-up me-2 text-danger"></i> <?php echo mt('Withdraw'); ?> USDT</h3>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success"><?php echo $success; ?></div>
<?php endif; ?>
<div class="bg-secondary bg-opacity-10 p-3 rounded-3 mb-4 border border-secondary">
<div class="small text-muted mb-1"><?php echo mt('Available'); ?></div>
<h4 class="fw-bold text-white mb-0"><?php echo number_format($user['balance_usdt'], 2); ?> USDT</h4>
</div>
<form method="POST">
<div class="mb-3">
<label class="form-label text-muted">Withdrawal Address</label>
<input type="text" name="address" class="form-control bg-dark text-white border-secondary py-3" placeholder="Enter USDT (TRC20) address" required>
</div>
<div class="mb-3">
<label class="form-label text-muted">Amount</label>
<div class="input-group">
<input type="number" name="amount" class="form-control bg-dark text-white border-secondary py-3" placeholder="Min 10.00" step="0.01" required>
<span class="input-group-text bg-dark border-secondary text-muted">USDT</span>
</div>
</div>
<div class="mb-4">
<label class="form-label text-muted"><?php echo mt('Trading Password'); ?> (6 digits)</label>
<input type="password" name="security_password" class="form-control bg-dark text-white border-secondary py-3" placeholder="Enter your 6-digit password" pattern="\d{6}" maxlength="6" required>
<div class="form-text text-muted small">Default is 123456</div>
</div>
<button type="submit" class="btn btn-danger w-100 py-3 fw-bold fs-5" style="border-radius: 12px;"><?php echo mt('Withdraw'); ?> USDT</button>
<div class="mt-4 p-3 bg-light bg-opacity-5 rounded-3 border border-secondary small text-muted">
<p class="mb-1"><i class="fas fa-info-circle me-1"></i> Withdrawal Tips:</p>
<ul class="ps-3 mb-0">
<li>Minimum withdrawal: 10 USDT</li>
<li>Processing time: 10-30 minutes</li>
<li>Network: TRC20 only</li>
</ul>
</div>
</form>
</div>
</div>
</div>
</div>
<style>
.form-control:focus {
background-color: #2b2f36;
border-color: #f6465d;
box-shadow: none;
color: #fff;
}
</style>
<?php require_once 'includes/footer.php'; ?>