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 @@
{{ plan.description }}
- {% if user and user.user_type == 'vip_pro' %} + {% if user and user.user_type == plan.user_type_key %} 当前套餐 {% elif user and user.user_type in ['vip_enterprise', 'admin'] %} 已升级 + {% elif user and user.user_type in ['vip_pro', 'vip_basic'] and plan.user_type_key not in ['vip_basic'] %} + 已升级 {% else %} - - {% endif %} -