From 703a7406e9b91a64a6b33907beccc0f2c83ff5ca Mon Sep 17 00:00:00 2001 From: Default User Date: Tue, 3 Mar 2026 09:54:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=88=9B=E5=BB=BA=E8=B4=A7?= =?UTF-8?q?=E6=BA=90=E6=97=B6=E9=BB=98=E8=AE=A4=E5=86=99=E5=85=A5=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Reject.js | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/Reject.js b/Reject.js index 1ccd4b1..f3f34da 100644 --- a/Reject.js +++ b/Reject.js @@ -1059,29 +1059,7 @@ app.post('/api/supplies/create', async (req, res) => { "好货,不错!" ]; - // 固定写入2条评论 - const commentCount = 2; - console.log('准备插入', commentCount, '条默认评论...'); - - for (let i = 0; i < commentCount; i++) { - // 随机选择评论内容 - const randomComment = defaultComments[Math.floor(Math.random() * defaultComments.length)]; - // 随机生成点赞数和点踩数 - const randomLike = Math.floor(Math.random() * 10); - const randomHate = Math.floor(Math.random() * 3); - - try { - // 插入评论数据 - await connection.query( - 'INSERT INTO comments (productId, phoneNumber, comments, time, `like`, hate, review) VALUES (?, ?, ?, ?, ?, ?, ?)', - [productId, contactPhone, randomComment, new Date(), randomLike, randomHate, 1] - ); - console.log('插入评论成功:', randomComment); - } catch (commentError) { - console.error('插入评论失败:', commentError.message); - // 继续插入其他评论,不中断流程 - } - } + // 提交事务 await connection.commit(); @@ -1965,9 +1943,13 @@ app.get('/api/admin/stats/supplies', async (req, res) => { const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1); timeCondition = `AND created_at >= '${beforeYesterday.toISOString().slice(0, 19).replace('T', ' ')}' AND created_at < '${yesterday.toISOString().slice(0, 19).replace('T', ' ')}'`; } else if (filter === 'week') { - // 本周 - const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); - timeCondition = `AND created_at >= '${weekAgo.toISOString().slice(0, 19).replace('T', ' ')}'`; + // 本周(从周一到周日) + const dayOfWeek = now.getDay(); // 0-6,0表示周日 + const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 计算到周一的天数 + const weekStart = new Date(now); + weekStart.setDate(now.getDate() - daysToMonday); + weekStart.setHours(0, 0, 0, 0); + timeCondition = `AND created_at >= '${weekStart.toISOString().slice(0, 19).replace('T', ' ')}'`; } else if (filter === 'month') { // 本月(从本月1日到当前日期) const monthStart = new Date(now.getFullYear(), now.getMonth(), 1); @@ -2063,9 +2045,13 @@ app.get('/api/admin/supplies', async (req, res) => { const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1); timeCondition = `AND created_at >= '${beforeYesterday.toISOString().slice(0, 19).replace('T', ' ')}' AND created_at < '${yesterday.toISOString().slice(0, 19).replace('T', ' ')}'`; } else if (filter === 'week') { - // 本周 - const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); - timeCondition = `AND created_at >= '${weekAgo.toISOString().slice(0, 19).replace('T', ' ')}'`; + // 本周(从周一到周日) + const dayOfWeek = now.getDay(); // 0-6,0表示周日 + const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 计算到周一的天数 + const weekStart = new Date(now); + weekStart.setDate(now.getDate() - daysToMonday); + weekStart.setHours(0, 0, 0, 0); + timeCondition = `AND created_at >= '${weekStart.toISOString().slice(0, 19).replace('T', ' ')}'`; } else if (filter === 'month') { // 本月(从本月1日到当前日期) const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);