feat(invite): 添加邀请统计功能

- 新增邀请统计页面,包含统计概览、邀请记录和排行榜三个标签页
- 实现邀请统计数据的获取和展示,包括总邀请数、成功注册数、转化率等
- 添加邀请记录的查询和展示功能
- 实现邀请排行榜的查询和展示功能
- 新增生成小程序码和处理邀请场景值的接口
This commit is contained in:
2025-08-19 01:38:37 +08:00
parent 9d9762ef17
commit f928264e2c
23 changed files with 2406 additions and 261 deletions

View File

@@ -6,6 +6,7 @@ import './app.scss'
import {loginByOpenId} from "@/api/layout";
import {TenantId} from "@/config/app";
import {saveStorageByLoginUser} from "@/utils/server";
import {parseInviteParams, saveInviteParams, trackInviteSource, handleInviteRelation} from "@/utils/invite";
function App(props: { children: any; }) {
const reload = () => {
@@ -14,9 +15,21 @@ function App(props: { children: any; }) {
loginByOpenId({
code: res.code,
tenantId: TenantId
}).then(data => {
}).then(async data => {
if (data) {
saveStorageByLoginUser(data.access_token, data.user)
// 处理邀请关系
if (data.user?.userId) {
try {
const inviteSuccess = await handleInviteRelation(data.user.userId)
if (inviteSuccess) {
console.log('自动登录时邀请关系建立成功')
}
} catch (error) {
console.error('自动登录时处理邀请关系失败:', error)
}
}
}
})
}
@@ -36,8 +49,41 @@ function App(props: { children: any; }) {
// 对应 onShow
useDidShow(() => {
// 处理小程序启动参数中的邀请信息
const options = Taro.getLaunchOptionsSync()
handleLaunchOptions(options)
})
// 处理启动参数
const handleLaunchOptions = (options: any) => {
try {
console.log('小程序启动参数:', options)
// 解析邀请参数
const inviteParams = parseInviteParams(options)
if (inviteParams) {
console.log('检测到邀请参数:', inviteParams)
// 保存邀请参数到本地存储
saveInviteParams(inviteParams)
// 统计邀请来源
trackInviteSource(inviteParams.source || 'unknown', parseInt(inviteParams.inviter || '0'))
// 显示邀请提示
setTimeout(() => {
Taro.showToast({
title: '检测到邀请信息',
icon: 'success',
duration: 2000
})
}, 1000)
}
} catch (error) {
console.error('处理启动参数失败:', error)
}
}
// 对应 onHide
useDidHide(() => {
})