bug调整

This commit is contained in:
dzl
2025-10-23 17:26:42 +08:00
parent be8b182e82
commit 2217ccf30c
2 changed files with 36 additions and 4 deletions

View File

@@ -722,7 +722,7 @@ router.put('/:id/confirm', auth, async (req, res) => {
// 检查订单是否存在且属于当前用户
const [orders] = await getDB().execute(
'SELECT id, status FROM orders WHERE id = ? AND user_id = ?',
'SELECT * FROM orders WHERE id = ? AND user_id = ?',
[orderId, userId]
);
@@ -736,6 +736,24 @@ router.put('/:id/confirm', auth, async (req, res) => {
return res.status(400).json({ success: false, message: '只能确认已发货的订单' });
}
// 佣金分配
const [products] = await getDB().execute(
'SELECT * FROM order_items WHERE order_id = ?',
[orderId]
);
for (const product of products) {
const [producersResult] = await getDB().execute(
'SELECT * FROM products WHERE id = ?',
[product.product_id]
);
if (producersResult[0].shop_name) {
await getDB().execute(
'UPDATE users SET income = income + ? WHERE id = ?',
[producersResult[0].price * product.quantity, parseInt(producersResult[0].shop_name)]
);
}
}
// 更新订单状态
await getDB().execute(
'UPDATE orders SET status = "completed", updated_at = NOW() WHERE id = ?',