From 85371a617b41f35baf29ea6ca949c69a404b97ec Mon Sep 17 00:00:00 2001 From: SwTt29 <2055018491@qq.com> Date: Thu, 25 Dec 2025 09:29:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=8D=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=97=A0=E6=B3=95=E5=86=99=E5=85=A5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93authorized=5Fregion=E5=AD=97=E6=AE=B5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/profile/index.js | 2 +- server-example/server-mysql.js | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) 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);