zksu
/
API
forked from yoone/API
1
0
Fork 0
API/src/entity/product.entity.ts

119 lines
3.0 KiB
TypeScript

import {
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Entity,
ManyToMany,
JoinTable,
OneToMany,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { ApiProperty } from '@midwayjs/swagger';
import { DictItem } from './dict_item.entity';
import { ProductStockComponent } from './product_stock_component.entity';
import { Category } from './category.entity';
@Entity('product')
export class Product {
@ApiProperty({
example: '1',
description: 'ID',
type: 'number',
required: true,
})
@PrimaryGeneratedColumn()
id: number;
@ApiProperty({ description: 'sku'})
@Column({ unique: true })
sku: string;
// 类型 主要用来区分混装和单品 单品死
@ApiProperty({ description: '类型' })
@Column({ length: 16, default: 'single' })
type: string;
@ApiProperty({
example: 'ZYN 6MG WINTERGREEN',
description: '产品名称',
type: 'string',
required: true,
})
@Column()
name: string;
@ApiProperty({ description: '产品中文名称' })
@Column({ default: '' })
nameCn: string;
@ApiProperty({ example: '产品简短描述', description: '产品简短描述' })
@Column({ nullable: true })
shortDescription?: string;
@ApiProperty({ example: '产品描述', description: '产品描述' })
@Column({ nullable: true })
description?: string;
// 商品价格
@ApiProperty({ description: '价格', example: 99.99 })
@Column({ type: 'decimal', precision: 10, scale: 2, default: 0 })
price: number;
// 促销价格
@ApiProperty({ description: '促销价格', example: 99.99 })
@Column({ type: 'decimal', precision: 10, scale: 2, default: 0 })
promotionPrice: number;
// 分类关联
@ManyToOne(() => Category, category => category.products)
@JoinColumn({ name: 'categoryId' })
category: Category;
@ManyToMany(() => DictItem, dictItem => dictItem.products, {
cascade: true,
})
@JoinTable({
name: 'product_attributes_dict_item',
joinColumn: {
name: 'productId',
referencedColumnName: 'id'
},
inverseJoinColumn: {
name: 'dictItemId',
referencedColumnName: 'id'
}
})
attributes: DictItem[];
// 产品的库存组成,一对多关系(使用独立表)
@ApiProperty({ description: '库存组成', type: ProductStockComponent, isArray: true })
@OneToMany(() => ProductStockComponent, (component) => component.product, { cascade: true })
components: ProductStockComponent[];
@ApiProperty({ description: '站点 SKU 列表', type: 'string', isArray: true })
@Column({ type: 'simple-array' ,nullable:true})
siteSkus: string[];
// 来源
@ApiProperty({ description: '来源', example: '1' })
@Column({ default: 0 })
source: number;
@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;
}