From 83ccdff0f550a0c0f176faacaf904332841797dd Mon Sep 17 00:00:00 2001 From: XingQue Date: Thu, 16 Jul 2026 19:54:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=BD=E6=88=90=E5=88=A9?= =?UTF-8?q?=E6=B6=A6=E7=BB=9F=E8=AE=A1=E5=9C=A8=20USE=5FTZ=3DFalse=20?= =?UTF-8?q?=E4=B8=8B=E7=9A=84=20MySQL=20=E6=97=B6=E5=8C=BA=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- houtai/tixian_profit_views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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)