完整修复

This commit is contained in:
Flatlogic Bot 2026-02-21 09:20:29 +00:00
parent 9c8652e6a3
commit 600ed722e9
9 changed files with 125 additions and 21 deletions

View File

@ -2,14 +2,14 @@
require_once __DIR__ . '/layout.php';
$db = db();
$title = '质押挖矿管理';
$title = __('mining_management');
ob_start();
$records = $db->query("SELECT r.*, u.username, u.uid FROM staking_records r JOIN users u ON r.user_id = u.id ORDER BY r.created_at DESC")->fetchAll();
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<div class="d-flex align-items-center gap-3">
<a href="index.php" class="btn btn-outline-secondary btn-sm"><i class="bi bi-arrow-left"></i> 返回</a>
<h4 class="mb-0">挖矿记录明细</h4>
<a href="index.php" class="btn btn-outline-secondary btn-sm"><i class="bi bi-arrow-left"></i> <?= __('back') ?></a>
<h4 class="mb-0"><?= __('mining_management') ?></h4>
</div>
</div>
<div class="table-container">
@ -17,12 +17,13 @@ $records = $db->query("SELECT r.*, u.username, u.uid FROM staking_records r JOIN
<thead>
<tr class="small text-muted">
<th>ID</th>
<th>用户</th>
<th>项目</th>
<th>质押金额</th>
<th>日收益率</th>
<th>期限/结束</th>
<th>状态</th>
<th><?= __('users') ?></th>
<th><?= __('mining_pool') ?></th>
<th><?= __('amount') ?></th>
<th><?= __('total_profit') ?></th>
<th><?= __('est_apy') ?></th>
<th><?= __('cycle') ?> / <?= __('last_updated') ?></th>
<th><?= __('status') ?></th>
</tr>
</thead>
<tbody>
@ -30,11 +31,21 @@ $records = $db->query("SELECT r.*, u.username, u.uid FROM staking_records r JOIN
<tr>
<td><?= $r['id'] ?></td>
<td><?= htmlspecialchars($r['username']) ?><br><code class="small"><?= $r['uid'] ?></code></td>
<td><?= htmlspecialchars($r['plan_name']) ?></td>
<td><strong><?= number_format($r['amount'], 2) ?> <?= $r['symbol'] ?></strong></td>
<td><?= $r['daily_profit'] ?>%</td>
<td><?= $r['period'] ?>天<br><small><?= $r['end_date'] ?></small></td>
<td><span class="badge <?= $r['status'] === 'running' ? 'bg-primary' : 'bg-secondary' ?>"><?= $r['status'] === 'running' ? '运行中' : '已结束' ?></span></td>
<td><?= htmlspecialchars($r['plan_name']) ?> (<?= $r['symbol'] ?>)</td>
<td><strong><?= number_format($r['amount'], 4) ?></strong></td>
<td class="text-success fw-bold">+<?= number_format($r['total_profit'], 6) ?></td>
<td><?= number_format($r['daily_profit'] * 365, 1) ?>%</td>
<td>
<span class="small"><?= $r['period'] ?> <?= __('day') ?></span><br>
<small class="text-muted"><?= $r['last_settle_time'] ?: $r['created_at'] ?></small>
</td>
<td>
<?php if ($r['status'] === 'running'): ?>
<span class="badge bg-primary"><?= __('running') ?></span>
<?php else: ?>
<span class="badge bg-secondary"><?= __('completed') ?></span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -53,12 +53,12 @@ try {
$endDate = date('Y-m-d', strtotime("+$period days"));
if ($period == 0) $endDate = '2099-12-31';
$stmt = $db->prepare("INSERT INTO staking_records (user_id, plan_name, amount, symbol, daily_profit, period, status, start_date, end_date, ip_address) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt = $db->prepare("INSERT INTO staking_records (user_id, plan_name, amount, symbol, daily_profit, period, status, start_date, end_date, last_settle_time, ip_address) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)");
$stmt->execute([$userId, $poolName, $amount, $symbol, $dailyProfit, $period, 'running', $startDate, $endDate, getRealIP()]);
// Add transaction record
$stmt = $db->prepare("INSERT INTO transactions (user_id, symbol, type, amount, status, ip_address) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$userId, $symbol, 'mining', $amount, 'completed', getRealIP()]);
$stmt->execute([$userId, $symbol, 'mining_invest', $amount, 'completed', getRealIP()]);
$db->commit();
echo json_encode(['success' => true]);

View File

@ -1,6 +1,5 @@
<?php
require_once __DIR__ . '/includes/lang.php';
require_once __DIR__ . '/includes/header.php';
require_once __DIR__ . '/db/config.php';
// Smart Download Redirection Logic
if (isset($_GET['action']) && $_GET['action'] === 'download') {
@ -25,6 +24,9 @@ if (isset($_GET['action']) && $_GET['action'] === 'download') {
exit;
}
}
require_once __DIR__ . '/includes/lang.php';
require_once __DIR__ . '/includes/header.php';
?>
<main class="app-page-wrapper">
<!-- Hero Section -->

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

View File

@ -452,6 +452,7 @@ CREATE TABLE `staking_records` (
`user_id` int(11) NOT NULL,
`plan_name` varchar(100) NOT NULL,
`amount` decimal(20,8) NOT NULL,
`total_profit` decimal(20,8) DEFAULT 0.00000000,
`symbol` varchar(10) DEFAULT 'USDT',
`daily_profit` decimal(5,2) NOT NULL,
`period` int(11) NOT NULL COMMENT 'days',
@ -459,6 +460,7 @@ CREATE TABLE `staking_records` (
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`created_at` timestamp NULL DEFAULT current_timestamp(),
`last_settle_time` datetime DEFAULT NULL,
`ip_address` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@ -471,7 +473,7 @@ CREATE TABLE `staking_records` (
LOCK TABLES `staking_records` WRITE;
/*!40000 ALTER TABLE `staking_records` DISABLE KEYS */;
INSERT INTO `staking_records` VALUES
(1,2,'ETH矿池',3.00000000,'ETH',0.02,0,'running','2026-02-20','2099-12-31','2026-02-20 05:29:16',NULL);
(1,2,'ETH矿池',3.00000000,0.00000000,'ETH',0.02,0,'running','2026-02-20','2099-12-31','2026-02-20 05:29:16','2026-02-20 05:29:16',NULL);
/*!40000 ALTER TABLE `staking_records` ENABLE KEYS */;
UNLOCK TABLES;

View File

@ -8,6 +8,11 @@ if (isset($_SESSION['user_id'])) {
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
if ($user) {
require_once __DIR__ . '/mining_helper.php';
settleMining($user['id']);
}
}
// site settings are fetched via getSetting() in db/config.php

View File

@ -1209,6 +1209,23 @@ $translations = [
'contact_sup_title' => 'Contact Support',
'contact_sup_desc' => 'Our team is available 24/7 if you encounter any issues.',
'fees_content' => 'BYRO uses a transparent fee structure designed to provide competitive trading costs.',
'platform_home' => 'Platform Home',
'admin_panel' => 'Admin Panel',
'agent_panel' => 'Agent Panel',
'users' => 'Users',
'agents' => 'Agents',
'real_name' => 'KYC',
'finance_management' => 'Finance',
'finance_details' => 'Finance Details',
'sec_contract_management' => 'Binary Management',
'spot_trading' => 'Spot Trading',
'contract_trading' => 'Contract Trading',
'exchange_management' => 'Exchange Management',
'mining_management' => 'Mining Management',
'ai_control' => 'AI Control',
'online_support' => 'Customer Service',
'backend_settings' => 'System Settings',
'personal_settings' => 'Profile Settings',
],
];

View File

@ -0,0 +1,63 @@
<?php
require_once __DIR__ . '/../db/config.php';
function settleMining($userId) {
$db = db();
try {
$db->beginTransaction();
// Find all running orders for this user
$stmt = $db->prepare("SELECT * FROM staking_records WHERE user_id = ? AND status = 'running' FOR UPDATE");
$stmt->execute([$userId]);
$orders = $stmt->fetchAll();
$now = new DateTime();
foreach ($orders as $order) {
$lastSettle = new DateTime($order['last_settle_time'] ?: $order['created_at']);
$diff = $now->getTimestamp() - $lastSettle->getTimestamp();
if ($diff <= 0) continue;
// Daily profit is a percentage (e.g. 0.02 is 2% daily)
// But looking at the SQL dump: daily_profit was 0.02 for "ETH矿池" which had "8.2%" APY.
// 8.2 / 365 = 0.02246... so 0.02 seems to be the daily percentage.
$dailyRate = $order['daily_profit'] / 100;
$profit = $order['amount'] * $dailyRate * ($diff / 86400);
if ($profit > 0.00000001) {
// Update balance
$stmt = $db->prepare("UPDATE user_balances SET available = available + ? WHERE user_id = ? AND symbol = ?");
$stmt->execute([$profit, $userId, $order['symbol']]);
// Add transaction record
$stmt = $db->prepare("INSERT INTO transactions (user_id, symbol, type, amount, status) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$userId, $order['symbol'], 'mining_profit', $profit, 'completed']);
// Update staking record
$stmt = $db->prepare("UPDATE staking_records SET total_profit = total_profit + ?, last_settle_time = NOW() WHERE id = ?");
$stmt->execute([$profit, $order['id']]);
// Check if it reached end_date
$endDate = new DateTime($order['end_date']);
if ($now >= $endDate) {
$stmt = $db->prepare("UPDATE staking_records SET status = 'ended' WHERE id = ?");
$stmt->execute([$order['id']]);
// Return principal
$stmt = $db->prepare("UPDATE user_balances SET frozen = frozen - ?, available = available + ? WHERE user_id = ? AND symbol = ?");
$stmt->execute([$order['amount'], $order['amount'], $userId, $order['symbol']]);
$stmt = $db->prepare("INSERT INTO transactions (user_id, symbol, type, amount, status) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$userId, $order['symbol'], 'mining_return', $order['amount'], 'completed']);
}
}
}
$db->commit();
} catch (Exception $e) {
if ($db->inTransaction()) $db->rollBack();
error_log("Mining settlement failed for user $userId: " . $e->getMessage());
}
}

View File

@ -1,6 +1,7 @@
<?php
require_once __DIR__ . '/includes/lang.php';
require_once __DIR__ . '/includes/header.php';
require_once __DIR__ . '/includes/mining_helper.php';
$stakingAmount = 0;
$todayProfit = 0;
@ -8,18 +9,21 @@ $totalProfit = 0;
$orderCount = 0;
if ($user) {
// Settle first
settleMining($user['id']);
// 托管中
$stmt = db()->prepare("SELECT SUM(amount) FROM staking_records WHERE user_id = ? AND status = 'running'");
$stmt->execute([$user['id']]);
$stakingAmount = $stmt->fetchColumn() ?: 0;
// 今日收益
$stmt = db()->prepare("SELECT SUM(amount) FROM transactions WHERE user_id = ? AND type = 'mining' AND DATE(created_at) = CURDATE()");
$stmt = db()->prepare("SELECT SUM(amount) FROM transactions WHERE user_id = ? AND type = 'mining_profit' AND DATE(created_at) = CURDATE()");
$stmt->execute([$user['id']]);
$todayProfit = $stmt->fetchColumn() ?: 0;
// 累计收益
$stmt = db()->prepare("SELECT SUM(amount) FROM transactions WHERE user_id = ? AND type = 'mining'");
$stmt = db()->prepare("SELECT SUM(total_profit) FROM staking_records WHERE user_id = ?");
$stmt->execute([$user['id']]);
$totalProfit = $stmt->fetchColumn() ?: 0;