128 lines
3.1 KiB
TypeScript
128 lines
3.1 KiB
TypeScript
import { ApiProperty } from '@midwayjs/swagger';
|
||
import { Exclude, Expose } from 'class-transformer';
|
||
import {
|
||
Column,
|
||
CreateDateColumn,
|
||
Entity,
|
||
PrimaryGeneratedColumn,
|
||
UpdateDateColumn,
|
||
} from 'typeorm';
|
||
import { SubscriptionStatus } from '../enums/base.enum';
|
||
|
||
@Entity('subscription')
|
||
@Exclude()
|
||
export class Subscription {
|
||
// 本地主键,自增 ID
|
||
@ApiProperty()
|
||
@PrimaryGeneratedColumn()
|
||
@Expose()
|
||
id: number;
|
||
|
||
// 站点唯一标识,用于区分不同来源站点
|
||
@ApiProperty({ description: '来源站点唯一标识' })
|
||
@Column()
|
||
@Expose()
|
||
siteId: string;
|
||
|
||
// WooCommerce 订阅的原始 ID(字符串化),用于幂等更新
|
||
@ApiProperty({ description: 'WooCommerce 订阅 ID' })
|
||
@Column()
|
||
@Expose()
|
||
externalSubscriptionId: string;
|
||
|
||
// 订阅状态(active/cancelled/on-hold 等)
|
||
@ApiProperty({ type: SubscriptionStatus })
|
||
@Column({ type: 'enum', enum: SubscriptionStatus })
|
||
@Expose()
|
||
status: SubscriptionStatus;
|
||
|
||
// 货币代码,例如 USD/CAD
|
||
@ApiProperty()
|
||
@Column({ default: '' })
|
||
@Expose()
|
||
currency: string;
|
||
|
||
// 总金额,保留两位小数
|
||
@ApiProperty()
|
||
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
||
@Expose()
|
||
total: number;
|
||
|
||
// 计费周期(day/week/month/year)
|
||
@ApiProperty({ description: '计费周期 e.g. day/week/month/year' })
|
||
@Column({ default: '' })
|
||
@Expose()
|
||
billing_period: string;
|
||
|
||
// 计费周期间隔(例如 1/3/12)
|
||
@ApiProperty({ description: '计费周期间隔 e.g. 1/3/12' })
|
||
@Column({ type: 'int', default: 0 })
|
||
@Expose()
|
||
billing_interval: number;
|
||
|
||
// 客户 ID(WooCommerce 用户 ID)
|
||
@ApiProperty()
|
||
@Column({ type: 'int', default: 0 })
|
||
@Expose()
|
||
customer_id: number;
|
||
|
||
// 客户邮箱(从 billing.email 或 customer_email 提取)
|
||
@ApiProperty()
|
||
@Column({ default: '' })
|
||
@Expose()
|
||
customer_email: string;
|
||
|
||
// 父订单/订阅 ID(如有)
|
||
@ApiProperty({ description: '父订单/父订阅ID(如有)' })
|
||
@Column({ type: 'int', default: 0 })
|
||
@Expose()
|
||
parent_id: number;
|
||
|
||
// 订阅开始时间
|
||
@ApiProperty()
|
||
@Column({ type: 'timestamp', nullable: true })
|
||
@Expose()
|
||
start_date: Date;
|
||
|
||
// 试用结束时间
|
||
@ApiProperty()
|
||
@Column({ type: 'timestamp', nullable: true })
|
||
@Expose()
|
||
trial_end: Date;
|
||
|
||
// 下次支付时间
|
||
@ApiProperty()
|
||
@Column({ type: 'timestamp', nullable: true })
|
||
@Expose()
|
||
next_payment_date: Date;
|
||
|
||
// 订阅结束时间
|
||
@ApiProperty()
|
||
@Column({ type: 'timestamp', nullable: true })
|
||
@Expose()
|
||
end_date: Date;
|
||
|
||
// 商品项(订阅行项目)
|
||
@ApiProperty()
|
||
@Column({ type: 'json', nullable: true })
|
||
@Expose()
|
||
line_items: any[];
|
||
|
||
// 额外元数据(键值对)
|
||
@ApiProperty()
|
||
@Column({ type: 'json', nullable: true })
|
||
@Expose()
|
||
meta_data: any[];
|
||
|
||
// 创建时间(数据库自动生成)
|
||
@ApiProperty({ example: '2022-12-12 11:11:11', description: '创建时间', required: true })
|
||
@CreateDateColumn()
|
||
@Expose()
|
||
createdAt: Date;
|
||
|
||
// 更新时间(数据库自动生成)
|
||
@ApiProperty({ example: '2022-12-12 11:11:11', description: '更新时间', required: true })
|
||
@UpdateDateColumn()
|
||
@Expose()
|
||
updatedAt: Date;
|
||
} |