|
|
@ -696,7 +696,7 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
let connection; |
|
|
let connection; |
|
|
try { |
|
|
try { |
|
|
connection = await pool.getConnection(); |
|
|
connection = await pool.getConnection(); |
|
|
const { productName, price, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category } = req.body; |
|
|
const { productName, price, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category, producting } = req.body; |
|
|
|
|
|
|
|
|
// 开始事务
|
|
|
// 开始事务
|
|
|
await connection.beginTransaction(); |
|
|
await connection.beginTransaction(); |
|
|
@ -782,6 +782,7 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
grossWeight, |
|
|
grossWeight, |
|
|
yolk, |
|
|
yolk, |
|
|
specification, |
|
|
specification, |
|
|
|
|
|
producting, |
|
|
quality, |
|
|
quality, |
|
|
region, |
|
|
region, |
|
|
status: 'published', // 直接上架,而不是审核中
|
|
|
status: 'published', // 直接上架,而不是审核中
|
|
|
@ -805,19 +806,19 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
|
|
|
|
|
if (columns.length === 0) { |
|
|
if (columns.length === 0) { |
|
|
// 没有quality字段,不包含quality字段的插入
|
|
|
// 没有quality字段,不包含quality字段的插入
|
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, quantity, grossWeight, yolk, specification, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, quantity, grossWeight, yolk, specification, producting, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
insertParams = [ |
|
|
insertParams = [ |
|
|
productId, productData.sellerId, productName, category || '', price.toString(), parseInt(quantity), grossWeight, |
|
|
productId, productData.sellerId, productName, category || '', price.toString(), parseInt(quantity), grossWeight, |
|
|
yolk, specification, region, productData.status, productData.supplyStatus, productData.sourceType, |
|
|
yolk, specification, producting, region, productData.status, productData.supplyStatus, productData.sourceType, |
|
|
productData.description, productData.rejectReason, productData.imageUrls, new Date(), new Date(), |
|
|
productData.description, productData.rejectReason, productData.imageUrls, new Date(), new Date(), |
|
|
productContact, contactPhone // 添加联系人信息
|
|
|
productContact, contactPhone // 添加联系人信息
|
|
|
]; |
|
|
]; |
|
|
} else { |
|
|
} else { |
|
|
// 有quality字段,包含quality字段的插入
|
|
|
// 有quality字段,包含quality字段的插入
|
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, quantity, grossWeight, yolk, specification, quality, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, quantity, grossWeight, yolk, specification, producting, quality, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
insertParams = [ |
|
|
insertParams = [ |
|
|
productId, productData.sellerId, productName, category || '', price.toString(), parseInt(quantity), grossWeight, |
|
|
productId, productData.sellerId, productName, category || '', price.toString(), parseInt(quantity), grossWeight, |
|
|
yolk, specification, quality, region, productData.status, productData.supplyStatus, |
|
|
yolk, specification, producting, quality, region, productData.status, productData.supplyStatus, |
|
|
productData.sourceType, productData.description, productData.rejectReason, productData.imageUrls, |
|
|
productData.sourceType, productData.description, productData.rejectReason, productData.imageUrls, |
|
|
new Date(), new Date(), productContact, contactPhone // 添加联系人信息
|
|
|
new Date(), new Date(), productContact, contactPhone // 添加联系人信息
|
|
|
]; |
|
|
]; |
|
|
@ -1023,7 +1024,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
try { |
|
|
try { |
|
|
const connection = await pool.getConnection(); |
|
|
const connection = await pool.getConnection(); |
|
|
const productId = req.params.id; |
|
|
const productId = req.params.id; |
|
|
const { productName, price, quantity, grossWeight, yolk, specification, supplyStatus, description, region, contactId } = req.body; |
|
|
const { productName, price, quantity, grossWeight, yolk, specification, supplyStatus, description, region, contactId, producting } = req.body; |
|
|
|
|
|
|
|
|
// 开始事务
|
|
|
// 开始事务
|
|
|
await connection.beginTransaction(); |
|
|
await connection.beginTransaction(); |
|
|
@ -1062,14 +1063,14 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
const updateQuery = ` |
|
|
const updateQuery = ` |
|
|
UPDATE products |
|
|
UPDATE products |
|
|
SET productName = ?, price = ?, quantity = ?, grossWeight = ?, |
|
|
SET productName = ?, price = ?, quantity = ?, grossWeight = ?, |
|
|
yolk = ?, specification = ?, supplyStatus = ?, description = ?, region = ?, |
|
|
yolk = ?, specification = ?, producting = ?, supplyStatus = ?, description = ?, region = ?, |
|
|
product_contact = ?, contact_phone = ? |
|
|
product_contact = ?, contact_phone = ? |
|
|
WHERE id = ? |
|
|
WHERE id = ? |
|
|
`;
|
|
|
`;
|
|
|
|
|
|
|
|
|
await connection.query(updateQuery, [ |
|
|
await connection.query(updateQuery, [ |
|
|
productName, price.toString(), parseInt(quantity), grossWeight, |
|
|
productName, price.toString(), parseInt(quantity), grossWeight, |
|
|
yolk, specification, supplyStatus, description, region, |
|
|
yolk, specification, producting, supplyStatus, description, region, |
|
|
productContact, contactPhone, productId |
|
|
productContact, contactPhone, productId |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
|