Browse Source

修复autoOfflineTime时间问题:

1. 后端编辑API添加autoOfflineTime字段更新
2. 修复前端时间计算错误(移除错误的+8小时偏移)
3. 后端返回时间字段保持原样不做额外处理
Boss2
Default User 2 months ago
parent
commit
bbf531f356
  1. 5
      Reject.js
  2. 19
      supply.html

5
Reject.js

@ -1353,7 +1353,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, costprice, 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, autoOfflineTime } = req.body;
// 开始事务 // 开始事务
await connection.beginTransaction(); await connection.beginTransaction();
@ -1463,7 +1463,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => {
SET productName = ?, price = ?, costprice = ?, quantity = ?, grossWeight = ?, SET productName = ?, price = ?, costprice = ?, quantity = ?, grossWeight = ?,
yolk = ?, specification = ?, producting = ?, supplyStatus = ?, description = ?, region = ?, yolk = ?, specification = ?, producting = ?, supplyStatus = ?, description = ?, region = ?,
product_contact = ?, contact_phone = ?, imageUrls = ?, product_contact = ?, contact_phone = ?, imageUrls = ?,
autoOfflineHours = ?, updated_at = ? autoOfflineTime = ?, autoOfflineHours = ?, updated_at = ?
WHERE id = ? WHERE id = ?
`; `;
@ -1471,6 +1471,7 @@ app.put('/api/supplies/:id/edit', async (req, res) => {
productName, price.toString(), costprice || '', quantityValue, grossWeight, productName, price.toString(), costprice || '', quantityValue, grossWeight,
yolk, specification, producting, supplyStatus, description, region, yolk, specification, producting, supplyStatus, description, region,
productContact, contactPhone, JSON.stringify(uploadedImageUrls), productContact, contactPhone, JSON.stringify(uploadedImageUrls),
autoOfflineTime || null, // 自动下架时间
req.body.autoOfflineHours || 24, // 默认24小时 req.body.autoOfflineHours || 24, // 默认24小时
new Date(), // 更新updated_at字段 new Date(), // 更新updated_at字段
productId productId

19
supply.html

@ -5944,6 +5944,13 @@
// 计算自动下架时间(当前时间 + 分钟数) // 计算自动下架时间(当前时间 + 分钟数)
const autoOfflineTime = new Date(); const autoOfflineTime = new Date();
autoOfflineTime.setMinutes(autoOfflineTime.getMinutes() + minutes); autoOfflineTime.setMinutes(autoOfflineTime.getMinutes() + minutes);
// 格式化为数据库存储的北京时间格式 (YYYY-MM-DD HH:mm:ss)
const autoOfflineTimeStr = autoOfflineTime.getFullYear() + '-' +
String(autoOfflineTime.getMonth() + 1).padStart(2, '0') + '-' +
String(autoOfflineTime.getDate()).padStart(2, '0') + ' ' +
String(autoOfflineTime.getHours()).padStart(2, '0') + ':' +
String(autoOfflineTime.getMinutes()).padStart(2, '0') + ':' +
String(autoOfflineTime.getSeconds()).padStart(2, '0');
const formData = { const formData = {
productName: document.getElementById('productName').value, productName: document.getElementById('productName').value,
@ -5966,7 +5973,7 @@
sellerId: userInfo.userId, // 添加当前登录用户的userId作为sellerId sellerId: userInfo.userId, // 添加当前登录用户的userId作为sellerId
autoOfflineDays: null, // 不再使用天数,设置为null autoOfflineDays: null, // 不再使用天数,设置为null
autoOfflineHours: autoOfflineHours, autoOfflineHours: autoOfflineHours,
autoOfflineTime: autoOfflineTime.toISOString() autoOfflineTime: autoOfflineTimeStr
}; };
// 验证表单 // 验证表单
@ -7785,7 +7792,13 @@
// 计算自动下架时间(当前时间 + 分钟数) // 计算自动下架时间(当前时间 + 分钟数)
const autoOfflineTime = new Date(); const autoOfflineTime = new Date();
autoOfflineTime.setMinutes(autoOfflineTime.getMinutes() + minutes); autoOfflineTime.setMinutes(autoOfflineTime.getMinutes() + minutes);
const autoOfflineTimeISO = autoOfflineTime.toISOString(); // 格式化为数据库存储的北京时间格式 (YYYY-MM-DD HH:mm:ss)
const autoOfflineTimeStr = autoOfflineTime.getFullYear() + '-' +
String(autoOfflineTime.getMonth() + 1).padStart(2, '0') + '-' +
String(autoOfflineTime.getDate()).padStart(2, '0') + ' ' +
String(autoOfflineTime.getHours()).padStart(2, '0') + ':' +
String(autoOfflineTime.getMinutes()).padStart(2, '0') + ':' +
String(autoOfflineTime.getSeconds()).padStart(2, '0');
const formData = { const formData = {
productName: document.getElementById('editProductName').value, productName: document.getElementById('editProductName').value,
@ -7805,7 +7818,7 @@
contactId: document.getElementById('editContactId').value, contactId: document.getElementById('editContactId').value,
freshness: document.getElementById('editFreshness').value, freshness: document.getElementById('editFreshness').value,
imageUrls: editCurrentImages, // 添加编辑后的图片列表 imageUrls: editCurrentImages, // 添加编辑后的图片列表
autoOfflineTime: autoOfflineTimeISO, // 自动下架时间 autoOfflineTime: autoOfflineTimeStr, // 自动下架时间
autoOfflineDays: null, // 不再使用天数,设置为null autoOfflineDays: null, // 不再使用天数,设置为null
autoOfflineHours: autoOfflineHours // 自动下架小时数(分钟转换而来) autoOfflineHours: autoOfflineHours // 自动下架小时数(分钟转换而来)
}; };

Loading…
Cancel
Save