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