feat: 反馈回复通知 + 修复导入
- 管理员回复反馈时自动发送个人通知给用户 - 修复 config.ts 和 feedback.ts 的 pool 导入方式
This commit is contained in:
@@ -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]
|
||||
)
|
||||
|
||||
@@ -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<string, string> = {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user