新增优惠卷管理和图片上传
This commit is contained in:
@@ -973,7 +973,6 @@ router.get('/:id/recommended', async (req, res) => {
|
||||
SELECT * FROM products_category WHERE category_id IN (${categoryIds.map(() => '?').join(',')})
|
||||
`;
|
||||
const [recommendProductIds] = await getDB().execute(recommendId, categoryIds);
|
||||
console.log(1234, recommendProductIds);
|
||||
|
||||
filteredRecommendProductIds = [...new Set(recommendProductIds.map(item => item.product_id))];
|
||||
|
||||
@@ -993,20 +992,42 @@ router.get('/:id/recommended', async (req, res) => {
|
||||
|
||||
// 如果同类别商品不足,补充其他热门商品
|
||||
if (recommendedProducts.length < 6) {
|
||||
console.log(123456, filteredRecommendProductIds);
|
||||
// const remainingCount = 6 - recommendedProducts.length;
|
||||
const additionalQuery = `
|
||||
SELECT id, name, price, points_price as points,
|
||||
stock, image_url as image, description
|
||||
FROM products
|
||||
WHERE id != 3
|
||||
|
||||
const recommendQuery = `
|
||||
SELECT products_id FROM recommend_product
|
||||
WHERE products_id NOT IN (${filteredRecommendProductIds.map(() => '?').join(',')})
|
||||
ORDER BY RAND()
|
||||
LIMIT ${6 - recommendedProducts.length}
|
||||
`;
|
||||
const [additionalProducts] = await getDB().execute(
|
||||
additionalQuery,
|
||||
);
|
||||
recommendedProducts.push(...additionalProducts);
|
||||
`
|
||||
const [recommendProductIds] = await getDB().execute(recommendQuery, [...filteredRecommendProductIds]);
|
||||
filteredRecommendProductIds.push(...recommendProductIds.map(item => item.products_id));
|
||||
for (const item of recommendProductIds) {
|
||||
const recommendQuery = `
|
||||
SELECT id, name, price, points_price as points,
|
||||
stock, image_url as image, description
|
||||
FROM products
|
||||
WHERE id = ?
|
||||
`;
|
||||
const [recommendProduct] = await getDB().execute(recommendQuery, [item.products_id]);
|
||||
recommendedProducts.push(recommendProduct[0]);
|
||||
}
|
||||
if (recommendProductIds.length + recommendedProducts.length < 6) {
|
||||
// 补充其他热门商品
|
||||
const additionalQuery = `
|
||||
SELECT id, name, price, points_price as points,
|
||||
stock, image_url as image, description
|
||||
FROM products
|
||||
WHERE id NOT IN (${filteredRecommendProductIds.map(() => '?').join(',')})
|
||||
AND id != 3
|
||||
ORDER BY RAND()
|
||||
LIMIT ${6 - recommendedProducts.length}
|
||||
`;
|
||||
const [additionalProducts] = await getDB().execute(
|
||||
additionalQuery,
|
||||
filteredRecommendProductIds
|
||||
);
|
||||
recommendedProducts.push(...additionalProducts);
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
|
||||
Reference in New Issue
Block a user