Browse Source

修复编辑失败问题,移除调试日志中未定义的price变量;下架货源时自动锁死货源

Boss3
Default User 2 months ago
parent
commit
1eca4b96b0
  1. 28
      Reject.js
  2. 9
      supply.html

28
Reject.js

@ -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,

9
supply.html

@ -4923,8 +4923,9 @@
resetForm();
// 填充表单字段 - 为所有元素添加null检查
// 不填充销售价格,因为现在不再使用
const priceInput = document.getElementById('price');
if (priceInput) priceInput.value = supply.price || '';
if (priceInput) priceInput.value = '';
const quantityInput = document.getElementById('quantity');
if (quantityInput) quantityInput.value = supply.quantity || '';
@ -5798,7 +5799,7 @@
productName: productName ? productName.value : '',
category: category ? category.value : '',
freshness: freshness ? freshness.value : '',
price: price ? price.value : '',
// 不再使用销售价格,移除price字段
quantity: quantity ? quantity.value : '',
grossWeight: grossWeight ? grossWeight.value : '',
yolk: yolk ? yolk.value : '',
@ -6110,7 +6111,7 @@
const formData = {
productName: document.getElementById('productName').value,
category: document.getElementById('category').value,
price: document.getElementById('price').value,
// 不再使用销售价格,移除price字段
costprice: costprices.join(','), // 将采购价以英文逗号分隔的字符串形式提交
quantity: quantities.join(','), // 将件数以英文逗号分隔的字符串形式提交
@ -7973,7 +7974,7 @@
productName: document.getElementById('editProductName').value,
sourceType: document.getElementById('editSourceType').value,
category: document.getElementById('editCategory').value,
price: document.getElementById('editPrice').value,
// 不再使用销售价格,移除price字段
costprice: costprices.join(','), // 将采购价以英文逗号分隔的字符串形式提交
quantity: quantities.join(','), // 将件数以英文逗号分隔的字符串形式提交

Loading…
Cancel
Save