goods.entity.mt.ts 4.9 KB

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