Browse Source

修复位置信息无法写入数据库authorized_region字段的问题

pull/1/head
SwTt29 2 months ago
parent
commit
85371a617b
  1. 2
      pages/profile/index.js
  2. 32
      server-example/server-mysql.js

2
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字段(服务器接口要求)

32
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);

Loading…
Cancel
Save