172 lines
4.3 KiB
JavaScript
172 lines
4.3 KiB
JavaScript
/**
|
||
* 系统配置管理控制器(客户端接口)
|
||
* 提供客户端调用的配置相关接口
|
||
*/
|
||
|
||
const Framework = require("../../framework/node-core-framework.js");
|
||
|
||
// sys_parameter 表直接存储字符串值,不需要类型转换
|
||
|
||
module.exports = {
|
||
/**
|
||
* @swagger
|
||
* /api/config/get:
|
||
* get:
|
||
* summary: 获取配置
|
||
* description: 根据配置键获取配置值,支持单个或多个配置键
|
||
* tags: [前端-系统配置]
|
||
* parameters:
|
||
* - in: query
|
||
* name: configKey
|
||
* required: false
|
||
* schema:
|
||
* type: string
|
||
* description: 配置键(单个,如:wx_num)
|
||
* - in: query
|
||
* name: configKeys
|
||
* required: false
|
||
* schema:
|
||
* type: string
|
||
* description: 配置键(多个,逗号分隔,如:wx_num,wx_img)
|
||
* responses:
|
||
* 200:
|
||
* description: 获取成功
|
||
*/
|
||
'GET /config/get': async (ctx) => {
|
||
try {
|
||
const models = await Framework.getModels();
|
||
const { sys_parameter, op } = models;
|
||
const { configKey, configKeys } = ctx.query;
|
||
|
||
// 如果没有提供配置键,返回失败
|
||
if (!configKey && !configKeys) {
|
||
return ctx.fail('请提供配置键');
|
||
}
|
||
|
||
// 处理多个配置键
|
||
let keys = [];
|
||
if (configKeys) {
|
||
keys = configKeys.split(',').map(k => k.trim()).filter(k => k);
|
||
} else if (configKey) {
|
||
keys = [configKey];
|
||
}
|
||
|
||
if (keys.length === 0) {
|
||
return ctx.fail('配置键不能为空');
|
||
}
|
||
|
||
const result = await sys_parameter.findAll({
|
||
where: {
|
||
key: {
|
||
[op.in]: keys
|
||
}
|
||
}
|
||
});
|
||
|
||
|
||
const tempData = {};
|
||
result.forEach(item => {
|
||
tempData[item.key] = item.value;
|
||
});
|
||
|
||
return ctx.success(tempData);
|
||
} catch (error) {
|
||
console.error('获取配置失败:', error);
|
||
return ctx.fail('获取配置失败: ' + error.message);
|
||
}
|
||
},
|
||
|
||
/**
|
||
* @swagger
|
||
* /api/config/pricing-plans:
|
||
* get:
|
||
* summary: 获取价格套餐列表
|
||
* description: 获取所有可用的价格套餐
|
||
* tags: [前端-系统配置]
|
||
* responses:
|
||
* 200:
|
||
* 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);
|
||
}
|
||
}
|
||
};
|
||
|