From 62ca400b64a3588cb6137808b6db7a398450986f Mon Sep 17 00:00:00 2001 From: wangxiaogang <1433729587@qq.com> Date: Mon, 8 Jun 2026 10:40:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=8D=E9=A6=88=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=20+=20=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 管理员回复反馈时自动发送个人通知给用户 - 修复 config.ts 和 feedback.ts 的 pool 导入方式 --- server/src/routes/config.ts | 4 ++-- server/src/routes/feedback.ts | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) 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)