feat(customer): implement customer analysis page and drawer flow

This commit is contained in:
2026-03-03 16:45:22 +08:00
parent ccf7d403de
commit d450526204
28 changed files with 2880 additions and 3 deletions

View File

@@ -168,6 +168,154 @@ export interface CustomerExportDto {
totalCount: number;
}
/** 客户分析周期筛选值。 */
export type CustomerAnalysisPeriodFilter = '7d' | '30d' | '90d' | '365d';
/** 客户分析趋势点。 */
export interface CustomerAnalysisTrendPointDto {
label: string;
value: number;
}
/** 客户分析新老客构成项。 */
export interface CustomerAnalysisCompositionItemDto {
count: number;
label: string;
percent: number;
segmentCode: string;
tone: string;
}
/** 客单价分布项。 */
export interface CustomerAnalysisAmountDistributionItemDto {
count: number;
label: string;
percent: number;
segmentCode: string;
}
/** RFM 分层单元。 */
export interface CustomerAnalysisRfmCellDto {
count: number;
label: string;
segmentCode: string;
tone: string;
}
/** RFM 分层行。 */
export interface CustomerAnalysisRfmRowDto {
cells: CustomerAnalysisRfmCellDto[];
label: string;
}
/** 客户分析 Top 客户。 */
export interface CustomerAnalysisTopCustomerDto {
averageAmount: number;
customerKey: string;
lastOrderAt: string;
name: string;
orderCount: number;
phoneMasked: string;
rank: number;
tags: CustomerTagDto[];
totalAmount: number;
}
/** 客户分析总览。 */
export interface CustomerAnalysisOverviewDto {
activeCustomers: number;
activeRatePercent: number;
amountDistribution: CustomerAnalysisAmountDistributionItemDto[];
averageLifetimeValue: number;
composition: CustomerAnalysisCompositionItemDto[];
growthRatePercent: number;
growthTrend: CustomerAnalysisTrendPointDto[];
newCustomers: number;
newCustomersDailyAverage: number;
periodCode: CustomerAnalysisPeriodFilter;
periodDays: number;
rfmRows: CustomerAnalysisRfmRowDto[];
topCustomers: CustomerAnalysisTopCustomerDto[];
totalCustomers: number;
}
/** 客群明细分群编码。 */
export type CustomerAnalysisSegmentCode =
| 'active_new'
| 'active_recent'
| 'all'
| 'amount_0_30'
| 'amount_30_60'
| 'amount_60_100'
| 'amount_100_150'
| 'amount_150_plus'
| 'churn'
| 'dormant'
| 'high_value_top'
| 'repeat_loyal'
| `rfm_r${1 | 2 | 3}c${1 | 2 | 3 | 4}`
| (string & {});
/** 客群明细行。 */
export interface CustomerAnalysisSegmentListItemDto {
avatarColor: string;
avatarText: string;
averageAmount: number;
customerKey: string;
isDimmed: boolean;
isMember: boolean;
lastOrderAt: string;
memberTierName: string;
name: string;
orderCount: number;
phoneMasked: string;
registeredAt: string;
tags: CustomerTagDto[];
totalAmount: number;
}
/** 客群明细结果。 */
export interface CustomerAnalysisSegmentListResultDto {
items: CustomerAnalysisSegmentListItemDto[];
page: number;
pageSize: number;
segmentCode: string;
segmentDescription: string;
segmentTitle: string;
totalCount: number;
}
/** 客户分析会员详情。 */
export interface CustomerMemberDetailDto {
averageAmount: number;
customerKey: string;
lastOrderAt: string;
member: CustomerMemberSummaryDto;
name: string;
phoneMasked: string;
recentOrders: CustomerRecentOrderDto[];
registeredAt: string;
repurchaseRatePercent: number;
source: string;
tags: CustomerTagDto[];
totalAmount: number;
totalOrders: number;
}
/** 客户分析基础查询参数。 */
export interface CustomerAnalysisBaseQuery {
period?: CustomerAnalysisPeriodFilter;
storeId: string;
}
/** 客群明细查询参数。 */
export interface CustomerAnalysisSegmentListQuery extends CustomerAnalysisBaseQuery {
keyword?: string;
page: number;
pageSize: number;
segmentCode: CustomerAnalysisSegmentCode;
}
/** 查询客户列表。 */
export async function getCustomerListApi(params: CustomerListQuery) {
return requestClient.get<CustomerListResultDto>('/customer/list/list', {
@@ -208,3 +356,69 @@ export async function exportCustomerCsvApi(params: CustomerListFilterQuery) {
params,
});
}
/** 查询客户分析总览。 */
export async function getCustomerAnalysisOverviewApi(
params: CustomerAnalysisBaseQuery,
) {
return requestClient.get<CustomerAnalysisOverviewDto>(
'/customer/analysis/overview',
{
params,
},
);
}
/** 查询客群明细分页。 */
export async function getCustomerAnalysisSegmentListApi(
params: CustomerAnalysisSegmentListQuery,
) {
return requestClient.get<CustomerAnalysisSegmentListResultDto>(
'/customer/analysis/segment/list',
{
params,
},
);
}
/** 查询客户分析会员详情。 */
export async function getCustomerMemberDetailApi(params: {
customerKey: string;
storeId: string;
}) {
return requestClient.get<CustomerMemberDetailDto>(
'/customer/analysis/member/detail',
{
params,
},
);
}
/** 查询客户分析客户详情。 */
export async function getCustomerAnalysisDetailApi(params: {
customerKey: string;
storeId: string;
}) {
return requestClient.get<CustomerDetailDto>('/customer/analysis/detail', {
params,
});
}
/** 查询客户分析客户画像。 */
export async function getCustomerAnalysisProfileApi(params: {
customerKey: string;
storeId: string;
}) {
return requestClient.get<CustomerProfileDto>('/customer/analysis/profile', {
params,
});
}
/** 导出客户分析 CSV。 */
export async function exportCustomerAnalysisCsvApi(
params: CustomerAnalysisBaseQuery,
) {
return requestClient.get<CustomerExportDto>('/customer/analysis/export', {
params,
});
}