import { PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Unique, Entity, } from 'typeorm'; import { ApiProperty } from '@midwayjs/swagger'; import { ProductStatus, ProductType } from '../enums/base.enum'; @Entity('wp_product') @Unique(['siteId', 'externalProductId']) // 确保产品的唯一性 export class WpProduct { @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; @ApiProperty({ description: 'sku', type: 'string' }) @Column({ nullable: true }) sku?: string; @ApiProperty({ example: 'ZYN 6MG WINTERGREEN', description: '产品名称', type: 'string', required: true, }) @Column() name: string; @ApiProperty({ description: '产品状态', enum: ProductStatus }) @Column({ type: 'enum', enum: ProductStatus }) status: ProductStatus; @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; // 是否促销中 @ApiProperty({ description: '产品类型', enum: ProductType, }) @Column({ type: 'enum', enum: ProductType }) type: ProductType; @Column({ type: 'json', nullable: true }) metadata: 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; }