更改商品添加逻辑,新增分佣逻辑
This commit is contained in:
@@ -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: '订单状态已更新' });
|
||||
|
||||
Reference in New Issue
Block a user