diff --git a/pages-activity/activity/duiduipeng/index.vue b/pages-activity/activity/duiduipeng/index.vue index 573a354..ca99538 100644 --- a/pages-activity/activity/duiduipeng/index.vue +++ b/pages-activity/activity/duiduipeng/index.vue @@ -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: '请先登录并绑定手机号', diff --git a/pages-activity/activity/wuxianshang/index.vue b/pages-activity/activity/wuxianshang/index.vue index adfd700..fe35047 100644 --- a/pages-activity/activity/wuxianshang/index.vue +++ b/pages-activity/activity/wuxianshang/index.vue @@ -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: '请先登录并绑定手机号', @@ -356,14 +357,15 @@ function mapResultsToFlipItems(resultRes, poolRewards) { async function onMachineDraw(count) { const aid = activityId.value const iid = currentIssueId.value - if (!aid || !iid) { + if (!aid || !iid) { uni.showToast({ title: '期数未选择', icon: 'none' }) - return + 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: '请先登录并绑定手机号', @@ -372,7 +374,7 @@ async function onMachineDraw(count) { }) return } - + const openid = uni.getStorageSync('openid') if (!openid) { uni.showToast({ title: '缺少OpenID,请重新登录', icon: 'none' }) diff --git a/pages-user/address/index.vue b/pages-user/address/index.vue index a10c053..bfee9c5 100644 --- a/pages-user/address/index.vue +++ b/pages-user/address/index.vue @@ -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 } diff --git a/pages-user/orders/index.vue b/pages-user/orders/index.vue index 9b60ac2..fb67c1c 100644 --- a/pages-user/orders/index.vue +++ b/pages-user/orders/index.vue @@ -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: '请先登录并绑定手机号', diff --git a/pages-user/points/index.vue b/pages-user/points/index.vue index 6820340..b4dc970 100644 --- a/pages-user/points/index.vue +++ b/pages-user/points/index.vue @@ -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: '请先登录并绑定手机号', diff --git a/pages/login/index.vue b/pages/login/index.vue index ce34fa5..c1de2f9 100644 --- a/pages/login/index.vue +++ b/pages/login/index.vue @@ -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) diff --git a/utils/cache.js b/utils/cache.js index a90b419..9def0ed 100644 --- a/utils/cache.js +++ b/utils/cache.js @@ -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 diff --git a/utils/checkPhone.js b/utils/checkPhone.js index 0313f37..fb8b3b6 100644 --- a/utils/checkPhone.js +++ b/utils/checkPhone.js @@ -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 : '未找到') diff --git a/utils/payment.js b/utils/payment.js index 904e3a8..f6829b3 100644 --- a/utils/payment.js +++ b/utils/payment.js @@ -1,10 +1,11 @@ /** * 通用支付流程工具函数 - * + * * 用于统一 一番赏、无限赏、对对碰 三种玩法的支付流程 */ import { createWechatOrder } from '../api/appUser' +import { hasPhoneBound } from './checkPhone' /** * 从API响应中提取订单号 @@ -18,7 +19,7 @@ export function extractOrderNo(res) { /** * 执行微信支付流程 - * + * * @param {Object} options * @param {string} options.orderNo - 订单号(必须) * @param {string} [options.openid] - 用户 openid(可选,默认从 storage 读取) @@ -65,7 +66,7 @@ export async function doWechatPayment({ orderNo, openid }) { /** * 完整支付流程(创建订单 + 支付) - * + * * @param {Object} options * @param {Function} options.createOrder - 创建订单的函数,返回 Promise,结果需包含 order_no * @param {string} [options.openid] - 用户 openid @@ -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 } }