nomadro/apps/api/services/ebook_svc/routers/vip_admin.py
Eric 9779b80d25 Ship WeChat admin UX overhaul and VIP content library.
Restructure /wechat nav (VIP submenu for ebooks/course/shop/memo), rebuild ops pages with shared wx UI, and wire vip-library remote content end-to-end with README paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 09:59:57 +08:00

52 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""微信 VIP 运营配置 API — admin.nomadro.cn/wechat/vip。"""
from __future__ import annotations
from typing import Any, Literal
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field
from ebook_svc.core.security import require_admin
from ebook_svc.services.vip_config import apply_vip_offer_key, read_vip_config, write_vip_config
router = APIRouter(prefix="/api/admin/vip", tags=["vip-admin"])
class VipBody(BaseModel):
vipEnabled: bool | None = None
gameEnabled: bool | None = None
joinGroupAction: Literal["popup", "vip"] | None = None
vipPriceFen: int | None = Field(default=None, ge=0)
vipProductId: str | None = None
vipCta: str | None = None
vipOfferKey: str | None = None
# 微信落地页运营配置 → platforms.weapp.vipContent(可选增量)
vipContent: dict[str, Any] | None = None
class VipOfferBody(BaseModel):
offer_key: str = Field(..., min_length=1)
@router.get("")
async def get_vip(_: str = Depends(require_admin)) -> dict[str, Any]:
return {"ok": True, **read_vip_config()}
@router.put("")
async def put_vip(body: VipBody, _: str = Depends(require_admin)) -> dict[str, Any]:
patch = body.model_dump(exclude_none=True)
saved = write_vip_config(patch)
return {"ok": True, **saved}
@router.post("/offer")
async def apply_vip_offer(body: VipOfferBody, _: str = Depends(require_admin)) -> dict[str, Any]:
"""一键切换免费 / 已发布道具(对齐小册 POST /books/{id}/offer)。"""
try:
apply_vip_offer_key(body.offer_key)
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e)) from e
saved = write_vip_config({"vipOfferKey": body.offer_key})
return {"ok": True, **saved}