|
|
|
@ -706,7 +706,7 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
let connection; |
|
|
|
try { |
|
|
|
connection = await pool.getConnection(); |
|
|
|
const { productName, price, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category, producting } = req.body; |
|
|
|
const { productName, price, costprice, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category, producting } = req.body; |
|
|
|
|
|
|
|
// 开始事务
|
|
|
|
await connection.beginTransaction(); |
|
|
|
@ -800,6 +800,7 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
productName, |
|
|
|
category: category || '', // 添加种类
|
|
|
|
price: price.toString(), // 确保是varchar类型
|
|
|
|
costprice: costprice || '', // 添加采购价
|
|
|
|
quantity: quantity, // 保持为逗号分隔的字符串,不转换为整数
|
|
|
|
grossWeight, |
|
|
|
yolk, |
|
|
|
@ -831,18 +832,18 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
|
|
|
|
if (columns.length === 0) { |
|
|
|
// 没有quality字段,不包含quality字段的插入
|
|
|
|
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, autoOfflineTime, autoOfflineDays, autoOfflineHours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, costprice, quantity, grossWeight, yolk, specification, producting, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone, autoOfflineTime, autoOfflineDays, autoOfflineHours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
|
insertParams = [ |
|
|
|
productId, productData.sellerId, productName, category || '', price.toString(), quantity, grossWeight, |
|
|
|
productId, productData.sellerId, productName, category || '', price.toString(), costprice || '', quantity, grossWeight, |
|
|
|
yolk, specification, producting, region, productData.status, productData.supplyStatus, productData.sourceType, |
|
|
|
productData.description, productData.rejectReason, productData.imageUrls, new Date(), new Date(), |
|
|
|
productContact, contactPhone, req.body.autoOfflineTime, req.body.autoOfflineDays, req.body.autoOfflineHours // 添加联系人信息和自动下架时间、小时数
|
|
|
|
]; |
|
|
|
} else { |
|
|
|
// 有quality字段,包含quality字段的插入
|
|
|
|
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, autoOfflineTime, autoOfflineDays, autoOfflineHours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, costprice, quantity, grossWeight, yolk, specification, producting, quality, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone, autoOfflineTime, autoOfflineDays, autoOfflineHours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
|
insertParams = [ |
|
|
|
productId, productData.sellerId, productName, category || '', price.toString(), quantity, grossWeight, |
|
|
|
productId, productData.sellerId, productName, category || '', price.toString(), costprice || '', quantity, grossWeight, |
|
|
|
yolk, specification, producting, quality, region, productData.status, productData.supplyStatus, |
|
|
|
productData.sourceType, productData.description, productData.rejectReason, productData.imageUrls, |
|
|
|
new Date(), new Date(), productContact, contactPhone, req.body.autoOfflineTime, req.body.autoOfflineDays, req.body.autoOfflineHours // 添加联系人信息和自动下架时间、小时数
|
|
|
|
@ -1097,7 +1098,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
try { |
|
|
|
const connection = await pool.getConnection(); |
|
|
|
const productId = req.params.id; |
|
|
|
const { productName, price, quantity, grossWeight, yolk, specification, supplyStatus, description, region, contactId, producting, imageUrls } = req.body; |
|
|
|
const { productName, price, costprice, quantity, grossWeight, yolk, specification, supplyStatus, description, region, contactId, producting, imageUrls } = req.body; |
|
|
|
|
|
|
|
// 开始事务
|
|
|
|
await connection.beginTransaction(); |
|
|
|
@ -1179,7 +1180,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
// 更新货源信息
|
|
|
|
const updateQuery = ` |
|
|
|
UPDATE products |
|
|
|
SET productName = ?, price = ?, quantity = ?, grossWeight = ?, |
|
|
|
SET productName = ?, price = ?, costprice = ?, quantity = ?, grossWeight = ?, |
|
|
|
yolk = ?, specification = ?, producting = ?, supplyStatus = ?, description = ?, region = ?, |
|
|
|
product_contact = ?, contact_phone = ?, imageUrls = ?, |
|
|
|
autoOfflineHours = ?, updated_at = ? |
|
|
|
@ -1187,7 +1188,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
`;
|
|
|
|
|
|
|
|
await connection.query(updateQuery, [ |
|
|
|
productName, price.toString(), quantityValue, grossWeight, |
|
|
|
productName, price.toString(), costprice || '', quantityValue, grossWeight, |
|
|
|
yolk, specification, producting, supplyStatus, description, region, |
|
|
|
productContact, contactPhone, JSON.stringify(uploadedImageUrls), |
|
|
|
req.body.autoOfflineHours || 24, // 默认24小时
|
|
|
|
|