完成距离预校验
This commit is contained in:
@@ -140,12 +140,78 @@ export async function checkinPrecheck(
|
||||
try {
|
||||
// 获取当前业务用户 ID(ak_users.id),不是 Supabase Auth ID
|
||||
console.warn('[CHECKIN RPC] 步骤 1: 获取当前业务用户 ID')
|
||||
const workerId = await getCurrentAkUserId()
|
||||
|
||||
// 打印认证相关日志
|
||||
console.warn('[CHECKIN AUTH] storage ak_user_id =', uni.getStorageSync('ak_user_id'))
|
||||
console.warn('[CHECKIN AUTH] current_ak_user =', uni.getStorageSync('current_ak_user'))
|
||||
|
||||
let workerId = await getCurrentAkUserId()
|
||||
console.warn('[CHECKIN RPC] workerId (ak_user_id):', workerId)
|
||||
|
||||
if (workerId == '' || workerId == null) {
|
||||
console.warn('[CHECKIN RPC] 未登录,返回 NOT_LOGGED_IN')
|
||||
return { distanceMeters: null, allowedRadiusMeters: 0, canCheckin: false, reasonCode: 'NOT_LOGGED_IN' }
|
||||
console.warn('[CHECKIN RPC] workerId 为空,尝试从缓存恢复')
|
||||
|
||||
// 按顺序从缓存恢复
|
||||
// 1. ak_user_id
|
||||
try {
|
||||
const cached = uni.getStorageSync('ak_user_id')
|
||||
if (cached != null && String(cached) != '') {
|
||||
workerId = String(cached)
|
||||
console.warn('[CHECKIN RPC] 从 ak_user_id 恢复:', workerId)
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
// 2. current_ak_user.id
|
||||
if (workerId == '' || workerId == null) {
|
||||
try {
|
||||
const currentAkUser = uni.getStorageSync('current_ak_user')
|
||||
if (currentAkUser != null && String(currentAkUser) != '') {
|
||||
const obj = JSON.parse(String(currentAkUser)) as any
|
||||
if (obj != null && obj.id != null && String(obj.id) != '') {
|
||||
workerId = String(obj.id)
|
||||
console.warn('[CHECKIN RPC] 从 current_ak_user.id 恢复:', workerId)
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// 3. user_id
|
||||
if (workerId == '' || workerId == null) {
|
||||
try {
|
||||
const userId = uni.getStorageSync('user_id')
|
||||
if (userId != null && String(userId) != '') {
|
||||
workerId = String(userId)
|
||||
console.warn('[CHECKIN RPC] 从 user_id 恢复:', workerId)
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// 4. user_info.id
|
||||
if (workerId == '' || workerId == null) {
|
||||
try {
|
||||
const cachedUserInfo = uni.getStorageSync('user_info')
|
||||
if (cachedUserInfo != null && String(cachedUserInfo) != '') {
|
||||
const userInfo = JSON.parse(String(cachedUserInfo)) as any
|
||||
if (userInfo != null && userInfo.id != null && String(userInfo.id) != '') {
|
||||
workerId = String(userInfo.id)
|
||||
console.warn('[CHECKIN RPC] 从 user_info.id 恢复:', workerId)
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// 恢复成功后写回缓存
|
||||
if (workerId != '' && workerId != null) {
|
||||
uni.setStorageSync('ak_user_id', workerId)
|
||||
uni.setStorageSync('current_ak_user', JSON.stringify({ id: workerId }))
|
||||
console.warn('[CHECKIN RPC] 已写回缓存: ak_user_id =', workerId)
|
||||
}
|
||||
|
||||
// 如果仍然为空,返回错误
|
||||
if (workerId == '' || workerId == null) {
|
||||
console.warn('[CHECKIN RPC] 所有恢复策略失败,返回 NOT_LOGGED_IN')
|
||||
return { distanceMeters: null, allowedRadiusMeters: 0, canCheckin: false, reasonCode: 'NOT_LOGGED_IN' }
|
||||
}
|
||||
}
|
||||
|
||||
// 构建 RPC 参数
|
||||
@@ -157,6 +223,7 @@ export async function checkinPrecheck(
|
||||
p_longitude: longitude,
|
||||
p_coordinate_type: 'gcj02',
|
||||
p_accuracy: accuracy,
|
||||
p_reported_at: new Date().toISOString(),
|
||||
p_location_scene: 'CHECKIN_PRECHECK'
|
||||
} as UTSJSONObject
|
||||
console.warn('[CHECKIN RPC] RPC 参数:', JSON.stringify(rpcParams))
|
||||
|
||||
Reference in New Issue
Block a user