feat: Introduce a new page for purchasing points and viewing recharge history, supported by model updates and a new logging service.
This commit is contained in:
parent
771498db38
commit
1aa3cb4151
17
models.py
17
models.py
@ -1,12 +1,23 @@
|
||||
from extensions import db
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
# 定义时区常量
|
||||
UTC_TZ = timezone.utc
|
||||
BEIJING_TZ = timezone(timedelta(hours=8))
|
||||
|
||||
def to_bj_time(dt):
|
||||
"""将 UTC 时间转换为北京时间 (UTC+8)"""
|
||||
"""将 UTC 时间转换为北京时间 (UTC+8)
|
||||
|
||||
无论系统时区设置如何,都能正确转换为北京时间
|
||||
"""
|
||||
if not dt:
|
||||
return None
|
||||
return dt + timedelta(hours=8)
|
||||
# 如果 dt 没有时区信息,假设它是 UTC 时间
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=UTC_TZ)
|
||||
# 转换为北京时间
|
||||
return dt.astimezone(BEIJING_TZ).replace(tzinfo=None)
|
||||
|
||||
|
||||
# 角色与权限的多对多关联表
|
||||
|
||||
@ -58,8 +58,8 @@ class SystemLogger:
|
||||
def _push_to_redis(self, level, message, extra=None):
|
||||
"""推送到 Redis 并保留 30 天数据"""
|
||||
try:
|
||||
now = datetime.utcnow()
|
||||
bj_now = now + timedelta(hours=8)
|
||||
now = datetime.now(timezone.utc)
|
||||
bj_now = now.astimezone(BEIJING_TZ)
|
||||
user_id = None
|
||||
if has_request_context():
|
||||
user_id = g.get('user_id') or (getattr(g, 'user', None).id if hasattr(g, 'user') and g.user else None)
|
||||
@ -92,7 +92,7 @@ class SystemLogger:
|
||||
'module': module,
|
||||
'user_id': extra.get('user_id') if extra else None,
|
||||
'extra': json.dumps(extra, ensure_ascii=False) if extra else None,
|
||||
'created_at': datetime.utcnow()
|
||||
'created_at': datetime.now(timezone.utc).replace(tzinfo=None) # 存储 UTC 时间(无时区信息)
|
||||
}
|
||||
|
||||
# 捕获请求上下文信息
|
||||
|
||||
@ -200,9 +200,8 @@
|
||||
</td>
|
||||
<td class="px-8 py-5">
|
||||
<span class="text-[10px] font-bold text-slate-400">
|
||||
{% if order.paid_at %}
|
||||
{{ (order.paid_at + modules.datetime.timedelta(hours=8)).strftime('%m-%d %H:%M')
|
||||
}}
|
||||
{% if order.paid_at_bj %}
|
||||
{{ order.paid_at_bj.strftime('%m-%d %H:%M') }}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
|
||||
@ -77,9 +77,8 @@
|
||||
</td>
|
||||
<td class="px-8 py-5">
|
||||
<span class="text-xs font-bold text-slate-400">
|
||||
{% if order.paid_at %}
|
||||
{{ (order.paid_at + modules.datetime.timedelta(hours=8)).strftime('%Y-%m-%d %H:%M')
|
||||
}}
|
||||
{% if order.paid_at_bj %}
|
||||
{{ order.paid_at_bj.strftime('%Y-%m-%d %H:%M') }}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user