forked from yoone/API
126 lines
3.0 KiB
TypeScript
126 lines
3.0 KiB
TypeScript
import {
|
|
PrimaryGeneratedColumn,
|
|
Column,
|
|
CreateDateColumn,
|
|
UpdateDateColumn,
|
|
Unique,
|
|
Entity,
|
|
} 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: '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: '上下架状态', enum: ProductStockStatus })
|
|
@Column({
|
|
name: 'stock_status',
|
|
type: 'enum',
|
|
enum: ProductStockStatus,
|
|
default: ProductStockStatus.INSTOCK
|
|
})
|
|
stockStatus: ProductStockStatus;
|
|
|
|
@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: '是否删除', type: Boolean })
|
|
@Column({ nullable: true, type: Boolean , default: false })
|
|
on_delete: boolean; // 是否删除
|
|
|
|
|
|
@ApiProperty({
|
|
description: '产品类型',
|
|
enum: ProductType,
|
|
})
|
|
@Column({ type: 'enum', enum: ProductType })
|
|
type: ProductType;
|
|
|
|
|
|
@Column({ type: 'json', nullable: true })
|
|
metadata: Record<string, any>; // 产品的其他扩展字段
|
|
|
|
@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;
|
|
}
|