1
This commit is contained in:
@@ -189,13 +189,15 @@ module.exports = {
|
||||
try {
|
||||
const models = Framework.getModels();
|
||||
const { apply_records } = models;
|
||||
const { applyId } = ctx.query;
|
||||
// 支持 applyId 和 id 两种参数名(向后兼容)
|
||||
const recordId = ctx.query.applyId || ctx.query.id;
|
||||
|
||||
if (!applyId) {
|
||||
if (!recordId) {
|
||||
return ctx.fail('投递记录ID不能为空');
|
||||
}
|
||||
|
||||
const record = await apply_records.findOne({ where: { applyId } });
|
||||
// 使用 id 字段查询(数据库主键)
|
||||
const record = await apply_records.findOne({ where: { id: recordId } });
|
||||
|
||||
if (!record) {
|
||||
return ctx.fail('投递记录不存在');
|
||||
|
||||
@@ -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);
|
||||
|
||||
112
api/model/feedback.js
Normal file
112
api/model/feedback.js
Normal file
@@ -0,0 +1,112 @@
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
/**
|
||||
* 意见反馈表模型
|
||||
* 记录用户的意见反馈信息
|
||||
*/
|
||||
module.exports = (db) => {
|
||||
const feedback = db.define('feedback', {
|
||||
// 用户信息
|
||||
user_id: {
|
||||
comment: '用户ID(关联 pla_account.id)',
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'pla_account',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
sn_code: {
|
||||
comment: '设备SN码',
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
defaultValue: ''
|
||||
},
|
||||
|
||||
// 反馈信息
|
||||
type: {
|
||||
comment: '反馈类型: bug-Bug反馈, suggestion-功能建议, question-使用问题, other-其他',
|
||||
type: Sequelize.STRING(20),
|
||||
allowNull: false,
|
||||
defaultValue: 'other'
|
||||
},
|
||||
content: {
|
||||
comment: '反馈内容',
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: false
|
||||
},
|
||||
contact: {
|
||||
comment: '联系方式(手机号、邮箱等)',
|
||||
type: Sequelize.STRING(100),
|
||||
allowNull: true,
|
||||
defaultValue: ''
|
||||
},
|
||||
|
||||
// 处理状态
|
||||
status: {
|
||||
comment: '处理状态: pending-待处理, processing-处理中, completed-已完成, rejected-已拒绝',
|
||||
type: Sequelize.STRING(20),
|
||||
allowNull: false,
|
||||
defaultValue: 'pending'
|
||||
},
|
||||
reply_content: {
|
||||
comment: '回复内容',
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
reply_time: {
|
||||
comment: '回复时间',
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true
|
||||
},
|
||||
reply_user_id: {
|
||||
comment: '回复人ID(管理员ID)',
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: true
|
||||
},
|
||||
|
||||
// 备注
|
||||
remark: {
|
||||
comment: '备注',
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
|
||||
// 软删除
|
||||
is_delete: {
|
||||
comment: '是否删除(0-未删除,1-已删除)',
|
||||
type: Sequelize.TINYINT(1),
|
||||
allowNull: false,
|
||||
defaultValue: 0
|
||||
}
|
||||
}, {
|
||||
tableName: 'feedback',
|
||||
indexes: [
|
||||
{
|
||||
name: 'idx_user_id',
|
||||
fields: ['user_id']
|
||||
},
|
||||
{
|
||||
name: 'idx_sn_code',
|
||||
fields: ['sn_code']
|
||||
},
|
||||
{
|
||||
name: 'idx_type',
|
||||
fields: ['type']
|
||||
},
|
||||
{
|
||||
name: 'idx_status',
|
||||
fields: ['status']
|
||||
},
|
||||
{
|
||||
name: 'idx_create_time',
|
||||
fields: ['create_time']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// feedback.sync({ alter: true });
|
||||
|
||||
return feedback;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user