1
This commit is contained in:
@@ -88,84 +88,41 @@ module.exports = {
|
||||
* description: 获取成功
|
||||
*/
|
||||
'GET /config/pricing-plans': async (ctx) => {
|
||||
try {
|
||||
// 写死4条价格套餐数据
|
||||
// 价格计算规则:2小时 = 1天
|
||||
const pricingPlans = [
|
||||
{
|
||||
id: 1,
|
||||
name: '体验套餐',
|
||||
duration: '7天',
|
||||
days: 7,
|
||||
price: 28,
|
||||
originalPrice: 28,
|
||||
unit: '元',
|
||||
features: [
|
||||
'7天使用权限',
|
||||
'全功能体验',
|
||||
'技术支持'
|
||||
],
|
||||
featured: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '月度套餐',
|
||||
duration: '30天',
|
||||
days: 30,
|
||||
price: 99,
|
||||
originalPrice: 120,
|
||||
unit: '元',
|
||||
discount: '约8.3折',
|
||||
features: [
|
||||
'30天使用权限',
|
||||
'全功能使用',
|
||||
'优先技术支持',
|
||||
'性价比最高'
|
||||
],
|
||||
featured: true
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: '季度套餐',
|
||||
duration: '90天',
|
||||
days: 90,
|
||||
price: 269,
|
||||
originalPrice: 360,
|
||||
unit: '元',
|
||||
discount: '7.5折',
|
||||
features: [
|
||||
'90天使用权限',
|
||||
'全功能使用',
|
||||
'优先技术支持',
|
||||
'更优惠价格'
|
||||
],
|
||||
featured: false
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: '终生套餐',
|
||||
duration: '永久',
|
||||
days: -1,
|
||||
price: 888,
|
||||
originalPrice: null,
|
||||
unit: '元',
|
||||
discount: '超值',
|
||||
features: [
|
||||
'永久使用权限',
|
||||
'全功能使用',
|
||||
'终身技术支持',
|
||||
'一次购买,终身使用',
|
||||
'最划算选择'
|
||||
],
|
||||
featured: false
|
||||
}
|
||||
];
|
||||
|
||||
return ctx.success(pricingPlans);
|
||||
} catch (error) {
|
||||
console.error('获取价格套餐失败:', error);
|
||||
return ctx.fail('获取价格套餐失败: ' + error.message);
|
||||
}
|
||||
const models = Framework.getModels();
|
||||
const { pricing_plans } = models;
|
||||
|
||||
// 查询所有启用且未删除的套餐,按排序顺序返回
|
||||
const plans = await pricing_plans.findAll({
|
||||
where: {
|
||||
is_active: 1,
|
||||
is_delete: 0
|
||||
},
|
||||
order: [['sort_order', 'ASC'], ['id', 'ASC']],
|
||||
attributes: [
|
||||
'id', 'name', 'duration', 'days', 'price',
|
||||
'original_price', 'unit', 'discount', 'features', 'featured'
|
||||
]
|
||||
});
|
||||
|
||||
// 转换数据格式以匹配前端期望
|
||||
const pricingPlans = plans.map(plan => {
|
||||
const planData = plan.toJSON();
|
||||
|
||||
// 重命名字段以匹配前端期望(camelCase)
|
||||
if (planData.original_price !== null) {
|
||||
planData.originalPrice = planData.original_price;
|
||||
}
|
||||
delete planData.original_price;
|
||||
|
||||
// 转换 featured 为布尔值
|
||||
planData.featured = planData.featured === 1;
|
||||
|
||||
return planData;
|
||||
});
|
||||
|
||||
return ctx.success(pricingPlans);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user