From bca4b412c9b310074cc4496630ba104706d1ffd6 Mon Sep 17 00:00:00 2001 From: dzl <786316265@qq.com> Date: Fri, 24 Oct 2025 16:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BF=94=E5=9B=9E=E5=AE=9E?= =?UTF-8?q?=E4=BB=98=E6=80=BB=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/orders.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/routes/orders.js b/routes/orders.js index b618f12..4a533f1 100644 --- a/routes/orders.js +++ b/routes/orders.js @@ -77,7 +77,7 @@ router.get('/', auth, async (req, res) => { SELECT o.id, o.order_no, o.user_id, o.total_amount, o.total_points, o.status, o.address, o.created_at, o.updated_at,o.total_rongdou, - u.username + u.username, o.real_rongdou, o.real_points FROM orders o LEFT JOIN users u ON o.user_id = u.id ${whereClause} @@ -114,7 +114,7 @@ router.get('/', auth, async (req, res) => { } // 处理地址信息 - console.log(order.address,'order.address'); + // console.log(order.address,'order.address'); if (order.address) { try { @@ -344,7 +344,8 @@ router.get('/:id', auth, async (req, res) => { const query = ` SELECT o.id, o.order_no, o.user_id, o.total_amount, o.total_points, - o.status, o.address, o.created_at, o.updated_at, + o.status, o.address, o.created_at, o.updated_at, o.total_rongdou, + o.real_rongdou, o.real_points, u.username, u.phone FROM orders o LEFT JOIN users u ON o.user_id = u.id @@ -457,6 +458,10 @@ router.post('/create-from-cart', auth, async (req, res) => { `UPDATE product_spec_combinations SET stock = stock - ? WHERE id = ?`, [item.quantity, item.specification_id] ); + await db.execute( + `UPDATE products SET stock = stock - ? WHERE id = ?`, + [item.quantity, item.product_id] + ); } // 验证商品状态和库存,计算总价和支付方式 @@ -661,6 +666,11 @@ router.put('/:id/cancel', auth, async (req, res) => { 'UPDATE product_spec_combinations SET stock = stock + ? WHERE id = ?', [orderDetails[0].quantity, orderDetails[0].spec_combination_id] ); + // 返还销售量 + await db.execute( + 'UPDATE products SET stock = stock + ? WHERE id = ?', + [orderDetails[0].quantity, orderDetails[0].product_id] + ); // 更新订单状态 @@ -746,6 +756,10 @@ router.put('/:id/confirm', auth, 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] + ); if (producersResult[0].shop_name) { await getDB().execute( 'UPDATE users SET income = income + ? WHERE id = ?', @@ -1115,7 +1129,7 @@ router.post('/confirm-payment', auth, async (req, res) => { try { await connection.beginTransaction(); - const { orderId: order_id, addressId: address_id, couponRecordId, paymentMethod } = req.body; + const { orderId: order_id, addressId: address_id, couponRecordId, paymentMethod, beansAmount, pointsAmount } = req.body; const userId = req.user.id; // 验证必填字段 @@ -1389,6 +1403,20 @@ router.post('/confirm-payment', auth, async (req, res) => { ); } + if (beansAmount > 0) { + await connection.execute( + 'UPDATE orders SET real_rongdou = ? WHERE id = ?', + [beansAmount, order_id] + ); + } + + if (pointsAmount > 0) { + await connection.execute( + 'UPDATE orders SET real_points = ? WHERE id = ?', + [pointsAmount, order_id] + ); + } + // 更新订单状态和收货地址 const addressStr = JSON.stringify({ recipient_name: address.receiver_name,