This commit is contained in:
张成
2025-12-16 16:39:18 +08:00
parent 41e03daa50
commit 5252add88a
3 changed files with 200 additions and 36 deletions

View File

@@ -38,26 +38,44 @@ module.exports = {
*/
'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;
const sn_code = body.sn_code;
if (!type || !content) {
return ctx.fail('反馈类型和内容不能为空');
}
// 这里可以将反馈保存到数据库,暂时只返回成功
// 如果需要保存,可以创建一个 feedback 表
if (!sn_code) {
return ctx.fail('请提供设备SN码');
}
const models = await Framework.getModels();
const { feedback, pla_account } = models;
// 根据 sn_code 查找用户
const user = await pla_account.findOne({
where: { sn_code, is_delete: 0 }
});
if (!user) {
return ctx.fail('用户不存在');
}
// 创建反馈记录
const feedbackRecord = await feedback.create({
user_id: user.id,
sn_code: sn_code,
type: type,
content: content,
contact: contact || '',
status: 'pending',
is_delete: 0
});
return ctx.success({
message: '反馈提交成功,感谢您的反馈!',
feedbackId: `FB${Date.now()}`
feedbackId: feedbackRecord.id
});
} catch (error) {
console.error('提交反馈失败:', error);
@@ -91,22 +109,47 @@ module.exports = {
*/
'POST /feedback/list': async (ctx) => {
try {
// 从body中获取user_id实际应该从token中解析
const body = ctx.getBody();
const user_id = body.user_id;
const sn_code = body.sn_code;
const page = parseInt(body.page) || 1;
const pageSize = parseInt(body.pageSize) || 20;
if (!user_id) {
return ctx.fail('请先登录');
if (!sn_code) {
return ctx.fail('请提供设备SN码');
}
const page = body.page || 1;
const pageSize = body.pageSize || 20;
// 这里可以从数据库查询反馈列表,暂时返回空列表
const models = await Framework.getModels();
const { feedback, pla_account } = models;
// 根据 sn_code 查找用户
const user = await pla_account.findOne({
where: { sn_code, is_delete: 0 }
});
if (!user) {
return ctx.fail('用户不存在');
}
const offset = (page - 1) * pageSize;
// 查询反馈列表
const { count, rows } = await feedback.findAndCountAll({
where: {
user_id: user.id,
is_delete: 0
},
limit: pageSize,
offset: offset,
order: [['create_time', 'DESC']]
});
return ctx.success({
count: 0,
total: 0,
rows: [],
list: []
count: count,
total: count,
rows: rows,
list: rows,
page: page,
pageSize: pageSize
});
} catch (error) {
console.error('获取反馈列表失败:', error);
@@ -134,22 +177,29 @@ module.exports = {
*/
'GET /feedback/detail': async (ctx) => {
try {
// 从body中获取user_id实际应该从token中解析
const body = ctx.getBody() || {};
const user_id = body.user_id;
const { feedbackId, id } = ctx.query;
const recordId = feedbackId || id;
if (!user_id) {
return ctx.fail('请先登录');
}
const { feedbackId } = ctx.query;
if (!feedbackId) {
if (!recordId) {
return ctx.fail('反馈ID不能为空');
}
// 这里可以从数据库查询反馈详情,暂时返回空
return ctx.fail('反馈记录不存在');
const models = await Framework.getModels();
const { feedback } = models;
// 查询反馈详情
const record = await feedback.findOne({
where: {
id: recordId,
is_delete: 0
}
});
if (!record) {
return ctx.fail('反馈记录不存在');
}
return ctx.success(record);
} catch (error) {
console.error('获取反馈详情失败:', error);
return ctx.fail('获取反馈详情失败: ' + error.message);