feat: add portal account records

This commit is contained in:
QiuSW
2026-07-03 14:00:00 +08:00
parent 35f4c9c494
commit 4a10c2bb92
18 changed files with 653 additions and 27 deletions
+3 -1
View File
@@ -80,10 +80,12 @@
<nav class="navbar navbar-expand">
<div class="container">
<a class="navbar-brand fw-semibold" href="{% url 'portal-home' %}">cmhub</a>
<div class="ms-auto d-flex gap-2">
<div class="ms-auto d-flex gap-2 flex-wrap justify-content-end">
{% if user.is_authenticated %}
<a class="btn btn-sm btn-outline-secondary" href="{% url 'portal-dashboard' %}">控制台</a>
<a class="btn btn-sm btn-outline-secondary" href="{% url 'portal-apikeys' %}">API Key</a>
<a class="btn btn-sm btn-outline-secondary" href="{% url 'portal-recharge-records' %}">充值记录</a>
<a class="btn btn-sm btn-outline-secondary" href="{% url 'portal-usage-records' %}">消费记录</a>
<form method="post" action="{% url 'portal-logout' %}">
{% csrf_token %}
<button class="btn btn-sm btn-outline-secondary" type="submit">退出</button>
+115 -1
View File
@@ -8,13 +8,39 @@
<h1 class="h3 mb-1">控制台</h1>
<div class="text-secondary">{{ user.email }}</div>
</div>
{% if balance.points_balance != balance.ledger_balance %}
<div class="alert alert-warning mb-0">
钱包余额与点数流水余额不一致,请联系运营核对。
</div>
{% endif %}
<div class="row g-3">
<div class="col-md-4">
<div class="col-md-3">
<div class="metric">
<div class="text-secondary small">剩余点数</div>
<div class="display-6 fw-semibold">{{ balance.points_balance }}</div>
</div>
</div>
<div class="col-md-3">
<div class="metric">
<div class="text-secondary small">充值总额</div>
<div class="display-6 fw-semibold">{{ recharge_total_amount|floatformat:2 }}</div>
</div>
</div>
<div class="col-md-3">
<div class="metric">
<div class="text-secondary small">入账点数</div>
<div class="display-6 fw-semibold">{{ recharge_points_total }}</div>
</div>
</div>
<div class="col-md-3">
<div class="metric">
<div class="text-secondary small">净消耗点数</div>
<div class="display-6 fw-semibold">{{ net_used_points }}</div>
</div>
</div>
</div>
<div class="row g-3">
<div class="col-md-4">
<div class="metric d-flex flex-column gap-3">
<div>
@@ -24,6 +50,94 @@
<a class="btn btn-primary align-self-start" href="{% url 'portal-apikeys' %}">管理</a>
</div>
</div>
<div class="col-md-4">
<div class="metric d-flex flex-column gap-3">
<div>
<div class="text-secondary small">充值</div>
<div class="h5 mb-0">充值记录</div>
</div>
<a class="btn btn-primary align-self-start" href="{% url 'portal-recharge-records' %}">查看</a>
</div>
</div>
<div class="col-md-4">
<div class="metric d-flex flex-column gap-3">
<div>
<div class="text-secondary small">点数使用</div>
<div class="h5 mb-0">消费记录</div>
</div>
<a class="btn btn-primary align-self-start" href="{% url 'portal-usage-records' %}">查看</a>
</div>
</div>
</div>
<section class="cmhub-surface">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="h5 mb-0">最近充值</h2>
<a class="btn btn-sm btn-outline-secondary" href="{% url 'portal-recharge-records' %}">全部</a>
</div>
{% if recent_recharge_orders %}
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead>
<tr>
<th scope="col">订单号</th>
<th scope="col">金额</th>
<th scope="col">点数</th>
<th scope="col">状态</th>
<th scope="col">创建时间</th>
</tr>
</thead>
<tbody>
{% for order in recent_recharge_orders %}
<tr>
<td><code>{{ order.order_no }}</code></td>
<td>{{ order.amount_money|floatformat:2 }} {{ order.currency }}</td>
<td>{{ order.points_granted }}</td>
<td>{{ order.status }}</td>
<td>{{ order.created_at|date:"Y-m-d H:i" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-secondary">暂无充值记录</div>
{% endif %}
</section>
<section class="cmhub-surface">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="h5 mb-0">最近消费</h2>
<a class="btn btn-sm btn-outline-secondary" href="{% url 'portal-usage-records' %}">全部</a>
</div>
{% if recent_usage_entries %}
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead>
<tr>
<th scope="col">时间</th>
<th scope="col">类型</th>
<th scope="col">能力</th>
<th scope="col">点数变动</th>
<th scope="col">余额</th>
</tr>
</thead>
<tbody>
{% for entry in recent_usage_entries %}
<tr>
<td>{{ entry.created_at|date:"Y-m-d H:i" }}</td>
<td>{{ entry.change_type }}</td>
<td>{{ entry.ref_call.alias|default:"-" }}</td>
<td>{{ entry.points_delta }}</td>
<td>{{ entry.balance_after }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-secondary">暂无消费记录</div>
{% endif %}
</section>
</div>
{% endblock %}
@@ -0,0 +1,71 @@
{% extends "portal/base.html" %}
{% block title %}充值记录 - cmhub{% endblock %}
{% block content %}
<div class="d-flex flex-column gap-4">
<div>
<h1 class="h3 mb-1">充值记录</h1>
<div class="text-secondary">{{ user.email }}</div>
</div>
<div class="row g-3">
<div class="col-md-4">
<div class="metric">
<div class="text-secondary small">充值总额</div>
<div class="display-6 fw-semibold">{{ recharge_total_amount|floatformat:2 }}</div>
</div>
</div>
<div class="col-md-4">
<div class="metric">
<div class="text-secondary small">入账点数</div>
<div class="display-6 fw-semibold">{{ recharge_points_total }}</div>
</div>
</div>
<div class="col-md-4">
<div class="metric">
<div class="text-secondary small">已支付订单</div>
<div class="display-6 fw-semibold">{{ paid_recharge_count }}</div>
</div>
</div>
</div>
<section class="cmhub-surface">
<h2 class="h5 mb-3">订单列表</h2>
{% if recharge_orders %}
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead>
<tr>
<th scope="col">订单号</th>
<th scope="col">金额</th>
<th scope="col">支付方式</th>
<th scope="col">点数</th>
<th scope="col">状态</th>
<th scope="col">支付流水</th>
<th scope="col">创建时间</th>
<th scope="col">到账时间</th>
</tr>
</thead>
<tbody>
{% for order in recharge_orders %}
<tr>
<td><code>{{ order.order_no }}</code></td>
<td>{{ order.amount_money|floatformat:2 }} {{ order.currency }}</td>
<td>{{ order.pay_method }}</td>
<td>{{ order.points_granted }}</td>
<td>{{ order.status }}</td>
<td>{{ order.payment_txn_no|default:"-" }}</td>
<td>{{ order.created_at|date:"Y-m-d H:i" }}</td>
<td>{{ order.paid_at|date:"Y-m-d H:i"|default:"-" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-secondary">暂无充值记录</div>
{% endif %}
</section>
</div>
{% endblock %}
@@ -0,0 +1,95 @@
{% extends "portal/base.html" %}
{% block title %}消费记录 - cmhub{% endblock %}
{% block content %}
<div class="d-flex flex-column gap-4">
<div>
<h1 class="h3 mb-1">消费记录</h1>
<div class="text-secondary">{{ user.email }}</div>
</div>
<div class="row g-3">
<div class="col-md-4">
<div class="metric">
<div class="text-secondary small">累计扣点</div>
<div class="display-6 fw-semibold">{{ consumed_points_total }}</div>
</div>
</div>
<div class="col-md-4">
<div class="metric">
<div class="text-secondary small">失败退点</div>
<div class="display-6 fw-semibold">{{ refunded_points_total }}</div>
</div>
</div>
<div class="col-md-4">
<div class="metric">
<div class="text-secondary small">净消耗点数</div>
<div class="display-6 fw-semibold">{{ net_used_points }}</div>
</div>
</div>
</div>
<section class="cmhub-surface">
<h2 class="h5 mb-3">点数使用流水</h2>
{% if usage_entries %}
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead>
<tr>
<th scope="col">时间</th>
<th scope="col">类型</th>
<th scope="col">操作</th>
<th scope="col">能力别名</th>
<th scope="col">状态</th>
<th scope="col">API Key</th>
<th scope="col">点数变动</th>
<th scope="col">余额</th>
</tr>
</thead>
<tbody>
{% for entry in usage_entries %}
<tr>
<td>{{ entry.created_at|date:"Y-m-d H:i" }}</td>
<td>{{ entry.change_type }}</td>
<td>
{% if entry.ref_call %}
{{ entry.ref_call.operation_type }}
{% else %}
-
{% endif %}
</td>
<td>
{% if entry.ref_call %}
{{ entry.ref_call.alias|default:"-" }}
{% else %}
-
{% endif %}
</td>
<td>
{% if entry.ref_call %}
{{ entry.ref_call.status }}
{% else %}
-
{% endif %}
</td>
<td>
{% if entry.ref_call and entry.ref_call.api_key %}
<code>{{ entry.ref_call.api_key.key_prefix }}</code>
{% else %}
-
{% endif %}
</td>
<td>{{ entry.points_delta }}</td>
<td>{{ entry.balance_after }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-secondary">暂无消费记录</div>
{% endif %}
</section>
</div>
{% endblock %}