|
|
|
@ -644,6 +644,10 @@ User.init({ |
|
|
|
partnerstatus: { |
|
|
|
type: DataTypes.STRING(255) // 合作商状态
|
|
|
|
}, |
|
|
|
// 授权区域字段 - 用于存储用户位置信息
|
|
|
|
authorized_region: { |
|
|
|
type: DataTypes.TEXT // 存储用户位置信息的JSON字符串
|
|
|
|
}, |
|
|
|
reasonforfailure: { |
|
|
|
type: DataTypes.TEXT // 审核失败原因
|
|
|
|
}, |
|
|
|
@ -1188,12 +1192,17 @@ app.post('/api/user/upload', async (req, res) => { |
|
|
|
console.log('收到用户信息上传请求:', userData); |
|
|
|
|
|
|
|
// 使用微信小程序拉取唯一电话号码的插件,不再需要检查手机号冲突
|
|
|
|
// 确保用户数据中包含手机号
|
|
|
|
if (!userData.phoneNumber) { |
|
|
|
// 检查用户是否已存在,如果是更新操作,不需要强制要求手机号
|
|
|
|
let existingUser = await User.findOne({ |
|
|
|
where: { openid: userData.openid } |
|
|
|
}); |
|
|
|
|
|
|
|
// 只有在创建新用户时才强制要求手机号
|
|
|
|
if (!existingUser && !userData.phoneNumber) { |
|
|
|
return res.json({ |
|
|
|
success: false, |
|
|
|
code: 400, |
|
|
|
message: '缺少手机号信息', |
|
|
|
message: '创建新用户时必须提供手机号信息', |
|
|
|
data: {} |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -1509,7 +1518,8 @@ app.post('/api/user/get', async (req, res) => { |
|
|
|
const user = await User.findOne({ |
|
|
|
where: { openid }, |
|
|
|
include: [ |
|
|
|
{ model: Contact, |
|
|
|
{ |
|
|
|
model: Contact, |
|
|
|
as: 'contacts', |
|
|
|
attributes: ['id', 'name', 'phoneNumber', 'wechat', 'account', 'accountNumber', 'bank', 'address'] |
|
|
|
}, |
|
|
|
@ -1859,13 +1869,13 @@ app.post('/api/products/upload', upload.array('images', 10), async (req, res) => |
|
|
|
return await handleAddImagesToExistingProduct(req, res, existingProductId, req.files || []); |
|
|
|
} |
|
|
|
|
|
|
|
let productData; |
|
|
|
let uploadedFiles = req.files || []; // 修复:使用req.files而不是空数组
|
|
|
|
let imageUrls = []; |
|
|
|
let product; |
|
|
|
let tempFilesToClean = []; // 存储需要清理的临时文件路径
|
|
|
|
let productData; |
|
|
|
let uploadedFiles = req.files || []; // 修复:使用req.files而不是空数组
|
|
|
|
let imageUrls = []; |
|
|
|
let product; |
|
|
|
let tempFilesToClean = []; // 存储需要清理的临时文件路径
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
// 【关键修复】首先检查是否是仅上传图片到已存在商品的请求
|
|
|
|
const isAddImagesOnly = req.body.action === 'add_images_only' || req.body.isUpdate === 'true'; |
|
|
|
const existingProductId = req.body.productId; |
|
|
|
@ -3144,7 +3154,7 @@ try { |
|
|
|
|
|
|
|
// 发送最终增强的响应
|
|
|
|
res.status(200).json(customResponseData); |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
console.error('【错误】在添加商品时出错:', err); |
|
|
|
res.status(500).json({ |
|
|
|
success: false, |
|
|
|
@ -3152,7 +3162,7 @@ try { |
|
|
|
code: 500, |
|
|
|
error: err.message |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 【关键修复】在 handleAddImagesToExistingProduct 函数中加强图片合并逻辑
|
|
|
|
@ -8292,10 +8302,10 @@ updateProductContacts().then(() => { |
|
|
|
// 启动服务器监听 - 使用配置好的http server对象
|
|
|
|
// 监听0.0.0.0以允许通过所有网络接口访问(包括IPv4地址)
|
|
|
|
// 启动连接监控
|
|
|
|
startConnectionMonitoring(); |
|
|
|
console.log('连接监控服务已启动'); |
|
|
|
startConnectionMonitoring(); |
|
|
|
console.log('连接监控服务已启动'); |
|
|
|
|
|
|
|
server.listen(PORT, '0.0.0.0', () => { |
|
|
|
server.listen(PORT, '0.0.0.0', () => { |
|
|
|
console.log(`\n🚀 服务器启动成功,监听端口 ${PORT}`); |
|
|
|
console.log(`API 服务地址: http://localhost:${PORT}`); |
|
|
|
console.log(`API 通过IP访问地址: http://192.168.0.98:${PORT}`); |
|
|
|
|