diff --git a/routes/orders.js b/routes/orders.js index 8f82071..141ff67 100644 --- a/routes/orders.js +++ b/routes/orders.js @@ -1061,7 +1061,7 @@ router.post('/confirm-payment', auth, async (req, res) => { try { await connection.beginTransaction(); - const { orderId: order_id, addressId: address_id } = req.body; + const { orderId: order_id, addressId: address_id, couponRecordId } = req.body; const userId = req.user.id; // 验证必填字段 @@ -1090,7 +1090,7 @@ router.post('/confirm-payment', auth, async (req, res) => { // 解析支付方式 let allPaymentMethods = []; - console.log(typeof order.payment_methods_list); + // console.log(typeof order.payment_methods_list); if (order.payment_methods_list) { try { @@ -1222,6 +1222,14 @@ router.post('/confirm-payment', auth, async (req, res) => { ); } + // 更新优惠券记录 + if (couponRecordId) { + await connection.execute( + 'UPDATE coupon_use SET use_time = NOW(), order_id = ? WHERE id = ?', + [order_id, couponRecordId] + ); + } + // 更新订单状态和收货地址 const addressStr = JSON.stringify({ recipient_name: address.receiver_name, @@ -1238,6 +1246,12 @@ router.post('/confirm-payment', auth, async (req, res) => { [addressStr, order_id] ); + // 减组合库存 + // await connection.execute( + // 'UPDATE product_spec_combinations SET stock = stock - 1 WHERE id = ?', + // [order.product_combination_id] + // ); + await connection.commit(); res.json({ diff --git a/routes/products.js b/routes/products.js index aaa8924..bad609e 100644 --- a/routes/products.js +++ b/routes/products.js @@ -39,7 +39,7 @@ router.get('/', async (req, res) => { // 获取商品列表 const query = ` - SELECT id, name, rongdou_price, points_price, stock, image_url as image, description, status, payment_methods, created_at, updated_at, sales + SELECT id, name, rongdou_price, points_price, stock, image_url as image, description, status, payment_methods, created_at, updated_at, sales, images FROM products ${whereClause} ORDER BY created_at DESC @@ -53,6 +53,7 @@ router.get('/', async (req, res) => { products.forEach(item=>{ item.payment_methods = JSON.parse(item.payment_methods) + item.images = JSON.parse(item.images) }) @@ -1018,7 +1019,6 @@ router.get('/:id/recommended', async (req, res) => { 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} `;