修复抽成利润统计在 USE_TZ=False 下的 MySQL 时区报错。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-16 19:54:13 +08:00
parent fc93f1c8fc
commit 83ccdff0f5

View File

@@ -12,6 +12,7 @@ import logging
from datetime import datetime, time
from decimal import Decimal
from django.conf import settings
from django.db.models import (
Count, DecimalField, F, Q, Sum, Value,
)
@@ -59,10 +60,10 @@ def _parse_date(s):
def _day_bounds(d):
"""本地日历日 → aware datetime 区间 [start, end)"""
"""日历日 → datetime 区间 [start, end];兼容 USE_TZ=FalseMySQL 禁止 aware datetime"""
start = datetime.combine(d, time.min)
end = datetime.combine(d, time.max)
if timezone.is_naive(start):
end = datetime.combine(d, time(23, 59, 59, 999999))
if getattr(settings, 'USE_TZ', False):
tz = timezone.get_current_timezone()
start = timezone.make_aware(start, tz)
end = timezone.make_aware(end, tz)