diff --git a/app/api/v1/coupon.py b/app/api/v1/coupon.py index 4de69eb..9051f92 100644 --- a/app/api/v1/coupon.py +++ b/app/api/v1/coupon.py @@ -183,7 +183,15 @@ def coupon_prompt_should_show( device_id: str, db: DbSession ) -> CouponPromptShouldShowOut: """今天这台设备已 engage(领或拒)过 → should_show=false。客户端据此决定弹不弹 - (前台 SP 缓存做快速路径,这里是权威)。""" + (纯后台判据,客户端不再做前台 SP 缓存判断)。""" return CouponPromptShouldShowOut( should_show=not coupon_repo.has_engaged_today(db, device_id) ) + + +@router.post("/prompt/reset", summary="重置今日领券引导窗 engagement(开发测频控用)") +def coupon_prompt_reset(payload: CouponPromptDismissIn, db: DbSession) -> dict[str, bool]: + """删这台设备今天的 engagement → has_engaged_today 变 false,今天又能弹。 + 开发设置「重置今日领券弹窗状态」按钮调。MVP 不鉴权,按 device_id。""" + coupon_repo.reset_today_engagement(db, payload.device_id) + return {"ok": True} diff --git a/app/repositories/coupon_state.py b/app/repositories/coupon_state.py index d36be0a..e255e9f 100644 --- a/app/repositories/coupon_state.py +++ b/app/repositories/coupon_state.py @@ -9,7 +9,7 @@ import logging from datetime import date, datetime from zoneinfo import ZoneInfo -from sqlalchemy import select +from sqlalchemy import delete, select from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Session @@ -65,6 +65,19 @@ def mark_engagement( db.rollback() +def reset_today_engagement(db: Session, device_id: str) -> int: + """删这台设备今天的 engagement(开发设置「重置今日领券弹窗状态」调,测频控用)。 + 删后 has_engaged_today → false,今天又能弹。返回删除行数。""" + result = db.execute( + delete(CouponPromptEngagement).where( + CouponPromptEngagement.device_id == device_id, + CouponPromptEngagement.engage_date == today_cn(), + ) + ) + db.commit() + return result.rowcount or 0 + + # ===== 领券记录(coupon_claim_record)===== def record_claims(