Browse Source

feat: 下架时同时更新status为sold_out

pull/8/head
徐飞洋 2 months ago
parent
commit
777cd8bb8e
  1. 7
      server-example/server-mysql.js

7
server-example/server-mysql.js

@ -4181,19 +4181,20 @@ app.post('/api/products/unpublish', async (req, res) => {
console.log('准备下架商品,productId:', productId, ',当前label:', product.label);
// 直接使用商品实例更新label字段
// 直接使用商品实例更新label字段和status字段
product.label = 1;
product.status = 'sold_out';
product.updated_at = getBeijingTime();
try {
await product.save();
console.log('下架商品成功(使用save方法):', { productId: product.productId, newLabel: product.label });
console.log('下架商品成功(使用save方法):', { productId: product.productId, newLabel: product.label, newStatus: product.status });
} catch (saveError) {
console.error('使用save方法更新失败,尝试使用update方法:', saveError);
try {
const updateResult = await Product.update(
{ label: 1, updated_at: getBeijingTime() },
{ label: 1, status: 'sold_out', updated_at: getBeijingTime() },
{ where: { productId } }
);
console.log('下架商品成功(使用update方法):', { productId, updateResult });

Loading…
Cancel
Save