38350-vm/api/get_assets.php
Flatlogic Bot 79b07243ce 交易所
2026-02-11 15:18:19 +00:00

40 lines
1.0 KiB
PHP

<?php
session_start();
require_once '../db/config.php';
header('Content-Type: application/json');
if (!isset($_SESSION['user_id'])) {
echo json_encode(['success' => false, 'error' => 'Unauthorized']);
exit;
}
$user_id = $_SESSION['user_id'];
try {
$db = db();
// Get USDT balance
$stmt = $db->prepare("SELECT balance FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$usdt = $stmt->fetchColumn();
// Get other assets
$stmt = $db->prepare("SELECT symbol, amount FROM user_assets WHERE user_id = ? AND amount > 0");
$stmt->execute([$user_id]);
$other_assets = $stmt->fetchAll(PDO::FETCH_ASSOC);
$assets = [['symbol' => 'USDT', 'amount' => (float)$usdt]];
foreach ($other_assets as $asset) {
$assets[] = [
'symbol' => $asset['symbol'],
'amount' => (float)$asset['amount']
];
}
echo json_encode(['success' => true, 'data' => $assets]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}