package model import ( "gorm.io/gorm" "hospital-admin-api/global" "time" ) // OrderProductItem 订单-商品订单列表 type OrderProductItem struct { ProductItemId int64 `gorm:"column:product_item_id;type:bigint(19);primary_key;comment:主键id" json:"product_item_id"` OrderProductId int64 `gorm:"column:order_product_id;type:bigint(19);comment:订单-商品订单id" json:"order_product_id"` OrderInquiryId int64 `gorm:"column:order_inquiry_id;type:bigint(19);comment:订单-问诊id" json:"order_inquiry_id"` OrderPrescriptionId int64 `gorm:"column:order_prescription_id;type:bigint(19);comment:订单-处方id" json:"order_prescription_id"` ProductId int64 `gorm:"column:product_id;type:bigint(19);comment:商品id" json:"product_id"` ProductName string `gorm:"column:product_name;type:varchar(255);comment:商品名称" json:"product_name"` ProductPrice float64 `gorm:"column:product_price;type:decimal(10,2);comment:商品价格" json:"product_price"` ActualProductPrice float64 `gorm:"column:actual_product_price;type:decimal(10,2);comment:实际商品价格" json:"actual_product_price"` ProductPlatformCode string `gorm:"column:product_platform_code;type:varchar(100);comment:商品处方平台编码" json:"product_platform_code"` Amount int `gorm:"column:amount;type:int(11);comment:数量" json:"amount"` Manufacturer string `gorm:"column:manufacturer;type:varchar(255);comment:生产厂家" json:"manufacturer"` ProductCoverImg string `gorm:"column:product_cover_img;type:varchar(255);comment:商品封面图" json:"product_cover_img"` ProductSpec string `gorm:"column:product_spec;type:varchar(255);comment:商品规格" json:"product_spec"` Model Product *Product `gorm:"foreignKey:ProductId;references:product_id" json:"product"` // 药品 } func (m *OrderProductItem) TableName() string { return "gdxz_order_product_item" } func (m *OrderProductItem) BeforeCreate(tx *gorm.DB) error { if m.ProductItemId == 0 { m.ProductItemId = global.Snowflake.Generate().Int64() } m.CreatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("CreatedAt", m.CreatedAt) m.UpdatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) return nil }