|
|
@ -160,9 +160,8 @@ const upload = multer({ |
|
|
|
|
|
|
|
|
// 添加请求日志中间件,捕获所有到达服务器的请求(必须放在bodyParser之后)
|
|
|
// 添加请求日志中间件,捕获所有到达服务器的请求(必须放在bodyParser之后)
|
|
|
app.use((req, res, next) => { |
|
|
app.use((req, res, next) => { |
|
|
// 将UTC时间转换为北京时间(UTC+8)
|
|
|
// 使用统一的时间处理函数获取当前时间
|
|
|
const now = new Date(); |
|
|
const beijingTime = getBeijingTime(); |
|
|
const beijingTime = new Date(now.getTime() + 8 * 60 * 60 * 1000); |
|
|
|
|
|
const formattedTime = beijingTime.toISOString().replace('Z', '+08:00'); |
|
|
const formattedTime = beijingTime.toISOString().replace('Z', '+08:00'); |
|
|
|
|
|
|
|
|
console.log(`[${formattedTime}] 收到请求: ${req.method} ${req.url}`); |
|
|
console.log(`[${formattedTime}] 收到请求: ${req.method} ${req.url}`); |
|
|
@ -3273,7 +3272,7 @@ async function handleAddImagesToExistingProduct(req, res, existingProductId, upl |
|
|
await Product.update({ |
|
|
await Product.update({ |
|
|
imageUrls: imageUrlsJson, |
|
|
imageUrls: imageUrlsJson, |
|
|
allImageUrls: imageUrlsJson, |
|
|
allImageUrls: imageUrlsJson, |
|
|
updated_at: new Date(), |
|
|
updated_at: getBeijingTime(), |
|
|
hasMultipleImages: mergedImageUrls.length > 1, |
|
|
hasMultipleImages: mergedImageUrls.length > 1, |
|
|
totalImages: mergedImageUrls.length |
|
|
totalImages: mergedImageUrls.length |
|
|
}, { |
|
|
}, { |
|
|
@ -3664,7 +3663,7 @@ app.post('/api/products/edit', async (req, res) => { |
|
|
await Product.update( |
|
|
await Product.update( |
|
|
{ |
|
|
{ |
|
|
...updateData, |
|
|
...updateData, |
|
|
updated_at: new Date() |
|
|
updated_at: getBeijingTime() |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
where: { productId } |
|
|
where: { productId } |
|
|
@ -5091,8 +5090,8 @@ app.post('/api/product/publish', async (req, res) => { |
|
|
yolk: product.yolk || '', |
|
|
yolk: product.yolk || '', |
|
|
specification: product.specification || '', |
|
|
specification: product.specification || '', |
|
|
status: 'pending_review', // 严格设置为待审核状态
|
|
|
status: 'pending_review', // 严格设置为待审核状态
|
|
|
created_at: new Date(), |
|
|
created_at: getBeijingTime(), |
|
|
updated_at: new Date() |
|
|
updated_at: getBeijingTime() |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 立即验证创建后的状态
|
|
|
// 立即验证创建后的状态
|
|
|
@ -5635,7 +5634,7 @@ app.post('/api/product/edit', async (req, res) => { |
|
|
originalQuantity: originalQuantity, |
|
|
originalQuantity: originalQuantity, |
|
|
// 如果是重新提交审核,清除拒绝原因
|
|
|
// 如果是重新提交审核,清除拒绝原因
|
|
|
rejectReason: isResubmit ? null : existingProduct.rejectReason, |
|
|
rejectReason: isResubmit ? null : existingProduct.rejectReason, |
|
|
updated_at: new Date() |
|
|
updated_at: getBeijingTime() |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 【新增】更新前的最终数据验证
|
|
|
// 【新增】更新前的最终数据验证
|
|
|
@ -5975,7 +5974,7 @@ app.post('/api/settlement/submit', async (req, res) => { |
|
|
proofurl: proofurl || '', // 证明材料 - NOT NULL约束,使用空字符串
|
|
|
proofurl: proofurl || '', // 证明材料 - NOT NULL约束,使用空字符串
|
|
|
brandurl: brandurl || '', // 品牌授权链文件
|
|
|
brandurl: brandurl || '', // 品牌授权链文件
|
|
|
partnerstatus: 'underreview', // 合作商状态明确设置为审核中,覆盖数据库默认值
|
|
|
partnerstatus: 'underreview', // 合作商状态明确设置为审核中,覆盖数据库默认值
|
|
|
updated_at: new Date() |
|
|
updated_at: getBeijingTime() |
|
|
}, { |
|
|
}, { |
|
|
where: { userId: user.userId } |
|
|
where: { userId: user.userId } |
|
|
}); |
|
|
}); |
|
|
@ -6325,7 +6324,7 @@ app.post('/api/conversations/:conversationId/read', async (req, res) => { |
|
|
const conversationId = req.params.conversationId; |
|
|
const conversationId = req.params.conversationId; |
|
|
const { userId, managerId, type } = req.body; |
|
|
const { userId, managerId, type } = req.body; |
|
|
|
|
|
|
|
|
const now = new Date(); |
|
|
const now = getBeijingTime(); |
|
|
let updateField; |
|
|
let updateField; |
|
|
|
|
|
|
|
|
if (type === 'user') { |
|
|
if (type === 'user') { |
|
|
@ -6478,7 +6477,7 @@ wss.on('connection', (ws, req) => { |
|
|
managerId: null, |
|
|
managerId: null, |
|
|
isUser: false, |
|
|
isUser: false, |
|
|
isManager: false, |
|
|
isManager: false, |
|
|
connectedAt: new Date() |
|
|
connectedAt: getBeijingTime() |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 连接认证处理
|
|
|
// 连接认证处理
|
|
|
@ -6660,7 +6659,7 @@ wss.on('connection', (ws, req) => { |
|
|
// 更新chat_online_status表的心跳时间
|
|
|
// 更新chat_online_status表的心跳时间
|
|
|
async function updateChatOnlineStatusHeartbeat(userId, type) { |
|
|
async function updateChatOnlineStatusHeartbeat(userId, type) { |
|
|
try { |
|
|
try { |
|
|
const now = new Date(); |
|
|
const now = getBeijingTime(); |
|
|
// 根据userId是否为null使用不同的SQL语句
|
|
|
// 根据userId是否为null使用不同的SQL语句
|
|
|
let sql; |
|
|
let sql; |
|
|
let replacements; |
|
|
let replacements; |
|
|
@ -6687,7 +6686,7 @@ async function updateChatOnlineStatusHeartbeat(userId, type) { |
|
|
// 更新chat_online_status表为离线状态
|
|
|
// 更新chat_online_status表为离线状态
|
|
|
async function updateChatOnlineStatusOffline(userId, type) { |
|
|
async function updateChatOnlineStatusOffline(userId, type) { |
|
|
try { |
|
|
try { |
|
|
const now = new Date(); |
|
|
const now = getBeijingTime(); |
|
|
// 根据userId是否为null使用不同的SQL语句
|
|
|
// 根据userId是否为null使用不同的SQL语句
|
|
|
let sql; |
|
|
let sql; |
|
|
let replacements; |
|
|
let replacements; |
|
|
@ -6916,7 +6915,7 @@ async function handleAuth(ws, data) { |
|
|
// 更新chat_online_status表
|
|
|
// 更新chat_online_status表
|
|
|
async function updateChatOnlineStatus(userId, type, socketId, deviceInfo) { |
|
|
async function updateChatOnlineStatus(userId, type, socketId, deviceInfo) { |
|
|
try { |
|
|
try { |
|
|
const now = new Date(); |
|
|
const now = getBeijingTime(); |
|
|
// 使用INSERT ... ON DUPLICATE KEY UPDATE语法确保只更新或插入一条记录
|
|
|
// 使用INSERT ... ON DUPLICATE KEY UPDATE语法确保只更新或插入一条记录
|
|
|
await sequelize.query( |
|
|
await sequelize.query( |
|
|
`INSERT INTO chat_online_status
|
|
|
`INSERT INTO chat_online_status
|
|
|
@ -7175,7 +7174,7 @@ async function createOrGetConversation(userId, managerId) { |
|
|
|
|
|
|
|
|
// 创建新会话
|
|
|
// 创建新会话
|
|
|
const conversationId = crypto.randomUUID(); |
|
|
const conversationId = crypto.randomUUID(); |
|
|
const now = new Date(); |
|
|
const now = getBeijingTime(); |
|
|
|
|
|
|
|
|
await sequelize.query( |
|
|
await sequelize.query( |
|
|
`INSERT INTO chat_conversations
|
|
|
`INSERT INTO chat_conversations
|
|
|
@ -7625,7 +7624,7 @@ async function handleChatMessage(ws, payload) { |
|
|
|
|
|
|
|
|
// 生成消息ID和时间戳
|
|
|
// 生成消息ID和时间戳
|
|
|
const messageId = payload.messageId || crypto.randomUUID(); // 允许前端提供messageId
|
|
|
const messageId = payload.messageId || crypto.randomUUID(); // 允许前端提供messageId
|
|
|
const now = new Date(); |
|
|
const now = getBeijingTime(); |
|
|
|
|
|
|
|
|
console.log('准备存储消息:', { |
|
|
console.log('准备存储消息:', { |
|
|
messageId, |
|
|
messageId, |
|
|
@ -7806,8 +7805,8 @@ async function storeMessage(messageData) { |
|
|
fileUrl || null, |
|
|
fileUrl || null, |
|
|
fileSize || null, |
|
|
fileSize || null, |
|
|
duration || null, |
|
|
duration || null, |
|
|
createdAt || new Date(), |
|
|
createdAt || getBeijingTime(), |
|
|
createdAt || new Date() |
|
|
createdAt || getBeijingTime() |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
@ -7866,7 +7865,7 @@ async function updateUnreadCount(conversationId, countField, increment) { |
|
|
`UPDATE chat_conversations
|
|
|
`UPDATE chat_conversations
|
|
|
SET ${countField} = ${countField} + ?, updated_at = ? |
|
|
SET ${countField} = ${countField} + ?, updated_at = ? |
|
|
WHERE conversation_id = ?`,
|
|
|
WHERE conversation_id = ?`,
|
|
|
{ replacements: [increment, new Date(), conversationId] } |
|
|
{ replacements: [increment, getBeijingTime(), conversationId] } |
|
|
); |
|
|
); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('更新未读计数失败:', error); |
|
|
console.error('更新未读计数失败:', error); |
|
|
@ -7896,7 +7895,7 @@ async function handleMarkRead(ws, payload) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
const now = new Date(); |
|
|
const now = getBeijingTime(); |
|
|
let countField; |
|
|
let countField; |
|
|
let updateQuery; |
|
|
let updateQuery; |
|
|
let updateParams; |
|
|
let updateParams; |
|
|
|