diff --git a/src/pages/index/Header.tsx b/src/pages/index/Header.tsx index 7abaffe..d9f9592 100644 --- a/src/pages/index/Header.tsx +++ b/src/pages/index/Header.tsx @@ -89,6 +89,18 @@ const Header = (props: any) => { const handleGetPhoneNumber = ({detail}: {detail: {code?: string, encryptedData?: string, iv?: string}}) => { const {code, encryptedData, iv} = detail + // 防重复登录检查 + const loginKey = 'login_in_progress' + const loginInProgress = Taro.getStorageSync(loginKey) + + if (loginInProgress && Date.now() - loginInProgress < 5000) { // 5秒内防重 + console.log('登录正在进行中,跳过重复请求') + return + } + + // 标记登录开始 + Taro.setStorageSync(loginKey, Date.now()) + // 获取存储的邀请参数 const inviteParams = getStoredInviteParams() const refereeId = inviteParams?.inviter ? parseInt(inviteParams.inviter) : 0 @@ -116,6 +128,9 @@ const Header = (props: any) => { TenantId }, success: async function (res) { + // 清除登录防重标记 + Taro.removeStorageSync('login_in_progress') + if (res.data.code == 1) { Taro.showToast({ title: res.data.message, @@ -149,6 +164,10 @@ const Header = (props: any) => { Taro.reLaunch({ url: '/pages/index/index' }) + }, + fail: function() { + // 清除登录防重标记 + Taro.removeStorageSync('login_in_progress') } }) } else { diff --git a/src/utils/invite.ts b/src/utils/invite.ts index be72ddb..b87999c 100644 --- a/src/utils/invite.ts +++ b/src/utils/invite.ts @@ -189,6 +189,16 @@ export async function handleInviteRelation(userId: number): Promise { return false } + // 防重复检查:检查是否已经处理过这个邀请关系 + const relationKey = `invite_relation_${inviterId}_${userId}` + const existingRelation = Taro.getStorageSync(relationKey) + + if (existingRelation) { + console.log(`邀请关系已存在,跳过重复处理: ${inviterId} -> ${userId}`) + clearInviteParams() // 清除邀请参数 + return true // 返回true表示关系已存在 + } + console.log(`准备建立邀请关系: ${inviterId} -> ${userId}`) // 使用新的绑定推荐关系接口 @@ -199,6 +209,14 @@ export async function handleInviteRelation(userId: number): Promise { scene: inviteParams.source === 'qrcode' ? `uid_${inviterId}` : `inviter=${inviterId}&source=${inviteParams.source}&t=${inviteParams.t}` }) + // 标记邀请关系已处理(设置过期时间为7天) + Taro.setStorageSync(relationKey, { + inviterId, + userId, + timestamp: Date.now(), + source: inviteParams.source || 'qrcode' + }) + // 清除本地存储的邀请参数 clearInviteParams() @@ -355,6 +373,9 @@ export function debugInviteInfo() { */ export async function checkAndHandleInviteRelation(): Promise { try { + // 清理过期的防重记录 + cleanExpiredInviteRelations() + // 打印调试信息 debugInviteInfo() @@ -410,6 +431,34 @@ export async function manualHandleInviteRelation(userId: number): Promise { + if (key.startsWith('invite_relation_')) { + try { + const data = Taro.getStorageSync(key) + if (data && data.timestamp && (now - data.timestamp > expireTime)) { + Taro.removeStorageSync(key) + console.log('清理过期的邀请关系记录:', key) + } + } catch (error) { + // 如果读取失败,直接删除 + Taro.removeStorageSync(key) + } + } + }) + } catch (error) { + console.error('清理过期邀请关系记录失败:', error) + } +} + /** * 直接绑定推荐关系 * 用于直接调用绑定推荐关系接口