jiangshuai
2023-10-30 3f1fb8181a80624ec3f77412040777892a462fdc
models/location_product.go
@@ -3,21 +3,23 @@
import (
   "fmt"
   "gorm.io/gorm"
   "wms/constvar"
   "wms/pkg/mysqlx"
)
type (
   LocationProduct struct {
      WmsModel
      Id                int             `json:"id"  gorm:"column:id;primary_key;AUTO_INCREMENT"`
      LocationId        int             `json:"locationId" gorm:"type:int;not null;comment:位置id"` //位置id
      Location          Location        `json:"location" gorm:"foreignKey:LocationId;references:id"`
      AreaId            int             `json:"areaId" grom:"type:int;not null;comment:区域id"` //区域id
      Area              Location        `json:"area" gorm:"foreignKey:AreaId;references:id"`
      ProductCategoryID int             `json:"productCategoryId" gorm:"type:int;not null;comment:产品种类id"` //产品种类id
      ProductCategory   ProductCategory `json:"productCategory"`
      ProductId         string          `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id
      Product           Material        `json:"product" gorm:"foreignKey:ProductId;references:ID"`
      Id                int               `json:"id"  gorm:"column:id;primary_key;AUTO_INCREMENT"`
      LocationId        int               `json:"locationId" gorm:"type:int;not null;comment:位置id"` //位置id
      Location          Location          `json:"location" gorm:"foreignKey:LocationId;references:id"`
      AreaId            int               `json:"areaId" grom:"type:int;not null;comment:区域id"` //区域id
      Area              Location          `json:"area" gorm:"foreignKey:AreaId;references:id"`
      ProductCategoryID int               `json:"productCategoryId" gorm:"type:int;not null;comment:产品种类id"` //产品种类id
      ProductCategory   ProductCategory   `json:"productCategory"`
      ProductId         string            `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id
      Product           Material          `json:"product" gorm:"foreignKey:ProductId;references:ID"`
      RuleType          constvar.RuleType `json:"ruleType" gorm:"type:int(11);not null;comment:上架规则类型 1:产品类型;2:产品类别类型"`
   }
   LocationProductSearch struct {
@@ -90,6 +92,11 @@
   return slf
}
func (slf *LocationProductSearch) SetProductCategoryId(productCategoryID int) *LocationProductSearch {
   slf.ProductCategoryID = productCategoryID
   return slf
}
func (slf *LocationProductSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&LocationProduct{})
@@ -130,6 +137,10 @@
      db = db.Where("area_id = ?", slf.AreaId)
   }
   if slf.ProductCategoryID != 0 {
      db = db.Where("product_category_id = ?", slf.ProductCategoryID)
   }
   return db
}