364 lines
10 KiB
TypeScript
364 lines
10 KiB
TypeScript
import { ApiProperty } from '@midwayjs/swagger';
|
|
import { UnifiedSearchParamsDTO } from './api.dto';
|
|
import { Customer } from '../entity/customer.entity';
|
|
|
|
// 客户基本信息DTO(用于响应)
|
|
export class CustomerDTO extends Customer{
|
|
@ApiProperty({ description: '客户ID' })
|
|
id: number;
|
|
|
|
@ApiProperty({ description: '站点ID', required: false })
|
|
site_id: number;
|
|
|
|
@ApiProperty({ description: '原始ID', required: false })
|
|
origin_id: string;
|
|
|
|
@ApiProperty({ description: '站点创建时间', required: false })
|
|
site_created_at: Date;
|
|
|
|
@ApiProperty({ description: '站点更新时间', required: false })
|
|
site_updated_at: Date;
|
|
|
|
@ApiProperty({ description: '邮箱' })
|
|
email: string;
|
|
|
|
@ApiProperty({ description: '名字', required: false })
|
|
first_name: string;
|
|
|
|
@ApiProperty({ description: '姓氏', required: false })
|
|
last_name: string;
|
|
|
|
@ApiProperty({ description: '全名', required: false })
|
|
fullname: string;
|
|
|
|
@ApiProperty({ description: '用户名', required: false })
|
|
username: string;
|
|
|
|
@ApiProperty({ description: '电话', required: false })
|
|
phone: string;
|
|
|
|
@ApiProperty({ description: '头像URL', required: false })
|
|
avatar: string;
|
|
|
|
@ApiProperty({ description: '账单信息', type: 'object', required: false })
|
|
billing: any;
|
|
|
|
@ApiProperty({ description: '配送信息', type: 'object', required: false })
|
|
shipping: any;
|
|
|
|
@ApiProperty({ description: '原始数据', type: 'object', required: false })
|
|
raw: any;
|
|
|
|
|
|
@ApiProperty({ description: '创建时间' })
|
|
created_at: Date;
|
|
|
|
@ApiProperty({ description: '更新时间' })
|
|
updated_at: Date;
|
|
|
|
|
|
|
|
@ApiProperty({ description: '评分' })
|
|
rate: number;
|
|
|
|
@ApiProperty({ description: '标签列表', type: [String], required: false })
|
|
tags: string[];
|
|
}
|
|
|
|
// ====================== 单条操作 ======================
|
|
|
|
// 创建客户请求DTO
|
|
export class CreateCustomerDTO {
|
|
@ApiProperty({ description: '站点ID' })
|
|
site_id: number;
|
|
|
|
@ApiProperty({ description: '原始ID', required: false })
|
|
origin_id?: string;
|
|
|
|
@ApiProperty({ description: '邮箱' })
|
|
email: string;
|
|
|
|
@ApiProperty({ description: '名字', required: false })
|
|
first_name?: string;
|
|
|
|
@ApiProperty({ description: '姓氏', required: false })
|
|
last_name?: string;
|
|
|
|
@ApiProperty({ description: '全名', required: false })
|
|
fullname?: string;
|
|
|
|
@ApiProperty({ description: '用户名', required: false })
|
|
username?: string;
|
|
|
|
@ApiProperty({ description: '电话', required: false })
|
|
phone?: string;
|
|
|
|
@ApiProperty({ description: '头像URL', required: false })
|
|
avatar?: string;
|
|
|
|
@ApiProperty({ description: '账单信息', type: 'object', required: false })
|
|
billing?: any;
|
|
|
|
@ApiProperty({ description: '配送信息', type: 'object', required: false })
|
|
shipping?: any;
|
|
|
|
@ApiProperty({ description: '原始数据', type: 'object', required: false })
|
|
raw?: any;
|
|
|
|
@ApiProperty({ description: '评分', required: false })
|
|
rate?: number;
|
|
|
|
@ApiProperty({ description: '标签列表', type: [String], required: false })
|
|
tags?: string[];
|
|
|
|
@ApiProperty({ description: '站点创建时间', required: false })
|
|
site_created_at?: Date;
|
|
|
|
@ApiProperty({ description: '站点更新时间', required: false })
|
|
site_updated_at?: Date;
|
|
}
|
|
|
|
// 更新客户请求DTO
|
|
export class UpdateCustomerDTO {
|
|
@ApiProperty({ description: '站点ID', required: false })
|
|
site_id?: number;
|
|
|
|
@ApiProperty({ description: '原始ID', required: false })
|
|
origin_id?: string;
|
|
|
|
@ApiProperty({ description: '邮箱', required: false })
|
|
email?: string;
|
|
|
|
@ApiProperty({ description: '名字', required: false })
|
|
first_name?: string;
|
|
|
|
@ApiProperty({ description: '姓氏', required: false })
|
|
last_name?: string;
|
|
|
|
@ApiProperty({ description: '全名', required: false })
|
|
fullname?: string;
|
|
|
|
@ApiProperty({ description: '用户名', required: false })
|
|
username?: string;
|
|
|
|
@ApiProperty({ description: '电话', required: false })
|
|
phone?: string;
|
|
|
|
@ApiProperty({ description: '头像URL', required: false })
|
|
avatar?: string;
|
|
|
|
@ApiProperty({ description: '账单信息', type: 'object', required: false })
|
|
billing?: any;
|
|
|
|
@ApiProperty({ description: '配送信息', type: 'object', required: false })
|
|
shipping?: any;
|
|
|
|
@ApiProperty({ description: '原始数据', type: 'object', required: false })
|
|
raw?: any;
|
|
|
|
@ApiProperty({ description: '评分', required: false })
|
|
rate?: number;
|
|
|
|
@ApiProperty({ description: '标签列表', type: [String], required: false })
|
|
tags?: string[];
|
|
}
|
|
|
|
// 查询单个客户响应DTO(继承基本信息)
|
|
export class GetCustomerDTO extends CustomerDTO {
|
|
// 可以添加额外的详细信息字段
|
|
}
|
|
// 客户统计信息DTO(包含订单统计)
|
|
export class CustomerStatisticDTO extends CustomerDTO {
|
|
@ApiProperty({ description: '创建日期' })
|
|
date_created: Date;
|
|
|
|
@ApiProperty({ description: '首次购买日期' })
|
|
first_purchase_date: Date;
|
|
|
|
@ApiProperty({ description: '最后购买日期' })
|
|
last_purchase_date: Date;
|
|
|
|
@ApiProperty({ description: '订单数量' })
|
|
orders: number;
|
|
|
|
@ApiProperty({ description: '总消费金额' })
|
|
total: number;
|
|
|
|
@ApiProperty({ description: 'Yoone订单数量', required: false })
|
|
yoone_orders?: number;
|
|
|
|
@ApiProperty({ description: 'Yoone总金额', required: false })
|
|
yoone_total?: number;
|
|
}
|
|
|
|
// 客户统计查询条件DTO
|
|
export class CustomerStatisticWhereDTO {
|
|
@ApiProperty({ description: '邮箱筛选', required: false })
|
|
email?: string;
|
|
|
|
@ApiProperty({ description: '标签筛选', required: false })
|
|
tags?: string;
|
|
|
|
@ApiProperty({ description: '首次购买日期筛选', required: false })
|
|
first_purchase_date?: string;
|
|
|
|
@ApiProperty({ description: '评分筛选', required: false })
|
|
rate?: number;
|
|
|
|
@ApiProperty({ description: '客户ID筛选', required: false })
|
|
customerId?: number;
|
|
}
|
|
|
|
// 客户统计查询参数DTO(继承通用查询参数)
|
|
export type CustomerStatisticQueryParamsDTO = UnifiedSearchParamsDTO<CustomerStatisticWhereDTO>;
|
|
|
|
// 客户统计列表响应DTO
|
|
export class CustomerStatisticListResponseDTO {
|
|
@ApiProperty({ description: '客户统计列表', type: [CustomerStatisticDTO] })
|
|
items: CustomerStatisticDTO[];
|
|
|
|
@ApiProperty({ description: '总数', example: 100 })
|
|
total: number;
|
|
|
|
@ApiProperty({ description: '当前页', example: 1 })
|
|
current: number;
|
|
|
|
@ApiProperty({ description: '每页数量', example: 20 })
|
|
pageSize: number;
|
|
}
|
|
|
|
|
|
// ====================== 批量操作 ======================
|
|
|
|
// 批量创建客户请求DTO
|
|
export class BatchCreateCustomerDTO {
|
|
@ApiProperty({ description: '客户列表', type: [CreateCustomerDTO] })
|
|
customers: CreateCustomerDTO[];
|
|
}
|
|
|
|
// 单个客户更新项DTO
|
|
export class UpdateCustomerItemDTO {
|
|
@ApiProperty({ description: '客户ID' })
|
|
id: number;
|
|
|
|
@ApiProperty({ description: '更新字段', type: UpdateCustomerDTO })
|
|
update_data: Partial<Customer>;
|
|
}
|
|
|
|
// 批量更新客户请求DTO - 每个对象包含id和要更新的字段
|
|
export class BatchUpdateCustomerDTO {
|
|
@ApiProperty({ description: '客户更新列表', type: [UpdateCustomerItemDTO] })
|
|
customers: UpdateCustomerItemDTO[];
|
|
}
|
|
|
|
// 批量删除客户请求DTO
|
|
export class BatchDeleteCustomerDTO {
|
|
@ApiProperty({ description: '客户ID列表', type: [Number] })
|
|
ids: number[];
|
|
}
|
|
|
|
// ====================== 查询操作 ======================
|
|
|
|
// 客户查询条件DTO(用于UnifiedSearchParamsDTO的where参数)
|
|
export class CustomerWhereDTO {
|
|
@ApiProperty({ description: '邮箱筛选', required: false })
|
|
email?: string;
|
|
|
|
@ApiProperty({ description: '标签筛选', required: false })
|
|
tags?: string;
|
|
|
|
|
|
@ApiProperty({ description: '评分筛选', required: false })
|
|
rate?: number;
|
|
|
|
@ApiProperty({ description: '站点ID筛选', required: false })
|
|
site_id?: number;
|
|
|
|
@ApiProperty({ description: '客户ID筛选', required: false })
|
|
customerId?: number;
|
|
|
|
@ApiProperty({ description: '首次购买日期筛选', required: false })
|
|
first_purchase_date?: string;
|
|
|
|
@ApiProperty({ description: '角色筛选', required: false })
|
|
role?: string;
|
|
}
|
|
|
|
// 客户查询参数DTO(继承通用查询参数)
|
|
export type CustomerQueryParamsDTO = UnifiedSearchParamsDTO<CustomerWhereDTO>;
|
|
|
|
// 客户列表响应DTO(参考site-api.dto.ts中的分页格式)
|
|
export class CustomerListResponseDTO {
|
|
@ApiProperty({ description: '客户列表', type: [CustomerDTO] })
|
|
items: CustomerDTO[];
|
|
|
|
@ApiProperty({ description: '总数', example: 100 })
|
|
total: number;
|
|
|
|
@ApiProperty({ description: '页码', example: 1 })
|
|
page: number;
|
|
|
|
@ApiProperty({ description: '每页数量', example: 20 })
|
|
per_page: number;
|
|
|
|
@ApiProperty({ description: '总页数', example: 5 })
|
|
total_pages: number;
|
|
}
|
|
|
|
// ====================== 客户标签相关 ======================
|
|
|
|
// 客户标签基本信息DTO
|
|
export class CustomerTagBasicDTO {
|
|
@ApiProperty({ description: '标签ID' })
|
|
id: number;
|
|
|
|
@ApiProperty({ description: '客户ID' })
|
|
customer_id: number;
|
|
|
|
@ApiProperty({ description: '标签名称' })
|
|
tag: string;
|
|
|
|
@ApiProperty({ description: '创建时间', required: false })
|
|
created_at?: string;
|
|
}
|
|
|
|
// 添加客户标签请求DTO
|
|
export class AddCustomerTagDTO {
|
|
@ApiProperty({ description: '客户ID' })
|
|
customer_id: number;
|
|
|
|
@ApiProperty({ description: '标签名称' })
|
|
tag: string;
|
|
}
|
|
|
|
// 批量添加客户标签请求DTO
|
|
export class BatchAddCustomerTagDTO {
|
|
@ApiProperty({ description: '客户ID' })
|
|
customer_id: number;
|
|
|
|
@ApiProperty({ description: '标签列表', type: [String] })
|
|
tags: string[];
|
|
}
|
|
|
|
// 删除客户标签请求DTO
|
|
export class DeleteCustomerTagDTO {
|
|
@ApiProperty({ description: '标签ID' })
|
|
tag_id: number;
|
|
}
|
|
|
|
// 批量删除客户标签请求DTO
|
|
export class BatchDeleteCustomerTagDTO {
|
|
@ApiProperty({ description: '标签ID列表', type: [Number] })
|
|
tag_ids: number[];
|
|
}
|
|
|
|
// ====================== 同步操作 ======================
|
|
|
|
// 同步客户数据请求DTO
|
|
export class SyncCustomersDTO {
|
|
@ApiProperty({ description: '站点ID' })
|
|
siteId: number;
|
|
|
|
@ApiProperty({ description: '查询参数(支持where和orderBy)', type: UnifiedSearchParamsDTO, required: false })
|
|
params?: UnifiedSearchParamsDTO<CustomerWhereDTO>;
|
|
} |