fix: 今日订单查询改用 naive 时间(USE_TZ=False)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6b028738f1
commit
e79da5f097
1 file changed
+15
-7
@@ -5,7 +5,6 @@ import logging
|
||||
import random
|
||||
from datetime import datetime, time, timedelta
|
||||
from decimal import Decimal
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.models import Count, Q
|
||||
@@ -15,17 +14,23 @@ from orders.models import Order, TodayOrderFake, TodayOrderFakeBatchState, Today
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TZ = ZoneInfo('Asia/Shanghai')
|
||||
|
||||
# 进行中:已下单/待抢、进行中、指定中
|
||||
DOING_STATUSES = {1, 2, 7}
|
||||
# 不计入当日有效单:未支付、支付失败、已废弃
|
||||
EXCLUDE_STATUSES = {9, 14, 25}
|
||||
|
||||
|
||||
def _now_naive():
|
||||
"""项目 USE_TZ=False,MySQL 只接受 naive datetime。"""
|
||||
now = timezone.now()
|
||||
if timezone.is_aware(now):
|
||||
return timezone.make_naive(now)
|
||||
return now
|
||||
|
||||
|
||||
def _today_range():
|
||||
now = timezone.now().astimezone(TZ)
|
||||
start = datetime.combine(now.date(), time.min, tzinfo=TZ)
|
||||
now = _now_naive()
|
||||
start = datetime.combine(now.date(), time.min)
|
||||
end = start + timedelta(days=1)
|
||||
return start, end
|
||||
|
||||
@@ -119,12 +124,15 @@ def _pick_fake_batch(club_id: str, cfg: TodayOrderShowConfig) -> list[TodayOrder
|
||||
return []
|
||||
batch_n = min(int(cfg.batch_size), len(pool))
|
||||
interval = max(10, int(cfg.interval_seconds or 120))
|
||||
now = timezone.now()
|
||||
now = _now_naive()
|
||||
state = TodayOrderFakeBatchState.query.filter(club_id=club_id).first()
|
||||
need_reshuffle = True
|
||||
ids = []
|
||||
if state and state.last_shuffle_at and isinstance(state.fake_ids, list):
|
||||
elapsed = (now - state.last_shuffle_at).total_seconds()
|
||||
last = state.last_shuffle_at
|
||||
if timezone.is_aware(last):
|
||||
last = timezone.make_naive(last)
|
||||
elapsed = (now - last).total_seconds()
|
||||
if elapsed < interval and state.fake_ids:
|
||||
ids = [int(x) for x in state.fake_ids if str(x).isdigit() or isinstance(x, int)]
|
||||
need_reshuffle = False
|
||||
|
||||
Reference in new issue
Block a user