|
|
|
@ -1212,20 +1212,41 @@ app.post('/api/user/upload', async (req, res) => { |
|
|
|
where: { openid: userData.openid } |
|
|
|
}); |
|
|
|
|
|
|
|
// 详细日志记录收到的位置数据
|
|
|
|
console.log('处理位置数据前:', { |
|
|
|
authorized_region: userData.authorized_region, |
|
|
|
type: typeof userData.authorized_region, |
|
|
|
isObject: typeof userData.authorized_region === 'object', |
|
|
|
hasLatLng: userData.authorized_region && (userData.authorized_region.latitude || userData.authorized_region.longitude) |
|
|
|
}); |
|
|
|
|
|
|
|
if (user) { |
|
|
|
// 更新用户信息,确保authorized_region字段正确处理
|
|
|
|
const updateData = { ...userData, updated_at: getBeijingTime() }; |
|
|
|
|
|
|
|
// 特别处理authorized_region字段,如果是对象则转换为JSON字符串
|
|
|
|
|
|
|
|
// 特别处理authorized_region字段,只有当它是对象时才转换为JSON字符串
|
|
|
|
if (updateData.authorized_region && typeof updateData.authorized_region === 'object') { |
|
|
|
updateData.authorized_region = JSON.stringify(updateData.authorized_region); |
|
|
|
} else if (updateData.authorized_region === null || updateData.authorized_region === undefined) { |
|
|
|
// 如果是null或undefined,设置为空字符串
|
|
|
|
updateData.authorized_region = ''; |
|
|
|
} else if (typeof updateData.authorized_region === 'string' && updateData.authorized_region.trim() === '') { |
|
|
|
// 如果是空字符串,保持为空字符串
|
|
|
|
updateData.authorized_region = ''; |
|
|
|
} else if (typeof updateData.authorized_region === 'string') { |
|
|
|
// 如果已经是字符串,保持不变
|
|
|
|
console.log('authorized_region已经是字符串,无需转换:', updateData.authorized_region); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('更新用户数据:', { authorized_region: updateData.authorized_region }); |
|
|
|
|
|
|
|
await User.update(updateData, { |
|
|
|
where: { openid: userData.openid } |
|
|
|
}); |
|
|
|
user = await User.findOne({ where: { openid: userData.openid } }); |
|
|
|
|
|
|
|
console.log('更新后用户数据:', { authorized_region: user.authorized_region }); |
|
|
|
|
|
|
|
// 使用统一的关联记录创建函数
|
|
|
|
await createUserAssociations(user); |
|
|
|
} else { |
|
|
|
@ -1236,14 +1257,27 @@ app.post('/api/user/upload', async (req, res) => { |
|
|
|
created_at: getBeijingTime(), |
|
|
|
updated_at: getBeijingTime() |
|
|
|
}; |
|
|
|
|
|
|
|
// 特别处理authorized_region字段,如果是对象则转换为JSON字符串
|
|
|
|
|
|
|
|
// 特别处理authorized_region字段,只有当它是对象时才转换为JSON字符串
|
|
|
|
if (createData.authorized_region && typeof createData.authorized_region === 'object') { |
|
|
|
createData.authorized_region = JSON.stringify(createData.authorized_region); |
|
|
|
} else if (createData.authorized_region === null || createData.authorized_region === undefined) { |
|
|
|
// 如果是null或undefined,设置为空字符串
|
|
|
|
createData.authorized_region = ''; |
|
|
|
} else if (typeof createData.authorized_region === 'string' && createData.authorized_region.trim() === '') { |
|
|
|
// 如果是空字符串,保持为空字符串
|
|
|
|
createData.authorized_region = ''; |
|
|
|
} else if (typeof createData.authorized_region === 'string') { |
|
|
|
// 如果已经是字符串,保持不变
|
|
|
|
console.log('authorized_region已经是字符串,无需转换:', createData.authorized_region); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('创建用户数据:', { authorized_region: createData.authorized_region }); |
|
|
|
|
|
|
|
user = await User.create(createData); |
|
|
|
|
|
|
|
console.log('创建后用户数据:', { authorized_region: user.authorized_region }); |
|
|
|
|
|
|
|
// 使用统一的关联记录创建函数
|
|
|
|
await createUserAssociations(user); |
|
|
|
} |
|
|
|
|