diff --git a/api/get_option_orders.php b/api/get_option_orders.php index 28e42c7..f343460 100644 --- a/api/get_option_orders.php +++ b/api/get_option_orders.php @@ -20,7 +20,7 @@ $pdo = db(); // --- Settlement Logic for Due Orders --- try { $now = date('Y-m-d H:i:s'); - // Fetch orders that are pending and due for settlement, and join with users to get control settings. + // Fetch orders that are pending and due for settlement $stmt = $pdo->prepare( "SELECT o.*, u.win_loss_control FROM option_orders o " . "JOIN users u ON o.user_id = u.id " . @@ -33,44 +33,38 @@ try { $pdo->beginTransaction(); foreach ($due_orders as $order) { - $result = 'loss'; // Default to loss + $result = 'loss'; - // Determine final control setting (user's setting is the only one we consider as per request) $final_control = $order['win_loss_control']; if ($final_control == 'win') { $result = 'win'; } elseif ($final_control == 'loss') { $result = 'loss'; - } else { // No control set, default to random - $result = (rand(0, 100) < 51) ? 'loss' : 'win'; // 51% chance to lose to have a house edge + } else { + $result = (rand(0, 100) < 51) ? 'loss' : 'win'; } $profit = 0; - // Calculate profit and update user balance if ($result === 'win') { $profit = $order['amount'] * $order['profit_rate']; $total_return = $order['amount'] + $profit; - // Credit the user's balance with the principal + profit $bal_stmt = $pdo->prepare("UPDATE users SET balance = balance + ? WHERE id = ?"); $bal_stmt->execute([$total_return, $order['user_id']]); } else { - // Loss means the wagered amount is lost. No balance update needed as it was deducted at placement. $profit = -$order['amount']; } - // Fake a closing price that realistically matches the outcome - $price_variation = (float)($order['open_price'] * 0.0001 * rand(1, 5)); + $price_variation = (float)($order['opening_price'] * 0.0001 * rand(1, 5)); if (($order['direction'] === 'up' && $result === 'win') || ($order['direction'] === 'down' && $result === 'loss')) { - $closing_price = $order['open_price'] + $price_variation; + $closing_price = $order['opening_price'] + $price_variation; } else { - $closing_price = $order['open_price'] - $price_variation; + $closing_price = $order['opening_price'] - $price_variation; } - // Update the order to settled status $update_stmt = $pdo->prepare( - "UPDATE option_orders SET status = 'completed', result = ?, profit = ?, close_price = ? WHERE id = ?" + "UPDATE option_orders SET status = 'completed', result = ?, profit = ?, closing_price = ? WHERE id = ?" ); $update_stmt->execute([$result, $profit, $closing_price, $order['id']]); } @@ -81,13 +75,12 @@ try { $pdo->rollBack(); } error_log("Option settlement failed: " . $e->getMessage()); - // Don't exit, still try to fetch orders for the user } // --- Fetch and Return Orders for Frontend --- -$stmt = $pdo->prepare("SELECT * FROM option_orders WHERE user_id = ? AND status = ? ORDER BY start_time DESC LIMIT 50"); +$stmt = $pdo->prepare("SELECT * FROM option_orders WHERE user_id = ? AND status = ? ORDER BY created_at DESC LIMIT 50"); $stmt->execute([$user_id, $status_filter]); $orders = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode($orders); -?> +?> \ No newline at end of file diff --git a/api/place_option_order.php b/api/place_option_order.php index c9f04c6..27e7199 100644 --- a/api/place_option_order.php +++ b/api/place_option_order.php @@ -17,6 +17,7 @@ $amount = (float)($data['amount'] ?? 0); $direction = $data['direction'] ?? null; $duration = (int)($data['duration'] ?? 0); $rate = (float)($data['rate'] ?? 0); // Profit rate in percentage +$frontend_price = isset($data['price']) ? (float)$data['price'] : null; if (empty($pair) || empty($direction) || $amount <= 0 || $duration <= 0 || $rate <= 0) { echo json_encode(['success' => false, 'error' => 'Invalid order parameters.']); @@ -61,9 +62,15 @@ function get_current_price($symbol) { } $open_price = get_current_price($pair); + +// Fallback to frontend price if server fetch fails if ($open_price === null) { - echo json_encode(['success' => false, 'error' => 'Could not fetch current price for the pair. Please try again.']); - exit; + if ($frontend_price !== null && $frontend_price > 0) { + $open_price = $frontend_price; + } else { + echo json_encode(['success' => false, 'error' => 'Could not fetch current price for the pair. Please try again.']); + exit; + } } // --- Database Transaction --- @@ -90,10 +97,10 @@ try { // 3. Insert the new option order $start_time = date('Y-m-d H:i:s'); $settle_at = date('Y-m-d H:i:s', time() + $duration); - $profit_rate_decimal = $rate / 100; // Store as decimal for calculation + $profit_rate_decimal = $rate / 100; $stmt = $pdo->prepare( - "INSERT INTO option_orders (user_id, pair, amount, direction, duration, profit_rate, open_price, status, start_time, settle_at) " . + "INSERT INTO option_orders (user_id, symbol, amount, direction, duration, profit_rate, opening_price, status, created_at, settle_at) " . "VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?)" ); $stmt->execute([$user_id, $pair, $amount, $direction, $duration, $profit_rate_decimal, $open_price, $start_time, $settle_at]); @@ -115,6 +122,6 @@ try { $pdo->rollBack(); } error_log("Option order failed: " . $e->getMessage()); - echo json_encode(['success' => false, 'error' => 'An internal error occurred. Please try again later.']); + echo json_encode(['success' => false, 'error' => 'An internal error occurred.']); } ?> \ No newline at end of file diff --git a/assets/pasted-20260213-151532-3946676c.png b/assets/pasted-20260213-151532-3946676c.png new file mode 100644 index 0000000..442bc28 Binary files /dev/null and b/assets/pasted-20260213-151532-3946676c.png differ diff --git a/futures.php b/futures.php index e663794..7968fdd 100644 --- a/futures.php +++ b/futures.php @@ -1,153 +1,132 @@ prepare("SELECT currency, balance FROM assets WHERE user_id = ?"); + $stmt = $db->prepare("SELECT balance FROM users WHERE id = ?"); + $stmt->execute([$user_id]); + $usdt_balance = $stmt->fetchColumn(); + $user_assets['USDT'] = (float)($usdt_balance ?: 0); + + $stmt = $db->prepare("SELECT symbol, amount FROM user_assets WHERE user_id = ?"); $stmt->execute([$user_id]); $assets_data = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); if ($assets_data) { - $user_assets = $assets_data; + foreach ($assets_data as $symbol => $amount) { + $user_assets[$symbol] = (float)$amount; + } } } ?>
- -
-
+
+ +
- -
+ +
+
-
-
- - --/-- +
+ + --/--
-
--
-
--
+
--
+
--
-
--
-
--
-
--
-
-
-
+
-
+
20x
-
USDT
-
--
-
-
: 0.00 USDT
-
- - +
USDT
+
--
+
+
: 0.00 USDT
+
+ +
@@ -155,279 +134,168 @@ if ($user_id) {
-
+
+
+
-
+ +
- -
-
- (USDT) - (--) - -
-
+
+
+
-
--
+
--
- -
+ - - - \ No newline at end of file diff --git a/includes/i18n.php b/includes/i18n.php index 7067075..a1d8510 100644 --- a/includes/i18n.php +++ b/includes/i18n.php @@ -145,6 +145,10 @@ $translations = [ 'order_date' => 'Order Date', 'options_order_executing' => 'Order is executing, settlement upon countdown completion.', 'options_order_settled' => 'Order settled.', + 'win' => 'Win', + 'loss' => 'Loss', + 'profit_amount' => 'Profit Amount', + 'loss_amount' => 'Loss Amount', 'kyc_status' => 'KYC Verification', 'kyc_none' => 'Unverified', @@ -170,6 +174,7 @@ $translations = [ 'orders' => 'Orders', 'order_placed' => 'Order Placed', 'min_amount' => 'Min Amount', + 'trades' => 'Trades', 'home_slide1_title' => 'NovaEx Global Launch', 'home_slide1_desc' => 'Experience the next generation of digital asset trading with ultra-low latency and bank-grade security.', @@ -359,6 +364,10 @@ $translations = [ 'order_date' => '下单日期', 'options_order_executing' => '订单执行中,倒计时结束后结算。', 'options_order_settled' => '订单已结算。', + 'win' => '盈利', + 'loss' => '亏损', + 'profit_amount' => '盈利金额', + 'loss_amount' => '亏损金额', 'kyc_status' => '实名认证', 'kyc_none' => '未认证', @@ -384,15 +393,16 @@ $translations = [ 'orders' => '订单', 'order_placed' => '下单成功', 'min_amount' => '最小金额', + 'trades' => '最新成交', 'home_slide1_title' => 'NovaEx 全球发布', 'home_slide1_desc' => '体验超低延迟和银行级安全的新一代数字资产交易。', 'home_slide2_title' => '100倍杠杆合约交易', 'home_slide2_desc' => '通过我们的专业永续合约最大限度地提高您的资金效率。', 'home_slide3_title' => '安全数字资产质押', - 'home_slide3_desc' => 'Earn passive income on your idle assets with our high-yield staking pools.', + 'home_slide3_desc' => '通过我们的高收益质押池为您的闲置资产赚取被动收入。', 'home_download_title' => '随时随地,随心交易', - 'home_download_desc' => 'Stay connected to the markets with the NovaEx mobile app. Experience professional trading features in the palm of your hand.', + 'home_download_desc' => '通过 NovaEx 移动应用随时随地关注市场。在掌中体验专业交易功能。', 'fast_secure' => '快速且安全', 'fast_secure_desc' => '为您的所有数据提供军用级加密。', 'real_time' => '实时行情', @@ -454,4 +464,4 @@ $lang = $_SESSION['lang']; function __($key, $default = '') { global $translations, $lang; return $translations[$lang][$key] ?? ($translations['en'][$key] ?? ($default ?: $key)); -} +} \ No newline at end of file diff --git a/options.php b/options.php index 3c0f019..81b25fc 100644 --- a/options.php +++ b/options.php @@ -1,200 +1,258 @@ prepare("SELECT currency, balance FROM assets WHERE user_id = ?"); + // $db is already defined in header.php + $stmt = $db->prepare("SELECT balance FROM users WHERE id = ?"); + $stmt->execute([$user_id]); + $usdt_balance = $stmt->fetchColumn(); + $user_assets['USDT'] = (float)($usdt_balance ?: 0); + + $stmt = $db->prepare("SELECT symbol, amount FROM user_assets WHERE user_id = ?"); $stmt->execute([$user_id]); $assets_data = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); if ($assets_data) { - $user_assets = $assets_data; + foreach ($assets_data as $symbol => $amount) { + $user_assets[$symbol] = (float)$amount; + } } } ?>
-
- -
+ +
- -
+ +
- +
-
--/--
-
--
--
-
--
-
--
+
+ + --/-- +
+
+
--
+
--
+
+
--
+
--
+
+
-
-
-
/
-
-
60s
+8%
-
90s
+12%
-
120s
+15%
-
180s
+20%
-
300s
+32%
-
-
-
-
-
USDT
-
-
: 0.00
-
: +0.00
-
-
-
- - + +
+ +
+
60s
+8%
+
90s
+12%
+
120s
+15%
+
180s
+20%
+
300s
+32%
+ + +
+ +
+ + USDT +
+
+ + +
+
+ : + 0.00 USDT +
+
+ : + +0.00 +
+
+ + +
+ + +
+
-
+
- -
+ +
-
- (USDT) - (BTC) - +
+ (USDT) +
-
+
-
+
--
@@ -202,30 +260,56 @@ if ($user_id) {
-
-
- -