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 || '' const iid = currentIssueId.value || ''
if (!aid || !iid) { uni.showToast({ title: '期数未选择', icon: 'none' }); return } if (!aid || !iid) { uni.showToast({ title: '期数未选择', icon: 'none' }); return }
const token = uni.getStorageSync('token') 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({ uni.showModal({
title: '提示', title: '提示',
content: '请先登录并绑定手机号', content: '请先登录并绑定手机号',

View File

@ -250,8 +250,9 @@ function openPayment(count) {
pendingCount.value = times pendingCount.value = times
paymentAmount.value = (pricePerDraw.value * times).toFixed(2) paymentAmount.value = (pricePerDraw.value * times).toFixed(2)
const token = uni.getStorageSync('token') 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({ uni.showModal({
title: '提示', title: '提示',
content: '请先登录并绑定手机号', content: '请先登录并绑定手机号',
@ -356,14 +357,15 @@ function mapResultsToFlipItems(resultRes, poolRewards) {
async function onMachineDraw(count) { async function onMachineDraw(count) {
const aid = activityId.value const aid = activityId.value
const iid = currentIssueId.value const iid = currentIssueId.value
if (!aid || !iid) { if (!aid || !iid) {
uni.showToast({ title: '期数未选择', icon: 'none' }) uni.showToast({ title: '期数未选择', icon: 'none' })
return return
} }
const token = uni.getStorageSync('token') 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({ uni.showModal({
title: '提示', title: '提示',
content: '请先登录并绑定手机号', content: '请先登录并绑定手机号',
@ -372,7 +374,7 @@ async function onMachineDraw(count) {
}) })
return return
} }
const openid = uni.getStorageSync('openid') const openid = uni.getStorageSync('openid')
if (!openid) { if (!openid) {
uni.showToast({ title: '缺少OpenID请重新登录', icon: 'none' }) uni.showToast({ title: '缺少OpenID请重新登录', icon: 'none' })

View File

@ -88,10 +88,11 @@ const error = ref('')
async function fetchList() { async function fetchList() {
const user_id = uni.getStorageSync('user_id') const user_id = uni.getStorageSync('user_id')
const token = uni.getStorageSync('token') 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 return
} }

View File

@ -310,9 +310,10 @@ function filterOrders(items) {
async function fetchOrders(append) { async function fetchOrders(append) {
const user_id = uni.getStorageSync('user_id') const user_id = uni.getStorageSync('user_id')
const token = uni.getStorageSync('token') 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({ uni.showModal({
title: '提示', title: '提示',
content: '请先登录并绑定手机号', content: '请先登录并绑定手机号',

View File

@ -106,8 +106,9 @@ function getActionText(action) {
async function fetchRecords(append = false) { async function fetchRecords(append = false) {
const user_id = uni.getStorageSync('user_id') const user_id = uni.getStorageSync('user_id')
const token = uni.getStorageSync('token') 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({ uni.showModal({
title: '提示', title: '提示',
content: '请先登录并绑定手机号', content: '请先登录并绑定手机号',

View File

@ -359,6 +359,9 @@ async function handleSmsLogin() {
console.log('[DEBUG] 短信登录响应原始数据:', data) console.log('[DEBUG] 短信登录响应原始数据:', data)
saveUserData(data) saveUserData(data)
//
uni.setStorageSync('login_method', 'sms')
const isNew = data && data.is_new_user const isNew = data && data.is_new_user
uni.showToast({ uni.showToast({
title: isNew ? '🎉 注册成功!' : '✨ 登录成功!', title: isNew ? '🎉 注册成功!' : '✨ 登录成功!',
@ -595,7 +598,11 @@ function saveUserData(data) {
console.log('[DEBUG] 准备执行 saveUserData, payload:', data) console.log('[DEBUG] 准备执行 saveUserData, payload:', data)
uni.setStorageSync('user_info', data) uni.setStorageSync('user_info', data)
if (data.token) uni.setStorageSync('token', data.token) 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.avatar) uni.setStorageSync('avatar', data.avatar)
if (data.nickname) uni.setStorageSync('nickname', data.nickname) if (data.nickname) uni.setStorageSync('nickname', data.nickname)
if (data.invite_code) uni.setStorageSync('invite_code', data.invite_code) 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 || '') const issueKey = String(issueId || '')
if (!activityKey || !issueKey) return if (!activityKey || !issueKey) return
const cache = getMatchingGameCache() 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] : {} const act = (cache[activityKey] && typeof cache[activityKey] === 'object') ? cache[activityKey] : {}
act[issueKey] = entry act[issueKey] = entry
cache[activityKey] = act cache[activityKey] = act

View File

@ -1,5 +1,21 @@
import { getUserProfile } from '../api/appUser' 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() { export async function checkPhoneBound() {
try { try {
// 优先使用同步检查
if (hasPhoneBound()) {
console.log('[checkPhoneBound] 用户已通过手机号登录,跳过绑定检查')
return true
}
// 调用新的用户资料接口 // 调用新的用户资料接口
const profile = await getUserProfile() const profile = await getUserProfile()
@ -66,6 +88,11 @@ export async function checkPhoneBound() {
* @returns {boolean} 是否已绑定手机号 * @returns {boolean} 是否已绑定手机号
*/ */
export function checkPhoneBoundSync() { export function checkPhoneBoundSync() {
if (hasPhoneBound()) {
console.log('[checkPhoneBoundSync] 用户已通过手机号登录,跳过绑定检查')
return true
}
const phoneNumber = uni.getStorageSync('phone_number') || '' const phoneNumber = uni.getStorageSync('phone_number') || ''
console.log('[checkPhoneBoundSync] 检查 phone_number 缓存:', phoneNumber ? phoneNumber : '未找到') console.log('[checkPhoneBoundSync] 检查 phone_number 缓存:', phoneNumber ? phoneNumber : '未找到')

View File

@ -1,10 +1,11 @@
/** /**
* 通用支付流程工具函数 * 通用支付流程工具函数
* *
* 用于统一 一番赏无限赏对对碰 三种玩法的支付流程 * 用于统一 一番赏无限赏对对碰 三种玩法的支付流程
*/ */
import { createWechatOrder } from '../api/appUser' import { createWechatOrder } from '../api/appUser'
import { hasPhoneBound } from './checkPhone'
/** /**
* 从API响应中提取订单号 * 从API响应中提取订单号
@ -18,7 +19,7 @@ export function extractOrderNo(res) {
/** /**
* 执行微信支付流程 * 执行微信支付流程
* *
* @param {Object} options * @param {Object} options
* @param {string} options.orderNo - 订单号必须 * @param {string} options.orderNo - 订单号必须
* @param {string} [options.openid] - 用户 openid可选默认从 storage 读取 * @param {string} [options.openid] - 用户 openid可选默认从 storage 读取
@ -65,7 +66,7 @@ export async function doWechatPayment({ orderNo, openid }) {
/** /**
* 完整支付流程创建订单 + 支付 * 完整支付流程创建订单 + 支付
* *
* @param {Object} options * @param {Object} options
* @param {Function} options.createOrder - 创建订单的函数返回 Promise结果需包含 order_no * @param {Function} options.createOrder - 创建订单的函数返回 Promise结果需包含 order_no
* @param {string} [options.openid] - 用户 openid * @param {string} [options.openid] - 用户 openid
@ -98,15 +99,21 @@ export async function executePaymentFlow({ createOrder, openid, onOrderCreated }
*/ */
export function checkLoginStatus() { export function checkLoginStatus() {
const token = uni.getStorageSync('token') const token = uni.getStorageSync('token')
const phoneNumber = uni.getStorageSync('phone_number')
const openid = uni.getStorageSync('openid') const openid = uni.getStorageSync('openid')
if (!token || !phoneNumber) { if (!token) {
return { ok: false, message: '请先登录并绑定手机号' } return { ok: false, message: '请先登录' }
} }
// 使用统一的手机号绑定检查
if (!hasPhoneBound()) {
return { ok: false, message: '请先绑定手机号' }
}
if (!openid) { if (!openid) {
return { ok: false, message: '缺少OpenID请重新登录' } return { ok: false, message: '缺少OpenID请重新登录' }
} }
return { ok: true, openid } return { ok: true, openid }
} }