jiangshuai
2023-10-20 96844c22ef3fba86a55e0af1b51bc1009d6fa950
models/product_category.go
@@ -11,13 +11,13 @@
   // 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 {
@@ -28,6 +28,7 @@
      Keyword  string
      Orm      *gorm.DB
      Preload  bool
      Ids      []int
   }
)
@@ -73,6 +74,10 @@
   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{})
@@ -91,6 +96,9 @@
   if slf.Name != "" {
      db = db.Where("name = ?", slf.Name)
   }
   if len(slf.Ids) > 0 {
      db = db.Where("id in (?)", slf.Ids)
   }
   return db
@@ -243,3 +251,13 @@
   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
}