feat: pricing页面使用后台管理配置的会员套餐数据

- 从数据库MembershipPlanConfig读取动态配置
- 支持推荐标记、原价显示
- 按用户状态显示按钮
This commit is contained in:
2026-04-14 18:39:04 +08:00
parent 4f33e92abf
commit ee5e672901
2 changed files with 52 additions and 69 deletions

35
app.py
View File

@@ -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')