|
|
|
@ -1853,7 +1853,7 @@ app.post('/api/product/list', async (req, res) => { |
|
|
|
} |
|
|
|
|
|
|
|
// 处理商品列表中的grossWeight字段,确保是数字类型,同时反序列化imageUrls
|
|
|
|
const processedProducts = products.map(product => { |
|
|
|
const processedProducts = await Promise.all(products.map(async product => { |
|
|
|
const productJSON = product.toJSON(); |
|
|
|
|
|
|
|
// 确保created_at字段存在并转换为ISO字符串格式
|
|
|
|
@ -1880,8 +1880,15 @@ app.post('/api/product/list', async (req, res) => { |
|
|
|
// 确保grossWeight值是字符串类型
|
|
|
|
productJSON.grossWeight = String(grossWeightDetails.value); |
|
|
|
|
|
|
|
// 确保reservedCount是数字类型,如果不存在则默认为0
|
|
|
|
productJSON.reservedCount = typeof productJSON.reservedCount === 'number' ? productJSON.reservedCount : 0; |
|
|
|
// 查询该商品的收藏人数 - 从favorites表中统计
|
|
|
|
const favoriteCount = await Favorite.count({ |
|
|
|
where: { |
|
|
|
productId: productJSON.productId |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 使用查询到的收藏人数更新reservedCount字段
|
|
|
|
productJSON.reservedCount = favoriteCount; |
|
|
|
|
|
|
|
// 重要修复:反序列化imageUrls字段,确保前端收到的是数组
|
|
|
|
if (productJSON.imageUrls && typeof productJSON.imageUrls === 'string') { |
|
|
|
@ -1934,7 +1941,7 @@ app.post('/api/product/list', async (req, res) => { |
|
|
|
} |
|
|
|
|
|
|
|
return productJSON; |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
// 准备响应数据 - 修改格式以匹配前端期望
|
|
|
|
const responseData = { |
|
|
|
@ -3687,6 +3694,13 @@ app.post('/api/products/detail', async (req, res) => { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询收藏人数 - 从favorites表中统计该商品的收藏数量
|
|
|
|
const favoriteCount = await Favorite.count({ |
|
|
|
where: { |
|
|
|
productId: productId |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 对返回的商品数据进行处理
|
|
|
|
let updatedProduct = { ...product.toJSON() }; |
|
|
|
|
|
|
|
@ -3730,11 +3744,11 @@ app.post('/api/products/detail', async (req, res) => { |
|
|
|
updatedProduct.grossWeight = String(grossWeightDetails.value); |
|
|
|
} |
|
|
|
|
|
|
|
// 确保reservedCount是数字类型,如果不存在则默认为0
|
|
|
|
updatedProduct.reservedCount = typeof updatedProduct.reservedCount === 'number' ? updatedProduct.reservedCount : 0; |
|
|
|
// 设置收藏人数 - 从favorites表统计得到
|
|
|
|
updatedProduct.reservedCount = favoriteCount; |
|
|
|
|
|
|
|
console.log('商品详情 - 最终返回的毛重值:', updatedProduct.grossWeight, '类型:', typeof updatedProduct.grossWeight); |
|
|
|
console.log('商品详情 - 返回的预约人数:', updatedProduct.reservedCount, '类型:', typeof updatedProduct.reservedCount); |
|
|
|
console.log('商品详情 - 返回的收藏人数:', updatedProduct.reservedCount, '类型:', typeof updatedProduct.reservedCount); |
|
|
|
|
|
|
|
res.json({ |
|
|
|
success: true, |
|
|
|
|