bug修复
This commit is contained in:
132
routes/cart.js
132
routes/cart.js
@@ -473,71 +473,6 @@ router.put('/:id', auth, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/cart/{id}:
|
|
||||||
* delete:
|
|
||||||
* summary: 删除购物车商品
|
|
||||||
* tags: [Cart]
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* parameters:
|
|
||||||
* - in: path
|
|
||||||
* name: id
|
|
||||||
* required: true
|
|
||||||
* schema:
|
|
||||||
* type: integer
|
|
||||||
* description: 购物车项ID
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: 删除购物车商品成功
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* success:
|
|
||||||
* type: boolean
|
|
||||||
* message:
|
|
||||||
* type: string
|
|
||||||
* 401:
|
|
||||||
* description: 未授权
|
|
||||||
* 404:
|
|
||||||
* description: 购物车项不存在
|
|
||||||
* 500:
|
|
||||||
* description: 服务器错误
|
|
||||||
*/
|
|
||||||
router.delete('/:id', auth, async (req, res) => {
|
|
||||||
try {
|
|
||||||
const cartItemId = req.params.id;
|
|
||||||
const userId = req.user.id;
|
|
||||||
|
|
||||||
// 检查购物车项是否存在且属于当前用户
|
|
||||||
const [cartItems] = await getDB().execute(
|
|
||||||
'SELECT id FROM cart_items WHERE id = ? AND user_id = ?',
|
|
||||||
[cartItemId, userId]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (cartItems.length === 0) {
|
|
||||||
return res.status(404).json({ success: false, message: '购物车项不存在' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除购物车项
|
|
||||||
await getDB().execute(
|
|
||||||
'DELETE FROM cart_items WHERE id = ?',
|
|
||||||
[cartItemId]
|
|
||||||
);
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
success: true,
|
|
||||||
message: '删除购物车商品成功'
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('删除购物车商品失败:', error);
|
|
||||||
res.status(500).json({ success: false, message: '删除购物车商品失败' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* /api/cart/batch:
|
* /api/cart/batch:
|
||||||
@@ -654,6 +589,7 @@ router.delete('/clear', auth, async (req, res) => {
|
|||||||
success: true,
|
success: true,
|
||||||
message: '清空购物车成功'
|
message: '清空购物车成功'
|
||||||
});
|
});
|
||||||
|
console.log(11111111111111)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('清空购物车失败:', error);
|
console.error('清空购物车失败:', error);
|
||||||
res.status(500).json({ success: false, message: '清空购物车失败' });
|
res.status(500).json({ success: false, message: '清空购物车失败' });
|
||||||
@@ -932,4 +868,70 @@ router.post('/checkout', auth, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/cart/{id}:
|
||||||
|
* delete:
|
||||||
|
* summary: 删除购物车商品
|
||||||
|
* tags: [Cart]
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* parameters:
|
||||||
|
* - in: path
|
||||||
|
* name: id
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: integer
|
||||||
|
* description: 购物车项ID
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 删除购物车商品成功
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* success:
|
||||||
|
* type: boolean
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* 401:
|
||||||
|
* description: 未授权
|
||||||
|
* 404:
|
||||||
|
* description: 购物车项不存在
|
||||||
|
* 500:
|
||||||
|
* description: 服务器错误
|
||||||
|
*/
|
||||||
|
router.delete('/:id', auth, async (req, res) => {
|
||||||
|
try {
|
||||||
|
console.log(111111111)
|
||||||
|
const cartItemId = req.params.id;
|
||||||
|
const userId = req.user.id;
|
||||||
|
|
||||||
|
// 检查购物车项是否存在且属于当前用户
|
||||||
|
const [cartItems] = await getDB().execute(
|
||||||
|
'SELECT id FROM cart_items WHERE id = ? AND user_id = ?',
|
||||||
|
[cartItemId, userId]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (cartItems.length === 0) {
|
||||||
|
return res.status(404).json({ success: false, message: '购物车项不存在' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除购物车项
|
||||||
|
await getDB().execute(
|
||||||
|
'DELETE FROM cart_items WHERE id = ?',
|
||||||
|
[cartItemId]
|
||||||
|
);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
message: '删除购物车商品成功'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('删除购物车商品失败:', error);
|
||||||
|
res.status(500).json({ success: false, message: '删除购物车商品失败' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -496,20 +496,23 @@ router.post('/create-from-cart', auth, async (req, res) => {
|
|||||||
totalAmount += finalPrice * item.quantity;
|
totalAmount += finalPrice * item.quantity;
|
||||||
|
|
||||||
// 根据支付方式计算积分和融豆需求
|
// 根据支付方式计算积分和融豆需求
|
||||||
const hasPoints = productPaymentMethods.includes('points') || productPaymentMethods.includes('points_rongdou');
|
// const hasPoints = productPaymentMethods.includes('points') || productPaymentMethods.includes('points_rongdou');
|
||||||
const hasRongdou = productPaymentMethods.includes('rongdou') || productPaymentMethods.includes('points_rongdou');
|
// const hasRongdou = productPaymentMethods.includes('rongdou') || productPaymentMethods.includes('points_rongdou');
|
||||||
|
|
||||||
if (hasPoints && !hasRongdou) {
|
// if (hasPoints && !hasRongdou) {
|
||||||
// 仅积分支付:按10000积分=1融豆计算
|
// // 仅积分支付:按10000积分=1融豆计算
|
||||||
totalPoints += finalRongdouPrice * item.quantity * 10000;
|
// totalPoints += finalRongdouPrice * item.quantity * 10000;
|
||||||
totalRongdou += finalRongdouPrice * item.quantity;
|
// totalRongdou += finalRongdouPrice * item.quantity;
|
||||||
} else if (!hasPoints && hasRongdou) {
|
// } else if (!hasPoints && hasRongdou) {
|
||||||
// 仅融豆支付
|
// // 仅融豆支付
|
||||||
totalRongdou += finalRongdouPrice * item.quantity;
|
// totalRongdou += finalRongdouPrice * item.quantity;
|
||||||
} else {
|
// } else {
|
||||||
// 组合支付或默认:记录融豆价格,前端可选择支付方式
|
// // 组合支付或默认:记录融豆价格,前端可选择支付方式
|
||||||
totalRongdou += finalRongdouPrice * item.quantity;
|
// totalRongdou += finalRongdouPrice * item.quantity;
|
||||||
}
|
// }
|
||||||
|
totalPoints += item.points_price * item.quantity;
|
||||||
|
totalRongdou += item.rongdou_price * item.quantity;
|
||||||
|
// console.log(1111,item)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去重支付方式
|
// 去重支付方式
|
||||||
@@ -1176,6 +1179,8 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
|||||||
}
|
}
|
||||||
user.balance = Math.abs(user.balance);
|
user.balance = Math.abs(user.balance);
|
||||||
|
|
||||||
|
console.log(123456,paymentMethod)
|
||||||
|
|
||||||
// 开始扣钱
|
// 开始扣钱
|
||||||
switch (paymentMethod) {
|
switch (paymentMethod) {
|
||||||
case 'points':
|
case 'points':
|
||||||
@@ -1184,6 +1189,7 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
|||||||
await connection.rollback();
|
await connection.rollback();
|
||||||
return res.status(400).json({ success: false, message: '积分不足' });
|
return res.status(400).json({ success: false, message: '积分不足' });
|
||||||
}
|
}
|
||||||
|
console.log(1234567,paymentMethod,userId,order.total_points)
|
||||||
await connection.execute(
|
await connection.execute(
|
||||||
'UPDATE users SET points = points - ? WHERE id = ?',
|
'UPDATE users SET points = points - ? WHERE id = ?',
|
||||||
[order.total_points, userId]
|
[order.total_points, userId]
|
||||||
|
|||||||
Reference in New Issue
Block a user