diff --git a/houtai/tixian_profit_views.py b/houtai/tixian_profit_views.py index 5dc634a..932cd3c 100644 --- a/houtai/tixian_profit_views.py +++ b/houtai/tixian_profit_views.py @@ -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=False(MySQL 禁止 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)