Files
autoAiWorkSys/api/controller_front/config.js
张成 1b93211b7a 1
2025-12-16 17:51:40 +08:00

178 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 系统配置管理控制器(客户端接口)
* 提供客户端调用的配置相关接口
*/
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 mockData = {
wx_num: 'test_wechat_123',
wx_img: '/uploads/wechat_qrcode.png'
};
// 如果只有一个配置键,返回单个配置值
if (keys.length === 1) {
const key = keys[0];
return ctx.success({
[key]: mockData[key] || ''
});
}
// 多个配置键,返回对象
const result = {};
keys.forEach(key => {
result[key] = mockData[key] || '';
});
return ctx.success(result);
} 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);
}
}
};