|
|
|
@ -1188,7 +1188,7 @@ async function createUserAssociations(user) { |
|
|
|
// 专门用于更新用户位置信息的API端点
|
|
|
|
app.post('/api/user/update-location', async (req, res) => { |
|
|
|
try { |
|
|
|
const { openid, latitude, longitude } = req.body; |
|
|
|
const { openid, latitude, longitude, address } = req.body; |
|
|
|
|
|
|
|
if (!openid) { |
|
|
|
return res.json({ success: false, message: '缺少openid' }); |
|
|
|
@ -1203,8 +1203,19 @@ app.post('/api/user/update-location', async (req, res) => { |
|
|
|
|
|
|
|
console.log('更新用户位置信息:', { openid, locationJson }); |
|
|
|
|
|
|
|
// 准备要更新的数据
|
|
|
|
const updateData = { |
|
|
|
authorized_region: locationJson, |
|
|
|
updated_at: getBeijingTime() |
|
|
|
}; |
|
|
|
|
|
|
|
// 如果有地址信息,保存到detailedaddress字段
|
|
|
|
if (address) { |
|
|
|
updateData.detailedaddress = address; |
|
|
|
} |
|
|
|
|
|
|
|
const updateResult = await User.update( |
|
|
|
{ authorized_region: locationJson, updated_at: getBeijingTime() }, |
|
|
|
updateData, |
|
|
|
{ where: { openid } } |
|
|
|
); |
|
|
|
|
|
|
|
@ -1212,13 +1223,20 @@ app.post('/api/user/update-location', async (req, res) => { |
|
|
|
|
|
|
|
if (updateResult[0] > 0) { |
|
|
|
// 查询更新后的用户数据
|
|
|
|
const updatedUser = await User.findOne({ where: { openid }, attributes: ['authorized_region'] }); |
|
|
|
const updatedUser = await User.findOne({ |
|
|
|
where: { openid }, |
|
|
|
attributes: ['authorized_region', 'detailedaddress'] |
|
|
|
}); |
|
|
|
console.log('更新后的位置信息:', updatedUser.authorized_region); |
|
|
|
console.log('更新后的地址信息:', updatedUser.detailedaddress); |
|
|
|
|
|
|
|
return res.json({ |
|
|
|
success: true, |
|
|
|
message: '位置信息更新成功', |
|
|
|
data: { authorized_region: updatedUser.authorized_region } |
|
|
|
message: '位置和地址信息更新成功', |
|
|
|
data: { |
|
|
|
authorized_region: updatedUser.authorized_region, |
|
|
|
address: updatedUser.detailedaddress |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return res.json({ success: false, message: '用户不存在或位置信息未更新' }); |
|
|
|
|