完善库存算法,修复bug
This commit is contained in:
@@ -841,6 +841,27 @@ router.put('/:id/status', async (req, res) => {
|
||||
|
||||
const order = orders[0];
|
||||
|
||||
const [orderItems] = await db.execute(
|
||||
'SELECT * FROM order_items WHERE order_id = ?',
|
||||
[orderId]
|
||||
);
|
||||
if (status === 'cancelled') {
|
||||
// 增加商品库存
|
||||
for (const item of orderItems) {
|
||||
await db.execute(
|
||||
'UPDATE products SET stock = stock + ? WHERE id = ?',
|
||||
[item.quantity, item.product_id]
|
||||
);
|
||||
await db.execute(
|
||||
'UPDATE product_spec_combinations SET stock = stock + ? WHERE id = ?',
|
||||
[item.quantity, item.spec_combination_id]
|
||||
)
|
||||
}
|
||||
}
|
||||
// console.log(111,order,orderItems)
|
||||
|
||||
|
||||
|
||||
// 如果是取消订单,需要退还积分和融豆
|
||||
if (status === 'cancelled' && order.status !== 'cancelled' && order.status !== 'pre_order') {
|
||||
// 退还用户积分
|
||||
@@ -898,6 +919,14 @@ router.put('/:id/status', async (req, res) => {
|
||||
'SELECT * FROM products WHERE id = ?',
|
||||
[product.product_id]
|
||||
);
|
||||
await getDB().execute(
|
||||
'UPDATE products SET sales = sales + ? WHERE id = ?',
|
||||
[product.quantity, product.product_id]
|
||||
);
|
||||
await getDB().execute(
|
||||
'UPDATE products SET stock = stock - ? WHERE id = ?',
|
||||
[product.quantity, product.product_id]
|
||||
);
|
||||
if (producersResult[0].shop_name) {
|
||||
await db.execute(
|
||||
'UPDATE users SET income = income + ? WHERE id = ?',
|
||||
|
||||
@@ -673,7 +673,7 @@ router.put('/:id', async (req, res) => {
|
||||
updateValues.push(status);
|
||||
}
|
||||
|
||||
if (sale_price !== null) {
|
||||
if (sale_price !== undefined) {
|
||||
updateFields.push('sale_price = ?');
|
||||
updateValues.push(sale_price);
|
||||
console.log(12345,sale_price)
|
||||
|
||||
Reference in New Issue
Block a user