160 lines
4.3 KiB
JavaScript
160 lines
4.3 KiB
JavaScript
/**
|
||
* 意见反馈管理控制器(客户端接口)
|
||
* 提供客户端调用的意见反馈相关接口
|
||
*/
|
||
|
||
const Framework = require("../../framework/node-core-framework.js");
|
||
|
||
module.exports = {
|
||
/**
|
||
* @swagger
|
||
* /api/feedback/submit:
|
||
* post:
|
||
* summary: 提交反馈
|
||
* description: 提交用户反馈
|
||
* tags: [前端-意见反馈]
|
||
* requestBody:
|
||
* required: true
|
||
* content:
|
||
* application/json:
|
||
* schema:
|
||
* type: object
|
||
* required:
|
||
* - type
|
||
* - content
|
||
* properties:
|
||
* type:
|
||
* type: string
|
||
* description: 反馈类型
|
||
* content:
|
||
* type: string
|
||
* description: 反馈内容
|
||
* contact:
|
||
* type: string
|
||
* description: 联系方式(可选)
|
||
* responses:
|
||
* 200:
|
||
* description: 提交成功
|
||
*/
|
||
'POST /feedback/submit': async (ctx) => {
|
||
try {
|
||
// 从body中获取user_id和sn_code,实际应该从token中解析
|
||
const body = ctx.getBody();
|
||
const user_id = body.user_id;
|
||
const sn_code = body.sn_code;
|
||
|
||
if (!user_id) {
|
||
return ctx.fail('请先登录');
|
||
}
|
||
const { type, content, contact } = body;
|
||
|
||
if (!type || !content) {
|
||
return ctx.fail('反馈类型和内容不能为空');
|
||
}
|
||
|
||
// 这里可以将反馈保存到数据库,暂时只返回成功
|
||
// 如果需要保存,可以创建一个 feedback 表
|
||
|
||
return ctx.success({
|
||
message: '反馈提交成功,感谢您的反馈!',
|
||
feedbackId: `FB${Date.now()}`
|
||
});
|
||
} catch (error) {
|
||
console.error('提交反馈失败:', error);
|
||
return ctx.fail('提交反馈失败: ' + error.message);
|
||
}
|
||
},
|
||
|
||
/**
|
||
* @swagger
|
||
* /api/feedback/list:
|
||
* post:
|
||
* summary: 获取反馈列表
|
||
* description: 根据用户ID获取反馈列表
|
||
* tags: [前端-意见反馈]
|
||
* requestBody:
|
||
* required: true
|
||
* content:
|
||
* application/json:
|
||
* schema:
|
||
* type: object
|
||
* properties:
|
||
* page:
|
||
* type: integer
|
||
* description: 页码
|
||
* pageSize:
|
||
* type: integer
|
||
* description: 每页数量
|
||
* responses:
|
||
* 200:
|
||
* description: 获取成功
|
||
*/
|
||
'POST /feedback/list': async (ctx) => {
|
||
try {
|
||
// 从body中获取user_id,实际应该从token中解析
|
||
const body = ctx.getBody();
|
||
const user_id = body.user_id;
|
||
|
||
if (!user_id) {
|
||
return ctx.fail('请先登录');
|
||
}
|
||
const page = body.page || 1;
|
||
const pageSize = body.pageSize || 20;
|
||
|
||
// 这里可以从数据库查询反馈列表,暂时返回空列表
|
||
return ctx.success({
|
||
count: 0,
|
||
total: 0,
|
||
rows: [],
|
||
list: []
|
||
});
|
||
} catch (error) {
|
||
console.error('获取反馈列表失败:', error);
|
||
return ctx.fail('获取反馈列表失败: ' + error.message);
|
||
}
|
||
},
|
||
|
||
/**
|
||
* @swagger
|
||
* /api/feedback/detail:
|
||
* get:
|
||
* summary: 获取反馈详情
|
||
* description: 根据反馈ID获取详细信息
|
||
* tags: [前端-意见反馈]
|
||
* parameters:
|
||
* - in: query
|
||
* name: feedbackId
|
||
* required: true
|
||
* schema:
|
||
* type: string
|
||
* description: 反馈ID
|
||
* responses:
|
||
* 200:
|
||
* description: 获取成功
|
||
*/
|
||
'GET /feedback/detail': async (ctx) => {
|
||
try {
|
||
// 从body中获取user_id,实际应该从token中解析
|
||
const body = ctx.getBody() || {};
|
||
const user_id = body.user_id;
|
||
|
||
if (!user_id) {
|
||
return ctx.fail('请先登录');
|
||
}
|
||
|
||
const { feedbackId } = ctx.query;
|
||
|
||
if (!feedbackId) {
|
||
return ctx.fail('反馈ID不能为空');
|
||
}
|
||
|
||
// 这里可以从数据库查询反馈详情,暂时返回空
|
||
return ctx.fail('反馈记录不存在');
|
||
} catch (error) {
|
||
console.error('获取反馈详情失败:', error);
|
||
return ctx.fail('获取反馈详情失败: ' + error.message);
|
||
}
|
||
}
|
||
};
|
||
|