更改商品添加逻辑,新增分佣逻辑

This commit is contained in:
dzl
2025-10-22 17:26:40 +08:00
parent 6d579316b7
commit cb38e0fa3a
2 changed files with 93 additions and 5 deletions

View File

@@ -887,6 +887,30 @@ router.put('/:id/status', async (req, res) => {
);
}
if (status === 'completed') {
const [products] = await getDB().execute(
'SELECT * FROM order_items WHERE order_id = ?',
[orderId]
);
let producers = []
for (const product of products) {
const [producersResult] = await db.execute(
'SELECT * FROM products WHERE id = ?',
[product.product_id]
);
if (producersResult[0].shop_name) {
await db.execute(
'UPDATE users SET income = income + ? WHERE id = ?',
[1, parseInt(producersResult[0].shop_name)]
);
}
}
// await db.execute(
// 'UPDATE users SET income = income + ? WHERE id = ?',
// ['分佣金额', '收到分佣的用户id']
// );
}
await db.query('COMMIT');
res.json({ success: true, message: '订单状态已更新' });