fix:移除多余的手机号绑定判断逻辑

This commit is contained in:
tsui110 2026-01-03 16:01:28 +08:00
parent 652528a14d
commit 3a1d4857dd
9 changed files with 98 additions and 23 deletions

View File

@ -1277,8 +1277,9 @@ async function onParticipate() {
const iid = currentIssueId.value || ''
if (!aid || !iid) { uni.showToast({ title: '期数未选择', icon: 'none' }); return }
const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
if (!token || !phoneNumber) {
// 使
const hasPhoneBound = uni.getStorageSync('login_method') === 'wechat_phone' || uni.getStorageSync('login_method') === 'sms' || uni.getStorageSync('phone_number')
if (!token || !hasPhoneBound) {
uni.showModal({
title: '提示',
content: '请先登录并绑定手机号',

View File

@ -250,8 +250,9 @@ function openPayment(count) {
pendingCount.value = times
paymentAmount.value = (pricePerDraw.value * times).toFixed(2)
const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
if (!token || !phoneNumber) {
// 使
const hasPhoneBound = uni.getStorageSync('login_method') === 'wechat_phone' || uni.getStorageSync('login_method') === 'sms' || uni.getStorageSync('phone_number')
if (!token || !hasPhoneBound) {
uni.showModal({
title: '提示',
content: '请先登录并绑定手机号',
@ -362,8 +363,9 @@ async function onMachineDraw(count) {
}
const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
if (!token || !phoneNumber) {
// 使
const hasPhoneBound = uni.getStorageSync('login_method') === 'wechat_phone' || uni.getStorageSync('login_method') === 'sms' || uni.getStorageSync('phone_number')
if (!token || !hasPhoneBound) {
uni.showModal({
title: '提示',
content: '请先登录并绑定手机号',

View File

@ -88,10 +88,11 @@ const error = ref('')
async function fetchList() {
const user_id = uni.getStorageSync('user_id')
const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
// 使
const hasPhoneBound = uni.getStorageSync('login_method') === 'wechat_phone' || uni.getStorageSync('login_method') === 'sms' || uni.getStorageSync('phone_number')
//
if (!user_id || !token) {
if (!user_id || !token || !hasPhoneBound) {
//
return
}

View File

@ -310,9 +310,10 @@ function filterOrders(items) {
async function fetchOrders(append) {
const user_id = uni.getStorageSync('user_id')
const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
// 使
const hasPhoneBound = uni.getStorageSync('login_method') === 'wechat_phone' || uni.getStorageSync('login_method') === 'sms' || uni.getStorageSync('phone_number')
if (!user_id || !token || !phoneNumber) {
if (!user_id || !token || !hasPhoneBound) {
uni.showModal({
title: '提示',
content: '请先登录并绑定手机号',

View File

@ -106,8 +106,9 @@ function getActionText(action) {
async function fetchRecords(append = false) {
const user_id = uni.getStorageSync('user_id')
const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
if (!user_id || !token || !phoneNumber) {
// 使
const hasPhoneBound = uni.getStorageSync('login_method') === 'wechat_phone' || uni.getStorageSync('login_method') === 'sms' || uni.getStorageSync('phone_number')
if (!user_id || !token || !hasPhoneBound) {
uni.showModal({
title: '提示',
content: '请先登录并绑定手机号',

View File

@ -359,6 +359,9 @@ async function handleSmsLogin() {
console.log('[DEBUG] 短信登录响应原始数据:', data)
saveUserData(data)
//
uni.setStorageSync('login_method', 'sms')
const isNew = data && data.is_new_user
uni.showToast({
title: isNew ? '🎉 注册成功!' : '✨ 登录成功!',
@ -595,7 +598,11 @@ function saveUserData(data) {
console.log('[DEBUG] 准备执行 saveUserData, payload:', data)
uni.setStorageSync('user_info', data)
if (data.token) uni.setStorageSync('token', data.token)
if (data.user_id) uni.setStorageSync('user_id', data.user_id)
if (data.user_id) {
uni.setStorageSync('user_id', data.user_id)
//
uni.setStorageSync('login_method', 'wechat_phone')
}
if (data.avatar) uni.setStorageSync('avatar', data.avatar)
if (data.nickname) uni.setStorageSync('nickname', data.nickname)
if (data.invite_code) uni.setStorageSync('invite_code', data.invite_code)

View File

@ -93,6 +93,34 @@ export function writeMatchingGameCacheEntry(activityId, issueId, entry) {
const issueKey = String(issueId || '')
if (!activityKey || !issueKey) return
const cache = getMatchingGameCache()
// 清理超过170秒的缓存记录
const now = Date.now()
const TTL = 170 * 1000 // 170秒
// 遍历所有活动的所有期,删除过期的缓存
for (const actKey in cache) {
const act = cache[actKey]
if (!act || typeof act !== 'object') continue
for (const issKey in act) {
const entry = act[issKey]
if (!entry || typeof entry !== 'object') continue
const ts = Number(entry.ts || 0)
if (now - ts >= TTL) {
// 超过170秒删除此缓存记录
delete act[issKey]
}
}
// 如果该活动下没有任何期了,删除活动
if (Object.keys(act).length === 0) {
delete cache[actKey]
}
}
// 写入新的缓存
const act = (cache[activityKey] && typeof cache[activityKey] === 'object') ? cache[activityKey] : {}
act[issueKey] = entry
cache[activityKey] = act

View File

@ -1,5 +1,21 @@
import { getUserProfile } from '../api/appUser'
/**
* 检查用户是否已绑定手机号同步仅检查本地
* @returns {boolean} 是否已绑定手机号
*/
export function hasPhoneBound() {
// 优先检查登录方式,如果是微信手机号登录或短信登录,则已绑定手机号
const loginMethod = uni.getStorageSync('login_method')
if (loginMethod === 'wechat_phone' || loginMethod === 'sms') {
return true
}
// 降级检查 phone_number 缓存
const phoneNumber = uni.getStorageSync('phone_number') || ''
return !!phoneNumber
}
/**
* 检查手机号绑定状态
* 如果未绑定手机号,则跳转到登录页面进行绑定
@ -7,6 +23,12 @@ import { getUserProfile } from '../api/appUser'
*/
export async function checkPhoneBound() {
try {
// 优先使用同步检查
if (hasPhoneBound()) {
console.log('[checkPhoneBound] 用户已通过手机号登录,跳过绑定检查')
return true
}
// 调用新的用户资料接口
const profile = await getUserProfile()
@ -66,6 +88,11 @@ export async function checkPhoneBound() {
* @returns {boolean} 是否已绑定手机号
*/
export function checkPhoneBoundSync() {
if (hasPhoneBound()) {
console.log('[checkPhoneBoundSync] 用户已通过手机号登录,跳过绑定检查')
return true
}
const phoneNumber = uni.getStorageSync('phone_number') || ''
console.log('[checkPhoneBoundSync] 检查 phone_number 缓存:', phoneNumber ? phoneNumber : '未找到')

View File

@ -5,6 +5,7 @@
*/
import { createWechatOrder } from '../api/appUser'
import { hasPhoneBound } from './checkPhone'
/**
* 从API响应中提取订单号
@ -98,15 +99,21 @@ export async function executePaymentFlow({ createOrder, openid, onOrderCreated }
*/
export function checkLoginStatus() {
const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
const openid = uni.getStorageSync('openid')
if (!token || !phoneNumber) {
return { ok: false, message: '请先登录并绑定手机号' }
if (!token) {
return { ok: false, message: '请先登录' }
}
// 使用统一的手机号绑定检查
if (!hasPhoneBound()) {
return { ok: false, message: '请先绑定手机号' }
}
if (!openid) {
return { ok: false, message: '缺少OpenID请重新登录' }
}
return { ok: true, openid }
}