解决创建商品时规格组合选择问题
This commit is contained in:
@@ -420,7 +420,7 @@ router.put('/combinations/:id', async (req, res) => {
|
||||
barcode,
|
||||
weight,
|
||||
volume,
|
||||
is_available
|
||||
status
|
||||
} = req.body;
|
||||
|
||||
// 检查规格组合是否存在
|
||||
@@ -477,9 +477,9 @@ router.put('/combinations/:id', async (req, res) => {
|
||||
updateValues.push(volume);
|
||||
}
|
||||
|
||||
if (is_available !== undefined) {
|
||||
if (status !== undefined) {
|
||||
updateFields.push('status = ?');
|
||||
updateValues.push(is_available ? 'active' : 'inactive');
|
||||
updateValues.push(status);
|
||||
}
|
||||
|
||||
if (updateFields.length === 0) {
|
||||
@@ -648,9 +648,34 @@ router.post('/generate-combinations', async (req, res) => {
|
||||
const values = [];
|
||||
const placeholders = [];
|
||||
|
||||
const createProduct = `
|
||||
INSERT INTO products (name, price)
|
||||
VALUES ('temp', 0)
|
||||
`
|
||||
const deleteProduct = `
|
||||
DELETE FROM products WHERE name = 'temp'
|
||||
`
|
||||
var newProductId = null;
|
||||
if (product_id === 'new') {
|
||||
|
||||
await getDB().execute(deleteProduct);
|
||||
await getDB().execute(createProduct);
|
||||
|
||||
// const deleteProduct = `
|
||||
// DELETE FROM products WHERE name = 'temp'
|
||||
// `
|
||||
// await getDB().execute(deleteProduct);
|
||||
|
||||
const getProductId = `
|
||||
SELECT id FROM products WHERE name = 'temp'
|
||||
`
|
||||
const [productResult] = await getDB().execute(getProductId);
|
||||
newProductId = productResult[0].id;
|
||||
}
|
||||
|
||||
newCombinations.forEach(item => {
|
||||
values.push(
|
||||
product_id,
|
||||
newProductId === null ? product_id : newProductId,
|
||||
item.key,
|
||||
JSON.stringify(item.combination),
|
||||
default_stock
|
||||
@@ -672,7 +697,8 @@ router.post('/generate-combinations', async (req, res) => {
|
||||
data: {
|
||||
total_combinations: combinations.length,
|
||||
created: createdCount,
|
||||
skipped: skippedCount
|
||||
skipped: skippedCount,
|
||||
product_id: newProductId === null ? product_id : newProductId
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user