From ee5e6729016713aa9a10bdf570f0dea9ba0b3348 Mon Sep 17 00:00:00 2001 From: coder Date: Tue, 14 Apr 2026 18:39:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20pricing=E9=A1=B5=E9=9D=A2=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E4=BC=9A=E5=91=98=E5=A5=97=E9=A4=90=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从数据库MembershipPlanConfig读取动态配置 - 支持推荐标记、原价显示 - 按用户状态显示按钮 --- app.py | 35 ++++++++++++++++- templates/pricing.html | 86 ++++++++++-------------------------------- 2 files changed, 52 insertions(+), 69 deletions(-) diff --git a/app.py b/app.py index 85c4c25..89d50d0 100644 --- a/app.py +++ b/app.py @@ -15,7 +15,7 @@ from werkzeug.utils import secure_filename from config import * from models import (db, User, Translation, TranslationCache, GuestTranslation, DataPackage, UserPackage, DynamicConfig, UserRecharge, UserRefund, - MembershipPurchase, AccountTransaction) + MembershipPurchase, AccountTransaction, MembershipPlanConfig, UserTypeConfig) from services import TranslationService, CacheService, TranslationTask from admin import admin_bp @@ -208,7 +208,38 @@ def history(): def pricing(): """会员定价页""" user = get_current_user() - return render_template('pricing.html', plans=MEMBERSHIP_PLANS, user=user) + + # 从数据库读取动态配置的会员套餐 + db_plans = MembershipPlanConfig.query.filter_by(is_active=True)\ + .order_by(MembershipPlanConfig.sort_order).all() + + # 如果数据库没有配置,使用默认配置 + if not db_plans: + plans = MEMBERSHIP_PLANS + else: + # 转换为字典格式供模板使用 + plans = {} + for plan in db_plans: + plans[plan.plan_key] = { + 'name': plan.display_name, + 'price': plan.price, + 'original_price': plan.original_price, + 'period': plan.period, + 'period_days': plan.period_days, + 'description': plan.description, + 'is_recommended': plan.is_recommended, + 'user_type_key': plan.user_type_key, + } + + # 添加免费用户套餐(固定) + plans['free'] = { + 'name': '免费用户', + 'price': 0, + 'period': 'forever', + 'description': '基础翻译功能', + } + + return render_template('pricing.html', plans=plans, user=user, db_plans=db_plans) @app.route('/profile') diff --git a/templates/pricing.html b/templates/pricing.html index fadc827..c74b2c9 100644 --- a/templates/pricing.html +++ b/templates/pricing.html @@ -41,7 +41,7 @@

会员套餐

- +
@@ -69,87 +69,39 @@
- + + {% for plan in db_plans if plan.is_active %}
-
-
-

基础会员

-
¥29/月
- -
    -
  • ✅ 每日翻译50次
  • -
  • ✅ 单文件最大100页
  • -
  • ✅ 翻译历史记录
  • -
  • ✅ 不满意重新翻译
  • -
  • ✅ 原文译文对比查看
  • -
  • ✅ 导出PDF格式
  • -
  • ✅ 优先处理队列
  • -
- - {% if user and user.user_type == 'vip_basic' %} - 当前套餐 - {% elif user and user.user_type in ['vip_pro', 'vip_enterprise', 'admin'] %} - 已升级 - {% else %} - - {% endif %} -
-
-
- - -
-
+ -
- - -
-
-
-

企业会员

-
¥999/年
- -
    -
  • ✅ 翻译次数无限制
  • -
  • ✅ 页数无限制
  • -
  • ✅ 所有功能解锁
  • -
  • ✅ 专属客服支持
  • -
  • ✅ API接口调用
  • -
- - {% if user and user.user_type in ['vip_enterprise', 'admin'] %} - 当前套餐 - {% else %} - + {% endif %}
+ {% endfor %}