Files
freeshop/order_detail.php
2026-08-14 10:55:06 +08:00

123 lines
6.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// 订单详情(仅本人可见)
require __DIR__ . '/includes/init.php';
requireLogin('order_detail.php?id=' . ($_GET['id'] ?? ''));
$pageTitle = '订单详情';
$user = currentUser();
$id = (int) ($_GET['id'] ?? 0);
$stmt = db()->prepare('SELECT o.*, u.username AS u_name, u.email AS u_email FROM ' . tn('orders') . ' o LEFT JOIN ' . tn('users') . ' u ON u.id = o.user_id WHERE o.id = ? AND o.user_id = ?');
$stmt->execute([$id, $user['id']]);
$order = $stmt->fetch();
if (!$order) {
http_response_code(404);
require 'includes/header.php';
echo '<section class="section"><div class="auth-card" style="text-align:center">'
. '<p class="form-err">订单不存在,或不属于当前账号。</p>'
. '<a href="myorders.php" class="btn btn-primary">返回我的订单</a></div></section>';
require 'includes/footer.php';
exit;
}
$itStmt = db()->prepare('SELECT * FROM ' . tn('order_items') . ' WHERE order_id = ?');
$itStmt->execute([$order['id']]);
$items = $itStmt->fetchAll();
$totalQty = array_sum(array_column($items, 'qty'));
// 发货信息(管理员发货后才有)
$dlvStmt = db()->prepare('SELECT * FROM ' . tn('order_deliveries') . ' WHERE order_id = ? ORDER BY created_at DESC LIMIT 1');
$dlvStmt->execute([$order['id']]);
$delivery = $dlvStmt->fetch();
// 是否可发起续期(周期商品且已发货/已完成)
$canRenew = ($order['period_days'] > 0) && in_array($order['status'], ['shipped', 'completed'], true);
require 'includes/header.php';
?>
<section class="section">
<a href="myorders.php" class="back-link"><i class="fas fa-arrow-left"></i> 返回我的订单</a>
<h2 class="sec-title"><i class="fas fa-receipt"></i> 订单详情</h2>
<div class="order-detail">
<div class="od-head">
<div>
<div class="od-no">订单号:<?= h($order['order_no']) ?></div>
<div class="od-time"><?= date('Y-m-d H:i', strtotime($order['created_at'])) ?></div>
</div>
<span class="badge-status status-<?= h($order['status']) ?>"><?= orderStatusLabel($order['status']) ?></span>
</div>
<div class="od-items">
<div class="od-th"><span>商品</span><span>单价</span><span>数量</span><span>小计</span></div>
<?php foreach ($items as $it): ?>
<div class="od-row">
<span class="od-name"><?= h($it['name']) ?><?= !empty($it['period_days']) ? ' <em class="od-period">· ' . periodLabel($it['period_days']) . '</em>' : '' ?></span>
<span><?= money($it['price']) ?></span>
<span>×<?= (int) $it['qty'] ?></span>
<span class="od-sub"><?= money($it['subtotal']) ?></span>
</div>
<?php endforeach; ?>
</div>
<div class="od-info">
<div class="od-block">
<div class="od-label">订单发起人</div>
<div class="od-line"><?= h($order['u_name'] ?? '未知') ?></div>
<div class="od-line">账号邮箱:<?= h($order['u_email'] ?? '未填写') ?></div>
</div>
<div class="od-block">
<div class="od-label">联系信息</div>
<div class="od-line">联系人:<?= $order['contact'] !== '' ? h($order['contact']) : '—' ?></div>
<div class="od-line">联系邮箱:<?= $order['contact_email'] !== '' ? h($order['contact_email']) : '未填写' ?></div>
<div class="od-line">收货地址:<?= $order['address'] !== '' ? h($order['address']) : '(未填写)' ?></div>
</div>
<div class="od-block">
<div class="od-label">周期 / 到期</div>
<div class="od-line">周期:<?= periodLabel($order['period_days']) ?></div>
<div class="od-line">到期时间:<?= expiryText($order['expires_at']) ?></div>
</div>
<div class="od-block">
<div class="od-label">备注</div>
<div class="od-line"><?= $order['note'] !== '' ? nl2br(h($order['note'])) : '(无)' ?></div>
</div>
<div class="od-block">
<div class="od-label">支付方式</div>
<div class="od-line"><?= payTypeLabel($order['pay_type']) ?><?= $order['pay_type']==='points' ? '(消耗 ' . (int)$order['points_used'] . ' 积分)' : '' ?></div>
</div>
</div>
<?php if ($delivery): ?>
<div class="od-block od-delivery">
<div class="od-label"><i class="fas fa-truck"></i> 发货信息(连接与登录凭据 / 商品信息)</div>
<div class="od-line">激活状态:<span class="badge-<?= !empty($delivery['activated']) ? 'on' : 'off' ?>"><?= !empty($delivery['activated']) ? '已激活' : '未激活' ?></span></div>
<div class="od-line">服务器 IP<?= h($delivery['server_ip']) ?: '—' ?></div>
<div class="od-line">连接地址:<?= h($delivery['conn_addr']) ?: '—' ?></div>
<div class="od-line">登录账户:<?= h($delivery['login_user']) ?: '—' ?></div>
<div class="od-line">
登录密码:
<span class="secret" data-secret="<?= h($delivery['login_pass']) ?>"><?= $delivery['login_pass'] !== '' ? str_repeat('●', max(6, mb_strlen($delivery['login_pass']))) : '—' ?></span>
<?php if ($delivery['login_pass'] !== ''): ?><button type="button" class="mini-btn reveal-btn" data-reveal>显示</button><?php endif; ?>
</div>
<?php if ($delivery['product_info'] !== ''): ?>
<div class="od-line od-info-block">商品信息:<?= nl2br(h($delivery['product_info'])) ?></div>
<?php endif; ?>
<?php if ($delivery['remark'] !== ''): ?>
<div class="od-line">备注:<?= nl2br(h($delivery['remark'])) ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="od-foot">
<span class="muted">共 <?= (int) $totalQty ?> 件</span>
<span class="od-total">合计:<strong><?= money($order['total']) ?></strong></span>
</div>
<?php if ($canRenew): ?>
<div class="od-renew">
<a href="ticket.php?order_id=<?= (int) $order['id'] ?>" class="btn btn-ghost"><i class="fas fa-rotate"></i> 申请续期</a>
<span class="muted">本订单为周期商品,可在到期后通过工单申请续期。</span>
</div>
<?php endif; ?>
</div>
</section>
<?php require 'includes/footer.php'; ?>