feat: 套餐权益列表从后台UserTypeConfig动态读取
- 权益列表从数据库配置读取 - 支持按用户类型显示✅/❌状态 - 更新各等级用户权益配置
This commit is contained in:
82
app.py
82
app.py
@@ -209,37 +209,71 @@ def pricing():
|
||||
"""会员定价页"""
|
||||
user = get_current_user()
|
||||
|
||||
# 权益名称映射
|
||||
feature_names = {
|
||||
'basic_translate': '基础翻译功能',
|
||||
'history': '翻译历史记录',
|
||||
'retranslate': '不满意重新翻译',
|
||||
'export_pdf': '导出PDF格式',
|
||||
'compare_view': '原文译文对比查看',
|
||||
'batch_translate': '批量翻译',
|
||||
'custom_terms': '自定义术语库',
|
||||
'priority_queue': '优先处理队列',
|
||||
'custom_instruction': '自定义翻译要求',
|
||||
'api_access': 'API接口调用',
|
||||
}
|
||||
|
||||
# 从数据库读取动态配置的会员套餐
|
||||
db_plans = MembershipPlanConfig.query.filter_by(is_active=True)\
|
||||
.order_by(MembershipPlanConfig.sort_order).all()
|
||||
|
||||
# 如果数据库没有配置,使用默认配置
|
||||
if not db_plans:
|
||||
plans = MEMBERSHIP_PLANS
|
||||
else:
|
||||
# 转换为字典格式供模板使用
|
||||
plans = {}
|
||||
# 读取用户类型配置获取权益
|
||||
user_types = UserTypeConfig.query.filter_by(is_active=True).all()
|
||||
user_type_map = {ut.type_key: ut for ut in user_types}
|
||||
|
||||
# 为每个套餐添加权益列表
|
||||
plan_features = {}
|
||||
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,
|
||||
}
|
||||
ut = user_type_map.get(plan.user_type_key)
|
||||
if ut:
|
||||
features = ut.get_features()
|
||||
plan_features[plan.plan_key] = [
|
||||
{'key': f, 'name': feature_names.get(f, f), 'has': True}
|
||||
for f in features
|
||||
]
|
||||
# 添加限制信息
|
||||
plan_features[plan.plan_key].insert(0, {
|
||||
'key': 'daily_translations',
|
||||
'name': f"每日翻译{ut.daily_translations if ut.daily_translations > 0 else '无限'}次",
|
||||
'has': True
|
||||
})
|
||||
plan_features[plan.plan_key].insert(1, {
|
||||
'key': 'max_pages',
|
||||
'name': f"单文件最大{ut.max_pages if ut.max_pages > 0 else '无限'}页",
|
||||
'has': True
|
||||
})
|
||||
|
||||
# 添加免费用户套餐(固定)
|
||||
plans['free'] = {
|
||||
'name': '免费用户',
|
||||
'price': 0,
|
||||
'period': 'forever',
|
||||
'description': '基础翻译功能',
|
||||
}
|
||||
# 免费用户权益
|
||||
free_ut = user_type_map.get('free')
|
||||
free_features = []
|
||||
if free_ut:
|
||||
free_features = [
|
||||
{'key': 'daily_translations', 'name': f"每日翻译{free_ut.daily_translations}次", 'has': True},
|
||||
{'key': 'max_pages', 'name': f"单文件最大{free_ut.max_pages}页", 'has': True},
|
||||
]
|
||||
for f in free_ut.get_features():
|
||||
free_features.append({'key': f, 'name': feature_names.get(f, f), 'has': True})
|
||||
# 添加没有的功能
|
||||
all_features = ['compare_view', 'batch_translate', 'custom_terms']
|
||||
for f in all_features:
|
||||
if f not in free_ut.get_features():
|
||||
free_features.append({'key': f, 'name': feature_names.get(f, f), 'has': False})
|
||||
|
||||
return render_template('pricing.html', plans=plans, user=user, db_plans=db_plans)
|
||||
return render_template('pricing.html',
|
||||
plans=db_plans,
|
||||
plan_features=plan_features,
|
||||
free_features=free_features,
|
||||
user=user)
|
||||
|
||||
|
||||
@app.route('/profile')
|
||||
|
||||
@@ -49,13 +49,9 @@
|
||||
<div class="price my-3">¥0<small>/永久</small></div>
|
||||
|
||||
<ul class="features text-start">
|
||||
<li>✅ 每日翻译10次</li>
|
||||
<li>✅ 单文件最大50页</li>
|
||||
<li>✅ 翻译历史记录</li>
|
||||
<li>✅ 不满意重新翻译</li>
|
||||
<li>✅ 导出PDF格式</li>
|
||||
<li class="text-muted">❌ 原文译文对比</li>
|
||||
<li class="text-muted">❌ 批量翻译</li>
|
||||
{% for feat in free_features %}
|
||||
<li>{% if feat.has %}✅{% else %}<span class="text-muted">❌</span>{% endif %} {{ feat.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if user and user.user_type in ['free', 'vip_basic', 'vip_pro', 'vip_enterprise', 'admin'] %}
|
||||
@@ -89,6 +85,12 @@
|
||||
|
||||
<p class="text-muted">{{ plan.description }}</p>
|
||||
|
||||
<ul class="features text-start">
|
||||
{% for feat in plan_features.get(plan.plan_key, []) %}
|
||||
<li>✅ {{ feat.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if user and user.user_type == plan.user_type_key %}
|
||||
<span class="btn btn-success w-100 mt-3 disabled">当前套餐</span>
|
||||
{% elif user and user.user_type in ['vip_enterprise', 'admin'] %}
|
||||
|
||||
Reference in New Issue
Block a user