From 8c8bcb8ec33c0a59ccd949aa98ff18939124825b Mon Sep 17 00:00:00 2001 From: dzl <786316265@qq.com> Date: Fri, 24 Oct 2025 16:17:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=BA=93=E5=AD=98=E7=AE=97?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/orders.js | 29 +++++++++++++++++++++++++++++ routes/products.js | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/routes/orders.js b/routes/orders.js index 66990f0..a9b0ec6 100644 --- a/routes/orders.js +++ b/routes/orders.js @@ -841,6 +841,27 @@ router.put('/:id/status', async (req, res) => { const order = orders[0]; + const [orderItems] = await db.execute( + 'SELECT * FROM order_items WHERE order_id = ?', + [orderId] + ); + if (status === 'cancelled') { + // 增加商品库存 + for (const item of orderItems) { + await db.execute( + 'UPDATE products SET stock = stock + ? WHERE id = ?', + [item.quantity, item.product_id] + ); + await db.execute( + 'UPDATE product_spec_combinations SET stock = stock + ? WHERE id = ?', + [item.quantity, item.spec_combination_id] + ) + } + } + // console.log(111,order,orderItems) + + + // 如果是取消订单,需要退还积分和融豆 if (status === 'cancelled' && order.status !== 'cancelled' && order.status !== 'pre_order') { // 退还用户积分 @@ -898,6 +919,14 @@ router.put('/:id/status', async (req, res) => { 'SELECT * FROM products WHERE id = ?', [product.product_id] ); + await getDB().execute( + 'UPDATE products SET sales = sales + ? WHERE id = ?', + [product.quantity, product.product_id] + ); + await getDB().execute( + 'UPDATE products SET stock = stock - ? WHERE id = ?', + [product.quantity, product.product_id] + ); if (producersResult[0].shop_name) { await db.execute( 'UPDATE users SET income = income + ? WHERE id = ?', diff --git a/routes/products.js b/routes/products.js index 5e4cf2d..a8119e2 100644 --- a/routes/products.js +++ b/routes/products.js @@ -673,7 +673,7 @@ router.put('/:id', async (req, res) => { updateValues.push(status); } - if (sale_price !== null) { + if (sale_price !== undefined) { updateFields.push('sale_price = ?'); updateValues.push(sale_price); console.log(12345,sale_price)