Browse Source

移除创建货源时默认写入评论的逻辑

Boss
Default User 4 days ago
parent
commit
703a7406e9
  1. 42
      Reject.js

42
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);

Loading…
Cancel
Save