goods.entity.ts 4.5 KB

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