|
|
|
@ -824,7 +824,7 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
let connection; |
|
|
|
try { |
|
|
|
connection = await pool.getConnection(); |
|
|
|
const { productName, price, costprice, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category, producting } = req.body; |
|
|
|
const { productName, costprice, quantity, grossWeight, yolk, specification, quality, region, imageUrls, sellerId, supplyStatus, description, sourceType, contactId, category, producting } = req.body; |
|
|
|
|
|
|
|
// 开始事务
|
|
|
|
await connection.beginTransaction(); |
|
|
|
@ -919,7 +919,7 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
sellerId: sellerId, // 使用前端传入的sellerId
|
|
|
|
productName, |
|
|
|
category: category || '', // 添加种类
|
|
|
|
price: (price || '').toString(), // 确保是varchar类型
|
|
|
|
// 不再使用price字段,移除price字段
|
|
|
|
costprice: costprice || '', // 添加采购价
|
|
|
|
quantity: quantity, // 保持为逗号分隔的字符串,不转换为整数
|
|
|
|
grossWeight, |
|
|
|
@ -952,18 +952,18 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
|
|
|
|
if (columns.length === 0) { |
|
|
|
// 没有quality字段,不包含quality字段的插入
|
|
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, freshness, 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, freshness, 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 || '', req.body.freshness || '', (price || '').toString(), costprice || '', quantity, grossWeight, |
|
|
|
productId, productData.sellerId, productName, category || '', req.body.freshness || '', 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, freshness, 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|
|
|
insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, freshness, 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 || '', req.body.freshness || '', (price || '').toString(), costprice || '', quantity, grossWeight, |
|
|
|
productId, productData.sellerId, productName, category || '', req.body.freshness || '', 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 // 添加联系人信息和自动下架时间、小时数
|
|
|
|
@ -993,7 +993,7 @@ app.post('/api/supplies/create', async (req, res) => { |
|
|
|
productId: productId, |
|
|
|
productName, |
|
|
|
category: category || '', |
|
|
|
price: (price || '').toString(), |
|
|
|
// 不再使用price字段,移除price字段
|
|
|
|
costprice: costprice || '', |
|
|
|
quantity, |
|
|
|
grossWeight, |
|
|
|
@ -1160,9 +1160,9 @@ app.post('/api/supplies/:id/unpublish', async (req, res) => { |
|
|
|
return sendResponse(res, false, null, '货源不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新状态为已下架
|
|
|
|
// 更新状态为已下架,并将标签设置为已锁定
|
|
|
|
await connection.query( |
|
|
|
'UPDATE products SET status = ?, updated_at = NOW() WHERE id = ?', |
|
|
|
'UPDATE products SET status = ?, label = 1, updated_at = NOW() WHERE id = ?', |
|
|
|
['sold_out', productId] |
|
|
|
); |
|
|
|
|
|
|
|
@ -1356,7 +1356,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
try { |
|
|
|
const connection = await pool.getConnection(); |
|
|
|
const productId = req.params.id; |
|
|
|
const { productName, price, costprice, quantity, grossWeight, yolk, specification, supplyStatus, description, region, contactId, producting, imageUrls, autoOfflineTime, category, sourceType, freshness, autoOfflineHours } = req.body; |
|
|
|
const { productName, costprice, quantity, grossWeight, yolk, specification, supplyStatus, description, region, contactId, producting, imageUrls, autoOfflineTime, category, sourceType, freshness, autoOfflineHours } = req.body; |
|
|
|
|
|
|
|
// 开始事务
|
|
|
|
await connection.beginTransaction(); |
|
|
|
@ -1484,7 +1484,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
// 打印用于调试的更新参数
|
|
|
|
console.log('更新参数调试:'); |
|
|
|
console.log('productName:', productName); |
|
|
|
console.log('price:', (price || '').toString()); |
|
|
|
// 不再使用price字段,移除price调试日志
|
|
|
|
console.log('costprice:', costprice || ''); |
|
|
|
console.log('quantityValue:', quantityValue); |
|
|
|
console.log('grossWeight:', grossWeight); |
|
|
|
@ -1507,7 +1507,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
// 更新货源信息
|
|
|
|
const updateQuery = ` |
|
|
|
UPDATE products |
|
|
|
SET productName = ?, price = ?, costprice = ?, quantity = ?, grossWeight = ?, |
|
|
|
SET productName = ?, costprice = ?, quantity = ?, grossWeight = ?, |
|
|
|
yolk = ?, specification = ?, producting = ?, supplyStatus = ?, description = ?, region = ?, |
|
|
|
category = ?, sourceType = ?, freshness = ?, |
|
|
|
product_contact = ?, contact_phone = ?, imageUrls = ?, |
|
|
|
@ -1516,7 +1516,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
`;
|
|
|
|
|
|
|
|
const [result] = await connection.query(updateQuery, [ |
|
|
|
productName, (price || '').toString(), costprice || '', quantityValue, grossWeight, |
|
|
|
productName, costprice || '', quantityValue, grossWeight, |
|
|
|
yolk, specification, producting, supplyStatus, description, region, |
|
|
|
category, sourceType, freshness, |
|
|
|
productContact, contactPhone, imageUrlsToUpdate, |
|
|
|
@ -1540,7 +1540,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
data: { |
|
|
|
id: productId, |
|
|
|
productName, |
|
|
|
price: (price || '').toString(), |
|
|
|
// 不再使用price字段,移除price字段
|
|
|
|
costprice: costprice || '', |
|
|
|
quantity, |
|
|
|
grossWeight, |
|
|
|
|