feat(invite): 添加邀请统计功能
- 新增邀请统计页面,包含统计概览、邀请记录和排行榜三个标签页 - 实现邀请统计数据的获取和展示,包括总邀请数、成功注册数、转化率等 - 添加邀请记录的查询和展示功能 - 实现邀请排行榜的查询和展示功能 - 新增生成小程序码和处理邀请场景值的接口
This commit is contained in:
239
src/api/invite/index.ts
Normal file
239
src/api/invite/index.ts
Normal file
@@ -0,0 +1,239 @@
|
||||
import request from '@/utils/request';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import { SERVER_API_URL } from '@/utils/server';
|
||||
|
||||
/**
|
||||
* 小程序码生成参数
|
||||
*/
|
||||
export interface MiniProgramCodeParam {
|
||||
// 小程序页面路径
|
||||
page?: string;
|
||||
// 场景值,最大32个可见字符
|
||||
scene: string;
|
||||
// 二维码宽度,单位 px,最小 280px,最大 1280px
|
||||
width?: number;
|
||||
// 是否检查页面是否存在
|
||||
checkPath?: boolean;
|
||||
// 环境版本
|
||||
envVersion?: 'release' | 'trial' | 'develop';
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请关系参数
|
||||
*/
|
||||
export interface InviteRelationParam {
|
||||
// 邀请人ID
|
||||
inviterId: number;
|
||||
// 被邀请人ID
|
||||
inviteeId: number;
|
||||
// 邀请来源
|
||||
source: string;
|
||||
// 场景值
|
||||
scene?: string;
|
||||
// 邀请时间
|
||||
inviteTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请统计数据
|
||||
*/
|
||||
export interface InviteStats {
|
||||
// 总邀请数
|
||||
totalInvites: number;
|
||||
// 成功注册数
|
||||
successfulRegistrations: number;
|
||||
// 转化率
|
||||
conversionRate: number;
|
||||
// 今日邀请数
|
||||
todayInvites: number;
|
||||
// 本月邀请数
|
||||
monthlyInvites: number;
|
||||
// 邀请来源统计
|
||||
sourceStats: InviteSourceStat[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请来源统计
|
||||
*/
|
||||
export interface InviteSourceStat {
|
||||
source: string;
|
||||
count: number;
|
||||
successCount: number;
|
||||
conversionRate: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请记录
|
||||
*/
|
||||
export interface InviteRecord {
|
||||
id?: number;
|
||||
inviterId?: number;
|
||||
inviteeId?: number;
|
||||
inviterName?: string;
|
||||
inviteeName?: string;
|
||||
source?: string;
|
||||
scene?: string;
|
||||
status?: 'pending' | 'registered' | 'activated';
|
||||
inviteTime?: string;
|
||||
registerTime?: string;
|
||||
activateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请记录查询参数
|
||||
*/
|
||||
export interface InviteRecordParam {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
inviterId?: number;
|
||||
status?: string;
|
||||
source?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成小程序码
|
||||
*/
|
||||
export async function generateMiniProgramCode(data: MiniProgramCodeParam) {
|
||||
const res = await request.post<ApiResult<string>>(
|
||||
SERVER_API_URL + '/invite/generate-miniprogram-code',
|
||||
data
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成邀请小程序码
|
||||
*/
|
||||
export async function generateInviteCode(inviterId: number, source: string = 'qrcode') {
|
||||
const scene = `inviter=${inviterId}&source=${source}&t=${Date.now()}`;
|
||||
|
||||
return generateMiniProgramCode({
|
||||
page: 'pages/index/index',
|
||||
scene: scene,
|
||||
width: 430,
|
||||
checkPath: true,
|
||||
envVersion: 'release'
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立邀请关系
|
||||
*/
|
||||
export async function createInviteRelation(data: InviteRelationParam) {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
SERVER_API_URL + '/invite/create-relation',
|
||||
data
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理邀请场景值
|
||||
*/
|
||||
export async function processInviteScene(scene: string, userId: number) {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
SERVER_API_URL + '/invite/process-scene',
|
||||
{ scene, userId }
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邀请统计数据
|
||||
*/
|
||||
export async function getInviteStats(inviterId: number) {
|
||||
const res = await request.get<ApiResult<InviteStats>>(
|
||||
SERVER_API_URL + `/invite/stats/${inviterId}`
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询邀请记录
|
||||
*/
|
||||
export async function pageInviteRecords(params: InviteRecordParam) {
|
||||
const res = await request.get<ApiResult<PageResult<InviteRecord>>>(
|
||||
SERVER_API_URL + '/invite/records/page',
|
||||
params
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的邀请记录
|
||||
*/
|
||||
export async function getMyInviteRecords(params: InviteRecordParam) {
|
||||
const res = await request.get<ApiResult<PageResult<InviteRecord>>>(
|
||||
SERVER_API_URL + '/invite/my-records',
|
||||
params
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证邀请码有效性
|
||||
*/
|
||||
export async function validateInviteCode(scene: string) {
|
||||
const res = await request.post<ApiResult<{ valid: boolean; inviterId?: number; source?: string }>>(
|
||||
SERVER_API_URL + '/invite/validate-code',
|
||||
{ scene }
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新邀请状态
|
||||
*/
|
||||
export async function updateInviteStatus(inviteId: number, status: 'registered' | 'activated') {
|
||||
const res = await request.put<ApiResult<unknown>>(
|
||||
SERVER_API_URL + `/invite/update-status/${inviteId}`,
|
||||
{ status }
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邀请排行榜
|
||||
*/
|
||||
export async function getInviteRanking(params?: { limit?: number; period?: 'day' | 'week' | 'month' }) {
|
||||
const res = await request.get<ApiResult<Array<{
|
||||
inviterId: number;
|
||||
inviterName: string;
|
||||
inviteCount: number;
|
||||
successCount: number;
|
||||
conversionRate: number;
|
||||
}>>>(
|
||||
SERVER_API_URL + '/invite/ranking',
|
||||
params
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
279
src/api/invite/model/index.ts
Normal file
279
src/api/invite/model/index.ts
Normal file
@@ -0,0 +1,279 @@
|
||||
import type { PageParam } from '@/api/index';
|
||||
|
||||
/**
|
||||
* 邀请记录表
|
||||
*/
|
||||
export interface InviteRecord {
|
||||
// 主键ID
|
||||
id?: number;
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 被邀请人ID
|
||||
inviteeId?: number;
|
||||
// 邀请人姓名
|
||||
inviterName?: string;
|
||||
// 被邀请人姓名
|
||||
inviteeName?: string;
|
||||
// 邀请来源 (qrcode, link, share等)
|
||||
source?: string;
|
||||
// 场景值
|
||||
scene?: string;
|
||||
// 邀请状态: pending-待注册, registered-已注册, activated-已激活
|
||||
status?: 'pending' | 'registered' | 'activated';
|
||||
// 邀请时间
|
||||
inviteTime?: string;
|
||||
// 注册时间
|
||||
registerTime?: string;
|
||||
// 激活时间
|
||||
activateTime?: string;
|
||||
// 备注
|
||||
comments?: string;
|
||||
// 是否删除, 0否, 1是
|
||||
deleted?: number;
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
// 修改时间
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请统计表
|
||||
*/
|
||||
export interface InviteStats {
|
||||
// 主键ID
|
||||
id?: number;
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 统计日期
|
||||
statDate?: string;
|
||||
// 总邀请数
|
||||
totalInvites?: number;
|
||||
// 成功注册数
|
||||
successfulRegistrations?: number;
|
||||
// 激活用户数
|
||||
activatedUsers?: number;
|
||||
// 转化率
|
||||
conversionRate?: number;
|
||||
// 今日邀请数
|
||||
todayInvites?: number;
|
||||
// 本周邀请数
|
||||
weeklyInvites?: number;
|
||||
// 本月邀请数
|
||||
monthlyInvites?: number;
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
// 修改时间
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请来源统计表
|
||||
*/
|
||||
export interface InviteSourceStats {
|
||||
// 主键ID
|
||||
id?: number;
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 来源类型
|
||||
source?: string;
|
||||
// 来源名称
|
||||
sourceName?: string;
|
||||
// 邀请数量
|
||||
inviteCount?: number;
|
||||
// 成功数量
|
||||
successCount?: number;
|
||||
// 转化率
|
||||
conversionRate?: number;
|
||||
// 统计日期
|
||||
statDate?: string;
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
// 修改时间
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序码记录表
|
||||
*/
|
||||
export interface MiniProgramCode {
|
||||
// 主键ID
|
||||
id?: number;
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 场景值
|
||||
scene?: string;
|
||||
// 小程序码URL
|
||||
codeUrl?: string;
|
||||
// 页面路径
|
||||
pagePath?: string;
|
||||
// 二维码宽度
|
||||
width?: number;
|
||||
// 环境版本
|
||||
envVersion?: string;
|
||||
// 过期时间
|
||||
expireTime?: string;
|
||||
// 使用次数
|
||||
useCount?: number;
|
||||
// 最后使用时间
|
||||
lastUseTime?: string;
|
||||
// 状态: active-有效, expired-过期, disabled-禁用
|
||||
status?: 'active' | 'expired' | 'disabled';
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
// 修改时间
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请记录搜索条件
|
||||
*/
|
||||
export interface InviteRecordParam extends PageParam {
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 被邀请人ID
|
||||
inviteeId?: number;
|
||||
// 邀请状态
|
||||
status?: string;
|
||||
// 邀请来源
|
||||
source?: string;
|
||||
// 开始时间
|
||||
startTime?: string;
|
||||
// 结束时间
|
||||
endTime?: string;
|
||||
// 关键词搜索
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请统计搜索条件
|
||||
*/
|
||||
export interface InviteStatsParam extends PageParam {
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 统计开始日期
|
||||
startDate?: string;
|
||||
// 统计结束日期
|
||||
endDate?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请来源统计搜索条件
|
||||
*/
|
||||
export interface InviteSourceStatsParam extends PageParam {
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 来源类型
|
||||
source?: string;
|
||||
// 统计开始日期
|
||||
startDate?: string;
|
||||
// 统计结束日期
|
||||
endDate?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序码搜索条件
|
||||
*/
|
||||
export interface MiniProgramCodeParam extends PageParam {
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 状态
|
||||
status?: string;
|
||||
// 场景值
|
||||
scene?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请排行榜数据
|
||||
*/
|
||||
export interface InviteRanking {
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 邀请人姓名
|
||||
inviterName?: string;
|
||||
// 邀请人头像
|
||||
inviterAvatar?: string;
|
||||
// 邀请数量
|
||||
inviteCount?: number;
|
||||
// 成功数量
|
||||
successCount?: number;
|
||||
// 转化率
|
||||
conversionRate?: number;
|
||||
// 排名
|
||||
rank?: number;
|
||||
// 奖励金额
|
||||
rewardAmount?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请奖励配置
|
||||
*/
|
||||
export interface InviteRewardConfig {
|
||||
// 主键ID
|
||||
id?: number;
|
||||
// 奖励类型: register-注册奖励, activate-激活奖励, order-订单奖励
|
||||
rewardType?: string;
|
||||
// 奖励名称
|
||||
rewardName?: string;
|
||||
// 奖励金额
|
||||
rewardAmount?: number;
|
||||
// 奖励积分
|
||||
rewardPoints?: number;
|
||||
// 奖励优惠券ID
|
||||
couponId?: number;
|
||||
// 是否启用
|
||||
enabled?: boolean;
|
||||
// 生效时间
|
||||
effectTime?: string;
|
||||
// 失效时间
|
||||
expireTime?: string;
|
||||
// 备注
|
||||
comments?: string;
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
// 修改时间
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请奖励记录
|
||||
*/
|
||||
export interface InviteRewardRecord {
|
||||
// 主键ID
|
||||
id?: number;
|
||||
// 邀请记录ID
|
||||
inviteRecordId?: number;
|
||||
// 邀请人ID
|
||||
inviterId?: number;
|
||||
// 被邀请人ID
|
||||
inviteeId?: number;
|
||||
// 奖励类型
|
||||
rewardType?: string;
|
||||
// 奖励金额
|
||||
rewardAmount?: number;
|
||||
// 奖励积分
|
||||
rewardPoints?: number;
|
||||
// 优惠券ID
|
||||
couponId?: number;
|
||||
// 发放状态: pending-待发放, issued-已发放, failed-发放失败
|
||||
status?: 'pending' | 'issued' | 'failed';
|
||||
// 发放时间
|
||||
issueTime?: string;
|
||||
// 失败原因
|
||||
failReason?: string;
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
// 修改时间
|
||||
updateTime?: string;
|
||||
}
|
||||
@@ -43,5 +43,9 @@ export interface ShopDealerOrder {
|
||||
*/
|
||||
export interface ShopDealerOrderParam extends PageParam {
|
||||
id?: number;
|
||||
firstUserId?: number;
|
||||
secondUserId?: number;
|
||||
thirdUserId?: number;
|
||||
userId?: number;
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { PageParam } from '@/api/index';
|
||||
import type { PageParam } from '@/api';
|
||||
|
||||
/**
|
||||
* 分销商推荐关系表
|
||||
@@ -25,5 +25,6 @@ export interface ShopDealerReferee {
|
||||
*/
|
||||
export interface ShopDealerRefereeParam extends PageParam {
|
||||
id?: number;
|
||||
dealerId?: number;
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
@@ -43,5 +43,6 @@ export interface ShopDealerWithdraw {
|
||||
*/
|
||||
export interface ShopDealerWithdrawParam extends PageParam {
|
||||
id?: number;
|
||||
userId?: number;
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user