diff --git a/pages/profile/index.js b/pages/profile/index.js index 75bdf3f..83b8d22 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -779,7 +779,7 @@ Page({ // 构造上传的数据,包含authorized_region字段和必要的phoneNumber let userInfo = { - authorized_region: JSON.stringify(locationData) // 将位置数据转换为JSON字符串存储 + authorized_region: locationData // 直接传递对象,由API层处理JSON序列化 }; // 确保包含phoneNumber字段(服务器接口要求) diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js index 7bab83c..8093f3b 100644 --- a/server-example/server-mysql.js +++ b/server-example/server-mysql.js @@ -1213,28 +1213,36 @@ app.post('/api/user/upload', async (req, res) => { }); if (user) { - // 更新用户信息 - await User.update( - { - ...userData, - updated_at: getBeijingTime() - }, - { - where: { openid: userData.openid } - } - ); + // 更新用户信息,确保authorized_region字段正确处理 + const updateData = { ...userData, updated_at: getBeijingTime() }; + + // 特别处理authorized_region字段,如果是对象则转换为JSON字符串 + if (updateData.authorized_region && typeof updateData.authorized_region === 'object') { + updateData.authorized_region = JSON.stringify(updateData.authorized_region); + } + + await User.update(updateData, { + where: { openid: userData.openid } + }); user = await User.findOne({ where: { openid: userData.openid } }); // 使用统一的关联记录创建函数 await createUserAssociations(user); } else { - // 创建新用户 - user = await User.create({ + // 创建新用户,确保authorized_region字段正确处理 + const createData = { ...userData, notice: 'new', // 创建用户时固定设置notice为new created_at: getBeijingTime(), updated_at: getBeijingTime() - }); + }; + + // 特别处理authorized_region字段,如果是对象则转换为JSON字符串 + if (createData.authorized_region && typeof createData.authorized_region === 'object') { + createData.authorized_region = JSON.stringify(createData.authorized_region); + } + + user = await User.create(createData); // 使用统一的关联记录创建函数 await createUserAssociations(user);