| | |
| | | // ProductCategory 产品分类 |
| | | ProductCategory struct { |
| | | BaseModelInt |
| | | Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:分类名称"` //位置名称 |
| | | Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:分类名称"` //分类名称 |
| | | ParentId int `json:"parentId" gorm:"type:int;comment:上级分类id"` //上级id |
| | | RouteId int `json:"routeId" gorm:"type:int;comment:路线id"` |
| | | RouteName string `json:"routeName" gorm:"type:varchar(512);comment:路线名称"` //公司 |
| | | ForceRemovalStrategy constvar.ForceRemovalStrategy `json:"forceRemovalStrategy" gorm:"type:tinyint;comment:强制下架策略"` //强制下架策略 |
| | | CostingMethod constvar.CostingMethod `json:"costingMethod" gorm:"type:tinyint;comment:成本方法"` //成本方法 |
| | | InventoryValuation constvar.InventoryValuation `json:"inventoryValuation" gorm:"type:tinyint;comment:库存计价"` //库存计价 |
| | | RouteId int `json:"routeId" gorm:"type:int;comment:路线id"` //路线id |
| | | RouteName string `json:"routeName" gorm:"type:varchar(512);comment:路线名称"` //公司 |
| | | ForceRemovalStrategy constvar.ForceRemovalStrategy `json:"forceRemovalStrategy" gorm:"type:tinyint;comment:强制下架策略"` //强制下架策略 |
| | | CostingMethod constvar.CostingMethod `json:"costingMethod" gorm:"type:tinyint;comment:成本方法"` //成本方法 |
| | | InventoryValuation constvar.InventoryValuation `json:"inventoryValuation" gorm:"type:tinyint;comment:库存计价"` //库存计价 |
| | | } |
| | | |
| | | ProductCategorySearch struct { |
| | |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | Ids []int |
| | | } |
| | | ) |
| | | |
| | |
| | | slf.Preload = preload |
| | | return slf |
| | | } |
| | | func (slf *ProductCategorySearch) SetIds(ids []int) *ProductCategorySearch { |
| | | slf.Ids = ids |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductCategorySearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&ProductCategory{}) |
| | |
| | | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | if len(slf.Ids) > 0 { |
| | | db = db.Where("id in (?)", slf.Ids) |
| | | } |
| | | |
| | | return db |
| | |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *ProductCategorySearch) Save(record *ProductCategory) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |