功能说明:用于IDC服务商后台管理客户服务器租用订单,支持添加新订单、查看订单状态、标记到期提醒,适合小型IDC企业使用。
<?php
/**
* IDC服务器租用订单管理系统(简易版)
* 适用场景:IDC服务商后台管理客户租用订单
* 数据存储:使用JSON文件(生产环境建议改用MySQL)
*/
session_start();
// 简单的管理员登录验证(生产环境请加强)
if (!isset($_SESSION['admin'])) {
$_SESSION['admin'] = true; // 简化演示,实际应做登录验证
}
// 数据文件路径
define('DATA_FILE', __DIR__ . '/orders.json');
// 初始化数据
if (!file_exists(DATA_FILE)) {
file_put_contents(DATA_FILE, json_encode([]));
}
// 处理表单提交
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$orders = json_decode(file_get_contents(DATA_FILE), true);
switch ($_POST['action']) {
case 'add':
$newOrder = [
'id' => uniqid(),
'customer' => htmlspecialchars($_POST['customer']),
'server_spec' => htmlspecialchars($_POST['server_spec']),
'bandwidth' => htmlspecialchars($_POST['bandwidth']),
'ip_address' => htmlspecialchars($_POST['ip_address']),
'start_date' => $_POST['start_date'],
'end_date' => $_POST['end_date'],
'status' => 'active',
'created_at' => date('Y-m-d H:i:s')
];
$orders[] = $newOrder;
$message = '✅ 订单添加成功!';
break;
case 'delete':
$orderId = $_POST['order_id'];
$orders = array_filter($orders, function($o) use ($orderId) {
return $o['id'] !== $orderId;
});
$orders = array_values($orders);
$message = '✅ 订单已删除。';
break;
case 'toggle_status':
$orderId = $_POST['order_id'];
foreach ($orders as &$o) {
if ($o['id'] === $orderId) {
$o['status'] = ($o['status'] === 'active') ? 'expired' : 'active';
break;
}
}
unset($o);
$message = '✅ 订单状态已更新。';
break;
}
file_put_contents(DATA_FILE, json_encode($orders, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
// 读取现有订单
$orders = json_decode(file_get_contents(DATA_FILE), true);
// 计算到期提醒
$today = new DateTime();
$reminders = [];
foreach ($orders as $o) {
if ($o['status'] === 'active') {
$endDate = new DateTime($o['end_date']);
$daysLeft = $today->diff($endDate)->days;
if ($daysLeft <= 7 && $endDate >= $today) {
$reminders[] = [
'customer' => $o['customer'],
'days_left' => $daysLeft,
'end_date' => $o['end_date']
];
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>IDC服务器租用订单管理系统 - XXIDC</title>
<style>
* { box-sizing: border-box; }
body { font-family: Arial, sans-serif; background: #f0f2f5; margin: 20px; }
.container { max-width: 1100px; margin: auto; }
h1 { color: #1a73e8; border-bottom: 3px solid #1a73e8; padding-bottom: 10px; }
.alert { padding: 12px 20px; border-radius: 5px; margin: 15px 0; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.form-section, .table-section { background: white; border-radius: 8px; padding: 25px; margin: 20px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
label { display: block; margin: 10px 0 5px; font-weight: bold; color: #555; }
input, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; }
.form-row { display: flex; gap: 20px; }
.form-row > div { flex: 1; }
button { background: #1a73e8; color: white; border: none; padding: 12px 30px; border-radius: 5px; cursor: pointer; font-size: 16px; margin-top: 15px; }
button:hover { background: #1557b0; }
table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th { background: #f8f9fa; padding: 12px; text-align: left; border-bottom: 2px solid #dee2e6; }
td { padding: 12px; border-bottom: 1px solid #eee; }
.status-active { color: #28a745; font-weight: bold; }
.status-expired { color: #dc3545; font-weight: bold; }
.btn-sm { padding: 5px 12px; font-size: 13px; margin: 0 3px; }
.btn-danger { background: #dc3545; }
.btn-warning { background: #ffc107; color: #333; }
.reminder-badge { background: #ff9800; color: white; padding: 3px 10px; border-radius: 10px; font-size: 12px; }
.footer { text-align: center; color: #999; margin-top: 30px; font-size: 13px; }
</style>
</head>
<body>
<div>
<h1>📋 IDC服务器租用订单管理系统</h1>
<?php if ($message): ?>
<div class="alert alert-success"><?php echo $message; ?></div>
<?php endif; ?>
<?php if (!empty($reminders)): ?>
<div class="alert alert-warning">
⏰ <strong>到期提醒:</strong>
<?php foreach ($reminders as $r): ?>
<span><?php echo $r['customer']; ?>(还剩 <?php echo $r['days_left']; ?> 天,到期日:<?php echo $r['end_date']; ?>)</span><br>
<?php endforeach; ?>
</div>
<?php endif; ?>
<!-- 添加订单表单 -->
<div>
<h2>➕ 添加新订单</h2>
<form method="POST">
<input type="hidden" name="action" value="add">
<div>
<div>
<label>客户名称</label>
<input type="text" name="customer" required placeholder="例如:张三科技有限公司">
</div>
<div>
<label>服务器配置</label>
<select name="server_spec">
<option value="E5-2680v4 16核 32G 1T SSD">E5-2680v4 16核 32G 1T SSD</option>
<option value="E5-2690v4 20核 64G 2T SSD">E5-2690v4 20核 64G 2T SSD</option>
<option value="Gold 6226R 32核 128G 4T NVMe">Gold 6226R 32核 128G 4T NVMe</option>
<option value="自定义配置">自定义配置</option>
</select>
</div>
</div>
<div>
<div>
<label>带宽</label>
<select name="bandwidth">
<option value="10M独享">10M独享</option>
<option value="20M独享">20M独享</option>
<option value="50M独享">50M独享</option>
<option value="100M独享">100M独享</option>
<option value="100M共享">100M共享</option>
</select>
</div>
<div>
<label>分配IP</label>
<input type="text" name="ip_address" required placeholder="例如:103.xxx.xxx.10">
</div>
</div>
<div>
<div>
<label>开始日期</label>
<input type="date" name="start_date" required>
</div>
<div>
<label>结束日期</label>
<input type="date" name="end_date" required>
</div>
</div>
<button type="submit">📌 添加订单</button>
</form>
</div>
<!-- 订单列表 -->
<div>
<h2>📄 当前订单列表(共 <?php echo count($orders); ?> 条)</h2>
<?php if (empty($orders)): ?>
<p style="color:#999;">暂无订单记录。</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>客户名称</th>
<th>服务器配置</th>
<th>带宽</th>
<th>IP地址</th>
<th>开始日期</th>
<th>结束日期</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $o): ?>
<tr>
<td><?php echo htmlspecialchars($o['customer']); ?></td>
<td><?php echo htmlspecialchars($o['server_spec']); ?></td>
<td><?php echo htmlspecialchars($o['bandwidth']); ?></td>
<td><?php echo htmlspecialchars($o['ip_address']); ?></td>
<td><?php echo $o['start_date']; ?></td>
<td><?php echo $o['end_date']; ?></td>
<td>
<span class="<?php echo $o['status'] === 'active' ? 'status-active' : 'status-expired'; ?>">
<?php echo $o['status'] === 'active' ? '● 运行中' : '● 已过期'; ?>
</span>
</td>
<td>
<form method="POST" style="display:inline;">
<input type="hidden" name="action" value="toggle_status">
<input type="hidden" name="order_id" value="<?php echo $o['id']; ?>">
<button type="submit" class="btn-sm btn-warning">切换状态</button>
</form>
<form method="POST" style="display:inline;" onsubmit="return confirm('确定删除该订单?');">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="order_id" value="<?php echo $o['id']; ?>">
<button type="submit" class="btn-sm btn-danger">删除</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<div>
© 2026 XXIDC 服务器出租 · 后台管理系统 · 数据存储于 orders.json<br>
⚠️ 生产环境建议改用MySQL数据库,并加强登录验证。
</div>
</div>
</body>
</html>
将代码保存为order_manager.php 在同目录下创建空文件orders.json(或让PHP自动创建) 上传到支持PHP的Web服务器 访问该页面即可管理租用订单
