Browse Source

更新创建货源时默认评论功能:固定写入2条评论,使用默认电话号码13800138000

Boss3
Default User 1 month ago
parent
commit
b7601c5400
  1. 77
      Reject.js
  2. 1
      supply.html

77
Reject.js

@ -851,7 +851,7 @@ app.post('/api/supplies/create', async (req, res) => {
let connection;
try {
connection = await pool.getConnection();
const { productName, costprice, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category, producting, spec_status } = req.body;
const { productName, costprice, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category, producting, spec_status, phoneNumber } = req.body;
// 开始事务
await connection.beginTransaction();
@ -870,7 +870,7 @@ app.post('/api/supplies/create', async (req, res) => {
// 移除重复货源检测限制,允许创建相同货源
console.log('移除重复货源检测限制,允许创建相同货源...');
// 处理联系人信息
// 处理联系人信息(只获取联系人名称,不获取电话号码)
let productContact = '';
let contactPhone = '';
if (contactId) {
@ -878,7 +878,7 @@ app.post('/api/supplies/create', async (req, res) => {
// 从userlogin数据库获取联系人信息
const userLoginConnection = await userLoginPool.getConnection();
const [personnelData] = await userLoginConnection.query(
'SELECT alias, phoneNumber FROM Personnel WHERE projectName = "销售员" AND phoneNumber IS NOT NULL AND phoneNumber != "" AND id = ?',
'SELECT alias FROM Personnel WHERE projectName = "销售员" AND id = ?',
[parseInt(contactId)] // 使用contactId直接查询对应的联系人
);
userLoginConnection.release();
@ -886,9 +886,24 @@ app.post('/api/supplies/create', async (req, res) => {
console.log('查询到的联系人数据:', personnelData);
if (personnelData && personnelData.length > 0) {
productContact = personnelData[0].alias || '';
contactPhone = personnelData[0].phoneNumber || '';
console.log('获取到的联系人信息:', productContact, contactPhone);
console.log('获取到的联系人信息:', productContact);
}
}
// 优先使用当前登录用户的电话号码
if (req.user && req.user.phoneNumber) {
contactPhone = req.user.phoneNumber;
console.log('从当前登录用户获取电话号码:', contactPhone);
}
// 如果没有登录用户电话号码,尝试从解构的参数中获取
else if (phoneNumber) {
contactPhone = phoneNumber;
console.log('从解构参数获取电话号码:', contactPhone);
}
// 如果还是没有电话号码,使用默认电话号码
else {
contactPhone = '13800138000';
console.log('使用默认电话号码:', contactPhone);
}
console.log('准备插入的联系人信息:', productContact, contactPhone);
@ -1007,6 +1022,58 @@ app.post('/api/supplies/create', async (req, res) => {
return sendResponse(res, false, null, `创建货源失败: ${insertError.sqlMessage}`);
}
// 默认评论内容数组
const defaultComments = [
"又鸟蛋这个平台可以,在这里买蛋多数都是鸡场直接装货",
"要的滴,好蛋!",
"要得要得,这蛋安逸,下回还来拿",
"平台很真实,昨天进的货蛋源很好",
"还提供找车的物流服务,到货鸡蛋超省心",
"每天都有很多蛋,可以看到很多不同规格的价格",
"确实可以,蛋源选择,还帮忙找车!",
"品质稳定和描述的一样,长期合作完全没问题",
"批了几回了,次次都巴适,蛋新鲜老板耿直",
"平台价格随行就市,好多地方的蛋价都看得到,拿货不踩坑!",
"前几天还不是这个价,价格变化很快!",
"不光专业,人还耿直,有啥说啥,不会乱推荐,帮我们选的货都恰到好处,省心又省钱。",
"销售小哥儿小姐姐都专业得很,不管是问蛋的规格,还是拿货的流程,讲得明明白白,一点不糊弄人。",
"刚开始合作不是很懂,销售全程耐心指导,业务流程摸得门清,帮我们少走好多弯路,必须给个好评。",
"简单说:蛋源真实,价格随行就市。以后就认准这家了!",
"平台价格明明白白,各个产地、各种规格的蛋价一目了然,价格变动也能实时看到,拿货心里有底。",
"没得啥子花里胡哨的,实实在在的平台,蛋好,服务好,价格透明,业务专业,放心冲",
"界面清清楚楚,规格、产地、价格一目了然,不用东问西问,专业得很,做生意省太多时间。",
"最近蛋价浮动是有点大,平台更新得及时,实时看得到行情,方便我们及时调整拿货计划",
"开先我还是还半信半疑的,打电话过去聊了几句,销售确实专业靠谱",
"每天都在上新蛋源,库存实时更新,每天都来看一下,了解最新的货源情况",
"蛋源真实得很,打电话过去也可以讲价,拿货完全放心!",
"今天看了哈对比价格,发现好多同规格的有些价格是不一样勒,看起来还是非常方便",
"销售这个小姐姐说话温柔,讲价也好商量"
];
// 固定写入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();
connection.release();

1
supply.html

@ -6522,6 +6522,7 @@
freshness: document.getElementById('freshness').value,
imageUrls: supplyData.uploadedImages,
sellerId: userInfo.userId, // 添加当前登录用户的userId作为sellerId
phoneNumber: '13800138000', // 使用默认电话号码
autoOfflineDays: null, // 不再使用天数,设置为null
autoOfflineHours: autoOfflineHours,
autoOfflineTime: autoOfflineTimeStr

Loading…
Cancel
Save