bug修复

This commit is contained in:
MasonLiu committed 2026-05-30 15:06:24 +08:00
1 parent 914208aa70
commit 88f7fc7141
8 files changed
+949 -456

No files matched your search

+52 -48
View File
@@ -1,5 +1,6 @@
<?php
require_once __DIR__ . '/app/db_helper.php';
require_once __DIR__ . '/app/logger.php';
require_once __DIR__ . '/mofangidc.php';
// 存储API_PASS
@@ -110,50 +111,36 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$db = getVpsDB();
$configs = $db->query('SELECT * FROM configs ORDER BY id');
// 构建配置ID到配置的映射
// 构建配置ID到api_label的映射
$configMap = [];
foreach ($configs as $config) {
$configMap[$config['id']] = $config;
$configMap[$config['id']] = $config['api_label'];
}
// 获取所有VPS列表(只从vpslist.db查询)
// 获取所有VPS列表(从vpslist.db查询)
$listDb = getVpsListDB();
$vpsList = $listDb->query('SELECT * FROM vps_list ORDER BY config_id, vps_id');
// 为每个VPS添加site_type和site_url信息
// 为每个VPS添加api_label
foreach ($vpsList as &$vps) {
$configId = $vps['config_id'];
if (isset($configMap[$configId])) {
$vps['site_type'] = $configMap[$configId]['site_type'];
// 修正site_url:移除末尾的/v1或/v1/
$siteUrl = $configMap[$configId]['site_url'];
$siteUrl = rtrim($siteUrl, '/'); // 移除末尾的 /
if (substr($siteUrl, -3) === '/v1') {
$siteUrl = substr($siteUrl, 0, -3); // 移除 /v1
}
$vps['site_url'] = $siteUrl;
} else {
$vps['site_type'] = 'unknown';
$vps['site_url'] = '';
}
$vps['api_label'] = $configMap[$configId] ?? 'Unknown';
}
unset($vps); // 解除引用
unset($vps);
// 调试信息(临时)
error_log("Configs count: " . count($configs));
error_log("VPS List count: " . count($vpsList));
Logger::info("Total VPS count: " . count($vpsList), 'index.php');
if (!empty($vpsList)) {
error_log("First VPS: " . json_encode($vpsList[0]));
Logger::debug("First VPS: " . json_encode($vpsList[0]), 'index.php');
}
// 按配置分组
$vpsByConfig = [];
// 按api_label分组
$vpsByApiLabel = [];
foreach ($vpsList as $vps) {
$configId = $vps['config_id'];
if (!isset($vpsByConfig[$configId])) {
$vpsByConfig[$configId] = [];
$apiLabel = $vps['api_label'];
if (!isset($vpsByApiLabel[$apiLabel])) {
$vpsByApiLabel[$apiLabel] = [];
}
$vpsByConfig[$configId][] = $vps;
$vpsByApiLabel[$apiLabel][] = $vps;
}
// 统计信息
@@ -296,6 +283,15 @@ foreach ($vpsList as $vps) {
.power-off {
background-color: #dc3545;
}
.power-process {
background-color: #ffc107;
box-shadow: 0 0 8px #ffc107;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.power-unknown {
background-color: #6c757d;
}
@@ -395,43 +391,37 @@ foreach ($vpsList as $vps) {
</a>
</div>
<?php else: ?>
<!-- 按配置分组显示VPS -->
<?php foreach ($configs as $config):
$configVps = $vpsByConfig[$config['id']] ?? [];
$typeMap = [
'mofang' => '魔方平台',
'aliyun' => '阿里云',
'tencent' => '腾讯云'
];
$typeName = $typeMap[$config['site_type']] ?? $config['site_type'];
?>
<!-- 按api_label分组显示VPS -->
<?php foreach ($vpsByApiLabel as $apiLabel => $labelVps): ?>
<div class="config-section">
<div class="config-title">
<?php echo htmlspecialchars($config['api_label']); ?>
(<?php echo htmlspecialchars($typeName); ?>)
- <?php echo count($configVps); ?> 台VPS
<?php echo htmlspecialchars($apiLabel); ?>
- <?php echo count($labelVps); ?> 台VPS
</div>
<?php if (empty($configVps)): ?>
<?php if (empty($labelVps)): ?>
<div class="empty-state" style="background: white; padding: 40px;">
<p>此配置下暂无VPS,请点击"手动刷新VPS列表"获取</p>
<p>此配置下暂无VPS,请点击“手动刷新VPS列表”获取</p>
</div>
<?php else: ?>
<div class="vps-grid">
<?php foreach ($configVps as $vps):
<?php foreach ($labelVps as $vps):
$statusClass = 'power-unknown';
$statusText = '未知';
$statusColor = '#999';
if ($vps['status'] === 'on') {
if ($vps['status'] === 'on' || $vps['status'] === 'running') {
$statusClass = 'power-on';
$statusText = '运行中';
$statusColor = '#28a745';
} elseif ($vps['status'] === 'off') {
} elseif ($vps['status'] === 'off' || $vps['status'] === 'stopped') {
$statusClass = 'power-off';
$statusText = '已关机';
$statusColor = '#dc3545';
} elseif ($vps['status'] === 'process' || $vps['status'] === 'pending' || $vps['status'] === 'rebooting') {
$statusClass = 'power-process';
$statusText = '处理中';
$statusColor = '#ffc107';
}
?>
<div class="vps-card">
@@ -482,6 +472,20 @@ foreach ($vpsList as $vps) {
<span class="info-value"><?php echo htmlspecialchars($vps['disk_size']) . ' / ' . htmlspecialchars($vps['bandwidth']) . ' / ' . htmlspecialchars($vps['os_type']); ?></span>
</div>
<?php endif; ?>
<?php if ($vps['amount']): ?>
<div class="info-row">
<span class="info-label">价格</span>
<span class="info-value"><?php echo htmlspecialchars($vps['amount']); ?></span>
</div>
<?php endif; ?>
<?php if ($vps['nextduedate']): ?>
<div class="info-row">
<span class="info-label">到期时间</span>
<span class="info-value"><?php echo date('Y-m-d', $vps['nextduedate']); ?></span>
</div>
<?php endif; ?>
</div>
<div class="power-status">