|
|
|
@ -3,6 +3,7 @@ const bodyParser = require('body-parser'); |
|
|
|
const cors = require('cors'); |
|
|
|
const mysql = require('mysql2/promise'); |
|
|
|
const path = require('path'); |
|
|
|
const OssUploader = require('./oss-uploader'); |
|
|
|
const app = express(); |
|
|
|
const PORT = 3000; |
|
|
|
|
|
|
|
@ -714,8 +715,6 @@ app.post('/api/suppliers/:id/terminate', async (req, res) => { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 导入OSS上传工具
|
|
|
|
const OssUploader = require('./oss-uploader'); |
|
|
|
// 导入图片处理工具
|
|
|
|
const ImageProcessor = require('./image-processor'); |
|
|
|
|
|
|
|
@ -1170,9 +1169,9 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理媒体文件上传(图片和视频)
|
|
|
|
let uploadedImageUrls = []; |
|
|
|
const { imageUrls } = req.body; |
|
|
|
if (Array.isArray(imageUrls) && imageUrls.length > 0) { |
|
|
|
console.log('开始处理编辑媒体文件上传,共', imageUrls.length, '个文件'); |
|
|
|
|
|
|
|
@ -1215,20 +1214,27 @@ app.put('/api/supplies/:id/edit', async (req, res) => { |
|
|
|
console.log('媒体文件处理完成,成功上传', uploadedImageUrls.length, '个文件'); |
|
|
|
} |
|
|
|
|
|
|
|
// 如果有新上传的图片,更新imageUrls字段
|
|
|
|
if (uploadedImageUrls.length > 0) { |
|
|
|
await connection.query( |
|
|
|
'UPDATE products SET imageUrls = ? WHERE id = ?', |
|
|
|
[JSON.stringify(uploadedImageUrls), productId] |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新货源信息
|
|
|
|
const updateQuery = ` |
|
|
|
UPDATE products |
|
|
|
SET productName = ?, price = ?, quantity = ?, grossWeight = ?, |
|
|
|
yolk = ?, specification = ?, supplyStatus = ?, description = ?, region = ?, |
|
|
|
producting = ?, product_contact = ?, contact_phone = ?, imageUrls = ? |
|
|
|
producting = ?, product_contact = ?, contact_phone = ? |
|
|
|
WHERE id = ? |
|
|
|
`;
|
|
|
|
|
|
|
|
await connection.query(updateQuery, [ |
|
|
|
productName, price.toString(), parseInt(quantity), grossWeight, |
|
|
|
yolk, specification, supplyStatus, description, region, |
|
|
|
producting, productContact, contactPhone, JSON.stringify(uploadedImageUrls), productId |
|
|
|
producting, productContact, contactPhone, productId |
|
|
|
]); |
|
|
|
|
|
|
|
// 提交事务
|
|
|
|
|