Trae AI 4 days ago
parent
commit
0982db2b2e
  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,
followupRecords: (viewer.followupRecords || []).map(record => ({
...record,
// 确保时间显示为北京时间
createdAt: record.createdAt ? formatBeijingTime(record.createdAt) : '未知时间'
// 优先使用users表的followup_at字段作为跟进时间,如果没有则使用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: {
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,否则使用当前时间
});
}

Loading…
Cancel
Save