配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
"""套餐目录:单一事实来源,供 plan service 与 quota 共用(避免 plan↔quota 循环依赖)。"""
|
|
|
|
from app.core.config import settings
|
|
from app.features.plan.schemas import PlanResponse
|
|
|
|
ENABLE_TEST_PLAN = settings.enable_test_plan
|
|
|
|
AVAILABLE_PLANS = [
|
|
PlanResponse(
|
|
id="free",
|
|
name="free",
|
|
display_name="免费体验版",
|
|
price=0.0,
|
|
currency="CNY",
|
|
features=["500 轮对话", "1 个章节整理", "完整回忆录生成流程"],
|
|
max_conversations=500,
|
|
max_chapters=1,
|
|
is_popular=False,
|
|
),
|
|
PlanResponse(
|
|
id="pro",
|
|
name="pro",
|
|
display_name="Pro 版",
|
|
price=88.0,
|
|
currency="CNY",
|
|
features=["2000 轮对话", "无章节限制", "完整回忆录生成"],
|
|
max_conversations=2000,
|
|
is_popular=True,
|
|
),
|
|
PlanResponse(
|
|
id="pro_plus",
|
|
name="pro_plus",
|
|
display_name="Pro+ 版",
|
|
price=288.0,
|
|
currency="CNY",
|
|
features=["10000 轮对话", "无章节限制", "完整回忆录生成", "长期创作无忧"],
|
|
max_conversations=10000,
|
|
is_popular=False,
|
|
),
|
|
]
|
|
|
|
TEST_PLAN = PlanResponse(
|
|
id="test",
|
|
name="test",
|
|
display_name="一分钱测试版",
|
|
price=0.01,
|
|
currency="CNY",
|
|
features=["无限对话", "无限章节整理", "仅用于开发环境测试支付"],
|
|
is_popular=False,
|
|
)
|
|
|
|
|
|
def get_plans_for_api() -> list[PlanResponse]:
|
|
if ENABLE_TEST_PLAN:
|
|
return AVAILABLE_PLANS + [TEST_PLAN]
|
|
return list(AVAILABLE_PLANS)
|
|
|
|
|
|
def get_plan_by_type(subscription_type: str) -> PlanResponse:
|
|
if subscription_type == "premium":
|
|
subscription_type = "pro"
|
|
if subscription_type == "test":
|
|
return TEST_PLAN if ENABLE_TEST_PLAN else AVAILABLE_PLANS[0]
|
|
for plan in AVAILABLE_PLANS:
|
|
if plan.id == subscription_type:
|
|
return plan
|
|
return AVAILABLE_PLANS[0]
|