From 809802e655a02351cb1e723ecce84b4237d1961d Mon Sep 17 00:00:00 2001 From: Mars Date: Mon, 7 Jul 2025 10:42:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1datetime=E9=94=99=E8=AF=AF=E5=92=8CPENDING?= =?UTF-8?q?=E6=9C=9F=E5=8F=B7=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/scheduler.py | 4 ++-- backend/update_lottery.py | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/scheduler.py b/backend/scheduler.py index ab2a52b..0b75ba7 100644 --- a/backend/scheduler.py +++ b/backend/scheduler.py @@ -63,7 +63,7 @@ class LotteryScheduler: db = SessionLocal() try: # 判断彩种 - weekday = datetime.datetime.now().isoweekday() + weekday = datetime.now().isoweekday() if weekday == 5: logger.info("周五休息,不推送推荐") return @@ -80,7 +80,7 @@ class LotteryScheduler: title = "你好,帮忙买下双色球。" dlt_append = False # 生成batch_id - today = datetime.datetime.now().strftime('%Y%m%d') + today = datetime.now().strftime('%Y%m%d') batch_id = f"{today}-{random.randint(1000, 9999)}" # 推荐4注(集成预测+智能选号补足) service = PredictionService(db) diff --git a/backend/update_lottery.py b/backend/update_lottery.py index c0ed6da..6e77507 100644 --- a/backend/update_lottery.py +++ b/backend/update_lottery.py @@ -258,7 +258,7 @@ class LotteryUpdater: def update_bet_issues_by_date(self, lottery_type: str): """ 根据投注日期更新期号 - 查找相同日期的投注记录,将期号设置为当天开奖的期号 + 查找投注记录,将期号设置为投注日期之后最近的开奖期号 """ try: db = self.SessionLocal() @@ -280,16 +280,29 @@ class LotteryUpdater: # 获取投注日期 bet_date = bet.bet_time.date() - # 查找相同日期的开奖记录 + # 查找投注日期之后最近的开奖记录 + # 先尝试找投注当天的开奖 draw = db.query(LotteryModel).filter( LotteryModel.open_time == bet_date).first() + # 如果投注当天没有开奖,找投注日期之后最近的开奖 + if not draw: + draw = db.query(LotteryModel).filter( + LotteryModel.open_time > bet_date + ).order_by(LotteryModel.open_time.asc()).first() + + # 如果还是没找到,找投注日期之前最近的开奖(兜底逻辑) + if not draw: + draw = db.query(LotteryModel).filter( + LotteryModel.open_time <= bet_date + ).order_by(LotteryModel.open_time.desc()).first() + if draw: # 更新投注记录的期号 old_issue = bet.issue bet.issue = draw.issue logger.debug( - f"更新投注记录 ID {bet.id}: 期号 {old_issue} -> {draw.issue} (日期匹配: {bet_date})") + f"更新投注记录 ID {bet.id}: 期号 {old_issue} -> {draw.issue} (投注日期: {bet_date}, 开奖日期: {draw.open_time})") else: logger.debug( f"投注记录 ID {bet.id} 的日期 {bet_date} 暂无开奖数据,期号保持 PENDING")