32 lines
		
	
	
		
			927 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			32 lines
		
	
	
		
			927 B
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package entities | |||
|  | 
 | |||
|  | import ( | |||
|  | 	"time" | |||
|  | 
 | |||
|  | 	"github.com/google/uuid" | |||
|  | 	"gorm.io/gorm" | |||
|  | ) | |||
|  | 
 | |||
|  | // ProductPackageItem 产品组合包项目 | |||
|  | type ProductPackageItem struct { | |||
|  | 	ID        string `gorm:"primaryKey;type:varchar(36)"` | |||
|  | 	PackageID string `gorm:"type:varchar(36);not null;index" comment:"组合包产品ID"` | |||
|  | 	ProductID string `gorm:"type:varchar(36);not null;index" comment:"子产品ID"` | |||
|  | 	SortOrder int    `gorm:"default:0" comment:"排序"` | |||
|  | 
 | |||
|  | 	// 关联关系 | |||
|  | 	Package *Product `gorm:"foreignKey:PackageID" comment:"组合包产品"` | |||
|  | 	Product *Product `gorm:"foreignKey:ProductID" comment:"子产品"` | |||
|  | 
 | |||
|  | 	CreatedAt time.Time      `gorm:"autoCreateTime"` | |||
|  | 	UpdatedAt time.Time      `gorm:"autoUpdateTime"` | |||
|  | 	DeletedAt gorm.DeletedAt `gorm:"index"` | |||
|  | } | |||
|  | 
 | |||
|  | // BeforeCreate GORM钩子:创建前自动生成UUID | |||
|  | func (ppi *ProductPackageItem) BeforeCreate(tx *gorm.DB) error { | |||
|  | 	if ppi.ID == "" { | |||
|  | 		ppi.ID = uuid.New().String() | |||
|  | 	} | |||
|  | 	return nil | |||
|  | }  |