feat: 新增用户端个人中心

This commit is contained in:
2026-08-03 12:38:00 +08:00
parent 7747334ea4
commit 20ed4875b8
10 changed files with 355 additions and 176 deletions

View File

@@ -20,6 +20,8 @@ class EntitlementView:
plan_id: int | None
name: str
plan_type: str
description: str | None
validity_days: int | None
monthly_topic_limit: int | None
monthly_topic_used: int
enable_growth_profile: bool
@@ -96,6 +98,8 @@ class EntitlementService:
plan_id=None,
name="旧版每日额度",
plan_type="legacy",
description="按每日问答额度提供基础服务。",
validity_days=None,
monthly_topic_limit=None,
monthly_topic_used=monthly_topic_used,
enable_growth_profile=False,
@@ -200,6 +204,8 @@ def entitlement_dict(view: EntitlementView) -> dict:
"planId": view.plan_id,
"name": view.name,
"planType": view.plan_type,
"description": view.description,
"validityDays": view.validity_days,
"monthlyTopicLimit": view.monthly_topic_limit,
"monthlyTopicUsed": view.monthly_topic_used,
"monthlyTopicRemaining": view.monthly_topic_remaining,
@@ -238,6 +244,8 @@ def view_from_plan(
plan_id=plan.id,
name=plan.name,
plan_type=plan.plan_type,
description=plan.description,
validity_days=plan.validity_days,
monthly_topic_limit=plan.monthly_topic_limit,
monthly_topic_used=monthly_topic_used,
enable_growth_profile=bool(plan.enable_growth_profile),

View File

@@ -13,7 +13,7 @@ from app.models.chat import ChatMessage, ChatSession, TopicSession
from app.models.entitlement import EntitlementPlan
from app.models.user import User
from app.services.chat_service import ChatService
from app.services.entitlement_service import EntitlementService
from app.services.entitlement_service import EntitlementService, entitlement_dict
from app.services.rag_service import RagResult, RagService
from app.services.topic_session_service import TopicSessionService
@@ -44,6 +44,8 @@ def test_default_entitlement_uses_basic_plan_when_user_has_no_assignment():
id=10,
name="大本营基础版",
plan_type="basic",
description="基础知识问答权益",
validity_days=180,
monthly_topic_limit=30,
status=1,
sort_order=10,
@@ -55,8 +57,12 @@ def test_default_entitlement_uses_basic_plan_when_user_has_no_assignment():
assert view.plan_id == 10
assert view.name == "大本营基础版"
assert view.description == "基础知识问答权益"
assert view.validity_days == 180
assert view.source == "default"
assert view.monthly_topic_remaining == 27
assert entitlement_dict(view)["description"] == "基础知识问答权益"
assert entitlement_dict(view)["validityDays"] == 180
def test_legacy_teacher_plan_is_not_exposed_or_used_as_default():