diff --git a/server/src/routes/config.ts b/server/src/routes/config.ts index 21747a1..e40121e 100644 --- a/server/src/routes/config.ts +++ b/server/src/routes/config.ts @@ -1,5 +1,5 @@ import { Router } from 'express' -import { pool } from '../db/connection' +import pool from '../db/connection' import { authMiddleware } from '../middleware/auth' const router = Router() @@ -37,7 +37,7 @@ router.put('/', authMiddleware, async (req, res) => { // 批量更新配置 for (const [key, value] of Object.entries(data)) { - await pool.execute( + await pool.query( 'INSERT INTO sys_config (config_key, config_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE config_value = ?', [key, value, value] ) diff --git a/server/src/routes/feedback.ts b/server/src/routes/feedback.ts index 9677b94..7762a4c 100644 --- a/server/src/routes/feedback.ts +++ b/server/src/routes/feedback.ts @@ -1,5 +1,5 @@ import { Router } from 'express' -import { pool } from '../db/connection' +import pool from '../db/connection' import { authMiddleware } from '../middleware/auth' const router = Router() @@ -95,11 +95,40 @@ router.put('/:id/status', authMiddleware, async (req, res) => { return res.status(400).json({ error: '无效的状态' }) } + // 查询反馈信息(用于发送通知) + const [feedbackRows] = await pool.execute( + 'SELECT user_id, content FROM feedbacks WHERE id = ?', + [id] + ) + const feedback = (feedbackRows as any[])[0] + await pool.execute( 'UPDATE feedbacks SET status = ?, admin_reply = ? WHERE id = ?', [status, admin_reply || '', id] ) + // 如果有管理员回复,发送通知给反馈提交者 + if (feedback && admin_reply && admin_reply.trim()) { + const statusText: Record = { + processed: '已处理', + ignored: '已忽略', + pending: '待处理' + } + const replyPreview = admin_reply.trim().length > 50 + ? admin_reply.trim().slice(0, 50) + '...' + : admin_reply.trim() + + await pool.execute( + `INSERT INTO notifications (user_id, type, title, content) + VALUES (?, 'personal', ?, ?)`, + [ + feedback.user_id, + `您的反馈已${statusText[status] || '更新'}`, + `反馈内容:${feedback.content.slice(0, 30)}...\n\n管理员回复:${replyPreview}` + ] + ) + } + res.json({ success: true }) } catch (error) { console.error('Update feedback status error:', error)