<?php
require_once __DIR__ . '/../includes/bootstrap.php';

$userId = current_user_id();
$stmt = db()->prepare('SELECT * FROM orders WHERE user_id = ? AND is_virtual = 0 ORDER BY id DESC LIMIT 50');
$stmt->execute([$userId]);
$list = $stmt->fetchAll();
?>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>我的订单</title>
<link rel="stylesheet" href="../assets/style.css">
<style>
*{margin:0;padding:0;box-sizing:border-box;font-family:system-ui,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif;}
body{background:#ffffff;color:#1a1a2e;}
.box{max-width:480px;margin:0 auto;padding:24px 16px;}
.box h2{color:#1a1a2e;}
.card2{background:#f7f8fc;border:1px solid #e8e8ef;border-radius:12px;padding:20px;margin-bottom:12px;color:#1a1a2e;}
.card2 .meta{color:#666 !important;}
.card2 .muted{color:#999;}
.badge{display:inline-block;padding:2px 8px;border-radius:10px;font-size:11px;}
.badge-on{background:rgba(82,196,26,.15);color:#16a34a;}
.badge-off{background:rgba(255,91,138,.18);color:#d23b7a;}
a.btn{display:inline-block;padding:10px 18px;background:#ff2c55;color:#fff;text-decoration:none;border-radius:8px;margin:6px 8px 0 0;font-size:14px;}
a.btn.gray{background:#e0e0e0;color:#333;}
</style>
</head>
<body>
<div class="box">
    <h2 style="margin-bottom:14px">我的订单</h2>
    <?php if (!$list): ?>
        <div class="card2" style="text-align:center;color:#888">暂无订单</div>
    <?php else: foreach ($list as $o):
        $badge = $o['status']==1 ? '<span class="badge badge-on">已支付</span>' : '<span class="badge badge-off">待支付</span>';
    ?>
        <div class="card2">
            <div style="display:flex;justify-content:space-between;align-items:center">
                <b><?= e($o['plan_name']) ?></b>
                <?= $badge ?>
            </div>
            <div style="color:#666;font-size:12px;margin:6px 0">订单号：<?= e($o['out_trade_no']) ?></div>
            <div style="display:flex;justify-content:space-between;align-items:center">
                <span style="color:#fe2c55;font-size:18px;font-weight:700">¥<?= fmt_money((float)$o['money']) ?></span>
                <span style="color:#999;font-size:12px"><?= fmt_time((int)$o['created_at']) ?></span>
            </div>
        </div>
    <?php endforeach; endif; ?>
    <a class="btn" href="../index.php">返回首页</a>
    <a class="btn" href="login.php">用户中心</a>
</div>
</body>
</html>
