diff --git a/server/server.js b/server/server.js index 71c2050..7464b6e 100644 --- a/server/server.js +++ b/server/server.js @@ -249,7 +249,7 @@ app.get('/api/rooms/:roomId/purchases/export', auth, (req, res) => { // WebSocket const clients = new Map(); wss.on('connection', (ws, req) => { - console.log('✅ WebSocket 客户端已连接'); + //console.log('✅ WebSocket 客户端已连接'); const url = new URL(req.url, 'http://localhost'); const token = url.searchParams.get('token'); if (!token) return ws.close(); @@ -516,11 +516,12 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) { console.log('📎 插入附件:', attachments.length, '个, purchase_id=', purchase.id); const insertAttach = db.prepare('INSERT INTO purchase_attachments (purchase_id, file_path, uploaded_by, timestamp) VALUES (?,?,?,?)'); attachments.forEach(fp => { console.log(' 📎', fp); insertAttach.run(purchase.id, fp, username, now); }); - if (usedRecentImage) { - replyText = `📎 已为「${aiResult.purchase_item}」关联 ${attachments.length} 个附件`; - db.prepare('INSERT INTO purchase_history (purchase_id, action, user, timestamp) VALUES (?,?,?,?)').run(purchase.id, `添加附件:${attachments.length} 个`, username, now); - console.log('✅ usedRecentImage 完成, replyText:', replyText); + db.prepare('INSERT INTO purchase_history (purchase_id, action, user, timestamp) VALUES (?,?,?,?)').run(purchase.id, `添加附件:${attachments.length} 个`, username, now); + // 如果字段没有变化,覆盖回复消息 + if (replyText.includes('没有发生') || usedRecentImage) { + replyText = `📎 已为「${aiResult.purchase_item}」添加 ${attachments.length} 个附件`; } + console.log('✅ 附件完成, replyText:', replyText); } else if (usedRecentImage) { replyText = `❌ 未找到最近的图片消息,请先发送图片再试。`; console.log('⚠️ usedRecentImage 但附件为空');