import { Entity, Column, PrimaryGeneratedColumn, Unique, CreateDateColumn, UpdateDateColumn, } from 'typeorm'; import { ApiProperty } from '@midwayjs/swagger'; @Entity('variation') @Unique(['siteId', 'externalProductId', 'externalVariationId']) // 确保变体的唯一性 export class Variation { @ApiProperty({ example: '1', description: 'ID', type: 'number', required: true, }) @PrimaryGeneratedColumn() id: number; @ApiProperty({ example: '1', description: 'wp网站ID', type: 'string', required: true, }) @Column() siteId: string; // 来源站点唯一标识 @ApiProperty({ example: '1', description: 'wp产品ID', type: 'string', required: true, }) @Column() externalProductId: string; // WooCommerce 产品 ID @ApiProperty({ example: '1', description: 'wp变体ID', type: 'string', required: true, }) @Column() externalVariationId: string; // WooCommerce 变体 ID @ApiProperty({ example: '1', description: '对应WP产品表的ID', type: 'number', required: true, }) @Column() productId: number; // 对应WP产品表的 ID @ApiProperty({ description: 'sku', type: 'string' }) @Column({ nullable: true }) sku?: string; // sku 编码 @ApiProperty({ description: '变体名称', type: 'string', required: true, }) @Column() name: string; @ApiProperty({ description: '常规价格', type: Number }) @Column('decimal', { precision: 10, scale: 2, nullable: true }) regular_price: number; // 常规价格 @ApiProperty({ description: '销售价格', type: Number }) @Column('decimal', { precision: 10, scale: 2, nullable: true }) sale_price: number; // 销售价格 @ApiProperty({ description: '是否促销中', type: Boolean }) @Column({ nullable: true, type: Boolean }) on_sale: boolean; // 是否促销中 @Column({ type: 'json', nullable: true }) attributes: Record; // 变体的属性 @ApiProperty({ example: '2022-12-12 11:11:11', description: '创建时间', required: true, }) @CreateDateColumn() createdAt: Date; @ApiProperty({ example: '2022-12-12 11:11:11', description: '更新时间', required: true, }) @UpdateDateColumn() updatedAt: Date; @ApiProperty({ description: '变体构成成分', type: 'array', items: { type: 'object', properties: { sku: { type: 'string' }, quantity: { type: 'number' }, }, }, }) @Column('json', { nullable: true, comment: '变体构成成分' }) constitution: { sku: string; quantity: number }[] | null; }