goods.entity.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn, ManyToMany, JoinTable } from 'typeorm';
  2. import { GoodsCategory } from './goods-category.entity';
  3. import { Supplier } from '@/server/modules/supplier/supplier.entity';
  4. import { File } from '@/server/modules/files/file.entity';
  5. @Entity('goods')
  6. export class Goods {
  7. @PrimaryGeneratedColumn({ unsigned: true })
  8. id!: number;
  9. @Column({ name: 'name', type: 'varchar', length: 255, comment: '商品名称' })
  10. name!: string;
  11. @Column({ name: 'price', type: 'decimal', precision: 10, scale: 2, default: 0.00, comment: '售卖价' })
  12. price!: number;
  13. @Column({ name: 'cost_price', type: 'decimal', precision: 10, scale: 2, default: 0.00, comment: '成本价' })
  14. costPrice!: number;
  15. @Column({ name: 'sales_num', type: 'bigint', unsigned: true, default: 0, comment: '销售数量' })
  16. salesNum!: number;
  17. @Column({ name: 'click_num', type: 'bigint', unsigned: true, default: 0, comment: '点击次数' })
  18. clickNum!: number;
  19. @Column({ name: 'category_id1', type: 'int', unsigned: true, default: 0, comment: '一级类别id' })
  20. categoryId1!: number;
  21. @Column({ name: 'category_id2', type: 'int', unsigned: true, default: 0, comment: '二级类别id' })
  22. categoryId2!: number;
  23. @Column({ name: 'category_id3', type: 'int', unsigned: true, default: 0, comment: '三级类别id' })
  24. categoryId3!: number;
  25. @Column({ name: 'goods_type', type: 'tinyint', unsigned: true, default: 1, comment: '订单类型 1实物产品 2虚拟产品' })
  26. goodsType!: number;
  27. @Column({ name: 'supplier_id', type: 'int', unsigned: true, nullable: true, comment: '所属供应商id' })
  28. supplierId!: number | null;
  29. @Column({ name: 'image_file_id', type: 'int', unsigned: true, nullable: true, comment: '商品主图文件ID' })
  30. imageFileId!: number | null;
  31. @ManyToMany(() => File)
  32. @JoinTable({
  33. name: 'goods_slide_images',
  34. joinColumn: { name: 'goods_id', referencedColumnName: 'id' },
  35. inverseJoinColumn: { name: 'file_id', referencedColumnName: 'id' }
  36. })
  37. slideImages!: File[];
  38. @Column({ name: 'detail', type: 'text', nullable: true, comment: '商品详情' })
  39. detail!: string | null;
  40. @Column({ name: 'instructions', type: 'varchar', length: 255, nullable: true, comment: '简介' })
  41. instructions!: string | null;
  42. @Column({ name: 'sort', type: 'int', unsigned: true, default: 0, comment: '排序' })
  43. sort!: number;
  44. @Column({ name: 'state', type: 'tinyint', unsigned: true, default: 1, comment: '状态 1可用 2不可用' })
  45. state!: number;
  46. @Column({ name: 'stock', type: 'bigint', unsigned: true, default: 0, comment: '库存' })
  47. stock!: number;
  48. @Column({ name: 'spu_id', type: 'int', unsigned: true, default: 0, comment: '主商品ID' })
  49. spuId!: number;
  50. @Column({ name: 'spu_name', type: 'varchar', length: 255, nullable: true, comment: '主商品名称' })
  51. spuName!: string | null;
  52. @Column({ name: 'lowest_buy', type: 'int', unsigned: true, default: 1, comment: '最小起购量' })
  53. lowestBuy!: number;
  54. @CreateDateColumn({ name: 'created_at', type: 'timestamp', comment: '创建时间' })
  55. createdAt!: Date;
  56. @UpdateDateColumn({ name: 'updated_at', type: 'timestamp', comment: '更新时间' })
  57. updatedAt!: Date;
  58. @Column({ name: 'created_by', type: 'int', unsigned: true, nullable: true, comment: '创建用户ID' })
  59. createdBy!: number | null;
  60. @Column({ name: 'updated_by', type: 'int', unsigned: true, nullable: true, comment: '更新用户ID' })
  61. updatedBy!: number | null;
  62. @ManyToOne(() => GoodsCategory, { nullable: true })
  63. @JoinColumn({ name: 'category_id1', referencedColumnName: 'id' })
  64. category1!: GoodsCategory | null;
  65. @ManyToOne(() => GoodsCategory, { nullable: true })
  66. @JoinColumn({ name: 'category_id2', referencedColumnName: 'id' })
  67. category2!: GoodsCategory | null;
  68. @ManyToOne(() => GoodsCategory, { nullable: true })
  69. @JoinColumn({ name: 'category_id3', referencedColumnName: 'id' })
  70. category3!: GoodsCategory | null;
  71. @ManyToOne(() => Supplier, { nullable: true })
  72. @JoinColumn({ name: 'supplier_id', referencedColumnName: 'id' })
  73. supplier!: Supplier | null;
  74. @ManyToOne(() => File, { nullable: true })
  75. @JoinColumn({ name: 'image_file_id', referencedColumnName: 'id' })
  76. imageFile!: File | null;
  77. }