From b0662f6feff0c6db33bfb47489203ad9d76d7054 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Wed, 20 May 2026 20:52:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E9=80=9A=20Pro=20=E6=97=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=90=8C=E6=97=B6=E6=89=A3=E9=99=A4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/routers/ops.py | 3 ++- web/services/ops_api.py | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/web/routers/ops.py b/web/routers/ops.py index b5ade5a1..dfc74f42 100644 --- a/web/routers/ops.py +++ b/web/routers/ops.py @@ -142,7 +142,8 @@ async def ops_subscription_grant(request: Request): email = str(body.get("email") or "").strip() plan_code = str(body.get("plan_code") or "pro_monthly").strip() days = int(body.get("days") or 30) - return grant_ops_subscription(request, email=email, plan_code=plan_code, days=days) + deduct_points = int(body.get("deduct_points") or 0) + return grant_ops_subscription(request, email=email, plan_code=plan_code, days=days, deduct_points=deduct_points) @router.post("/api/ops/subscriptions/extend") diff --git a/web/services/ops_api.py b/web/services/ops_api.py index a214919e..5f99cfa5 100644 --- a/web/services/ops_api.py +++ b/web/services/ops_api.py @@ -384,6 +384,7 @@ def grant_ops_subscription( email: str, plan_code: str = "pro_monthly", days: int = 30, + deduct_points: int = 0, ) -> dict[str, Any]: _require_ops(request) import os @@ -400,6 +401,7 @@ def grant_ops_subscription( raise HTTPException(status_code=400, detail=f"invalid plan_code, allowed: {allowed_plans}") safe_days = max(1, min(365, int(days or 30))) + safe_deduct = max(0, int(deduct_points or 0)) normalized_email = str(email or "").strip().lower() if not normalized_email: raise HTTPException(status_code=400, detail="email is required") @@ -443,9 +445,22 @@ def grant_ops_subscription( json=payload, timeout=10, ) - if resp.ok: - return {"ok": True, "user_id": user_id, "plan_code": plan_code, "days": safe_days, "expires_at": expires_at} - raise HTTPException(status_code=500, detail=f"Supabase insert failed: {resp.text[:200]}") + if not resp.ok: + raise HTTPException(status_code=500, detail=f"Supabase insert failed: {resp.text[:200]}") + + result: dict[str, Any] = { + "ok": True, "user_id": user_id, "plan_code": plan_code, + "days": safe_days, "expires_at": expires_at, + } + + # Optionally deduct points from the user (manual Pro grant with points payment) + if safe_deduct > 0: + db = DBManager() + deduct_result = db.deduct_points_by_supabase_email(normalized_email, safe_deduct) + result["points_deducted"] = safe_deduct + result["points_result"] = deduct_result + + return result def extend_ops_subscription(