import { Site } from './site.entity'; import { PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Unique, Entity, ManyToOne, JoinColumn, } from 'typeorm'; import { ApiProperty } from '@midwayjs/swagger'; import { ProductStatus, ProductStockStatus, 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: 'number', required: true, }) @Column({ type: 'int', nullable: true }) siteId: number; @ApiProperty({ description: '站点信息', type: Site }) @ManyToOne(() => Site) @JoinColumn({ name: 'siteId', referencedColumnName: 'id' }) site: Site; @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, comment: '产品状态: draft, pending, private, publish' }) status: ProductStatus; @ApiProperty({ description: '是否为特色产品', type: 'boolean' }) @Column({ default: false, comment: '是否为特色产品' }) featured: boolean; @ApiProperty({ description: '目录可见性', type: 'string' }) @Column({ default: 'visible', comment: '目录可见性: visible, catalog, search, hidden' }) catalog_visibility: string; @ApiProperty({ description: '产品描述', type: 'string' }) @Column({ type: 'text', nullable: true, comment: '产品描述' }) description: string; @ApiProperty({ description: '产品短描述', type: 'string' }) @Column({ type: 'text', nullable: true, comment: '产品短描述' }) short_description: string; @ApiProperty({ description: '上下架状态', enum: ProductStockStatus }) @Column({ name: 'stock_status', type: 'enum', enum: ProductStockStatus, default: ProductStockStatus.INSTOCK, comment: '库存状态: instock, outofstock, onbackorder', }) stockStatus: ProductStockStatus; @ApiProperty({ description: '库存数量', type: 'number' }) @Column({ type: 'int', nullable: true, comment: '库存数量' }) stock_quantity: number; @ApiProperty({ description: '允许缺货下单', type: 'string' }) @Column({ nullable: true, comment: '允许缺货下单: no, notify, yes' }) backorders: string; @ApiProperty({ description: '是否单独出售', type: 'boolean' }) @Column({ default: false, comment: '是否单独出售' }) sold_individually: boolean; @ApiProperty({ description: '常规价格', type: Number }) @Column('decimal', { precision: 10, scale: 2, nullable: true, comment: '常规价格' }) regular_price: number; @ApiProperty({ description: '销售价格', type: Number }) @Column('decimal', { precision: 10, scale: 2, nullable: true, comment: '销售价格' }) sale_price: number; @ApiProperty({ description: '促销开始日期', type: 'datetime' }) @Column({ type: 'datetime', nullable: true, comment: '促销开始日期' }) date_on_sale_from: Date| null; @ApiProperty({ description: '促销结束日期', type: 'datetime' }) @Column({ type: 'datetime', nullable: true, comment: '促销结束日期' }) date_on_sale_to: Date|null; @ApiProperty({ description: '是否促销中', type: Boolean }) @Column({ nullable: true, type: 'boolean', comment: '是否促销中' }) on_sale: boolean; @ApiProperty({ description: '税务状态', type: 'string' }) @Column({ default: 'taxable', comment: '税务状态: taxable, shipping, none' }) tax_status: string; @ApiProperty({ description: '税类', type: 'string' }) @Column({ nullable: true, comment: '税类' }) tax_class: string; @ApiProperty({ description: '重量(g)', type: 'number' }) @Column('decimal', { precision: 10, scale: 2, nullable: true, comment: '重量(g)' }) weight: number; @ApiProperty({ description: '尺寸(长宽高)', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '尺寸' }) dimensions: { length: string; width: string; height: string }; @ApiProperty({ description: '允许评论', type: 'boolean' }) @Column({ default: true, comment: '允许客户评论' }) reviews_allowed: boolean; @ApiProperty({ description: '购买备注', type: 'string' }) @Column({ nullable: true, comment: '购买备注' }) purchase_note: string; @ApiProperty({ description: '菜单排序', type: 'number' }) @Column({ default: 0, comment: '菜单排序' }) menu_order: number; @ApiProperty({ description: '产品类型', enum: ProductType }) @Column({ type: 'enum', enum: ProductType, comment: '产品类型: simple, grouped, external, variable' }) type: ProductType; @ApiProperty({ description: '父产品ID', type: 'number' }) @Column({ default: 0, comment: '父产品ID' }) parent_id: number; @ApiProperty({ description: '外部产品URL', type: 'string' }) @Column({ type: 'text', nullable: true, comment: '外部产品URL' }) external_url: string; @ApiProperty({ description: '外部产品按钮文本', type: 'string' }) @Column({ nullable: true, comment: '外部产品按钮文本' }) button_text: string; @ApiProperty({ description: '分组产品', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '分组产品' }) grouped_products: number[]; @ApiProperty({ description: '追加销售', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '追加销售' }) upsell_ids: number[]; @ApiProperty({ description: '交叉销售', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '交叉销售' }) cross_sell_ids: number[]; @ApiProperty({ description: '分类', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '分类' }) categories: { id: number; name: string; slug: string }[]; @ApiProperty({ description: '标签', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '标签' }) tags: { id: number; name: string; slug: string }[]; @ApiProperty({ description: '图片', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '图片' }) images: { id: number; src: string; name: string; alt: string }[]; @ApiProperty({ description: '产品属性', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '产品属性' }) attributes: { id: number; name: string; position: number; visible: boolean; variation: boolean; options: string[] }[]; @ApiProperty({ description: '默认属性', type: 'json' }) @Column({ type: 'json', nullable: true, comment: '默认属性' }) default_attributes: { id: number; name: string; option: string }[]; @ApiProperty({ description: 'GTIN', type: 'string' }) @Column({ nullable: true, comment: 'GTIN, UPC, EAN, or ISBN' }) gtin: string; @ApiProperty({ description: '是否删除', type: 'boolean' }) @Column({ nullable: true, type: 'boolean', default: false, comment: '是否删除' }) on_delete: boolean; @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; }