Browse Source

修复内部消息重复问题并使用followup_at作为跟进时间

main
Default User 4 days ago
parent
commit
79aa3ef0a2
  1. 4
      pages/goods-detail/goods-detail.js
  2. 18
      server-example/server-mysql.js

4
pages/goods-detail/goods-detail.js

@ -2352,8 +2352,8 @@ Page({
type: viewer.type, type: viewer.type,
followupRecords: (viewer.followupRecords || []).map(record => ({ followupRecords: (viewer.followupRecords || []).map(record => ({
...record, ...record,
// 确保时间显示为北京时间 // 优先使用users表的followup_at字段作为跟进时间,如果没有则使用createdAt
createdAt: record.createdAt ? formatBeijingTime(record.createdAt) : '未知时间' createdAt: record.followup_at ? formatBeijingTime(record.followup_at) : (record.createdAt ? formatBeijingTime(record.createdAt) : '未知时间')
})) }))
})); }));

18
server-example/server-mysql.js

@ -1712,6 +1712,11 @@ User.init({
followup: { followup: {
type: DataTypes.TEXT // 临时跟进 type: DataTypes.TEXT // 临时跟进
}, },
followup_at: {
type: DataTypes.DATE, // 跟进时间
defaultValue: null,
comment: '跟进时间'
},
notice: { notice: {
type: DataTypes.STRING(255) // 通知提醒 type: DataTypes.STRING(255) // 通知提醒
}, },
@ -6139,33 +6144,34 @@ app.post('/api/products/detail', async (req, res) => {
attributes: ['user_id', 'created_at'] attributes: ['user_id', 'created_at']
}); });
// 提取浏览用户的user_id列表 // 提取浏览用户的user_id列表并去重,避免重复处理同一用户
const userIds = userViews.map(view => view.user_id); const userIds = [...new Set(userViews.map(view => view.user_id))];
// 查询这些用户的电话号码和跟进记录 // 查询这些用户的电话号码和跟进记录
let viewerInfo = []; let viewerInfo = [];
if (userIds.length > 0) { if (userIds.length > 0) {
// 查询用户信息,包括followup和type字段 // 查询用户信息,包括followup、followup_at和type字段
const users = await User.findAll({ const users = await User.findAll({
where: { where: {
userId: { userId: {
[Sequelize.Op.in]: userIds [Sequelize.Op.in]: userIds
} }
}, },
attributes: ['userId', 'phoneNumber', 'nickName', 'followup', 'type'] attributes: ['userId', 'phoneNumber', 'nickName', 'followup', 'followup_at', 'type']
}); });
// 构建浏览用户信息 // 构建浏览用户信息
userIds.forEach(userId => { userIds.forEach(userId => {
const user = users.find(u => u.userId === userId); const user = users.find(u => u.userId === userId);
if (user) { if (user) {
// 构建跟进记录,使用users表中的followup字段 // 构建跟进记录,使用users表中的followup字段和followup_at字段
const followupRecords = []; const followupRecords = [];
if (user.followup) { if (user.followup) {
followupRecords.push({ followupRecords.push({
content: user.followup, content: user.followup,
phoneNumber: user.phoneNumber, phoneNumber: user.phoneNumber,
createdAt: new Date() // 使用当前时间 followup_at: user.followup_at, // 传递followup_at字段
createdAt: user.followup_at || new Date() // 优先使用followup_at,否则使用当前时间
}); });
} }

Loading…
Cancel
Save