| | |
| | | import ( |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strings" |
| | | "wms/constvar" |
| | | "wms/pkg/mysqlx" |
| | | ) |
| | |
| | | //ProduceAheadDay int `gorm:"type:int(11);comment:制造提前期(天)" json:"produceAheadDay"` |
| | | MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:最小采购量" json:"minPurchaseAmount"` //最小采购量 |
| | | PurchaseType constvar.PurchaseType `gorm:"type:int(11);comment:采购类型" json:"purchaseType"` |
| | | PurchaseTypes string `gorm:"type:varchar(255);comment:采购类型范围" json:"-"` |
| | | PurchaseTypeList []int `gorm:"-" json:"purchaseTypeList"` |
| | | IsSale bool `gorm:"type:tinyint(1);comment:是否销售" json:"isSale"` //是否销售 |
| | | SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"` //销售单价 |
| | | AutoIncr uint `gorm:"type:int(11);comment:自增ID;default:0;" json:"autoIncr"` |
| | |
| | | return "material" |
| | | } |
| | | |
| | | func (slf *Material) AfterFind(tx *gorm.DB) (err error) { |
| | | if slf.PurchaseTypes != "" && strings.Contains(slf.PurchaseTypes, ",") { |
| | | list := strings.Split(slf.PurchaseTypes, ",") |
| | | for _, v := range list { |
| | | slf.PurchaseTypeList = append(slf.PurchaseTypeList, cast.ToInt(v)) |
| | | } |
| | | } else if slf.PurchaseType != 0 { //兼容旧数据 |
| | | slf.PurchaseTypeList = append(slf.PurchaseTypeList, int(slf.PurchaseType)) |
| | | } |
| | | return |
| | | } |
| | | |
| | | func (slf *Material) BeforeCreate(tx *gorm.DB) (err error) { |
| | | if len(slf.PurchaseTypeList) > 0 { |
| | | var typeList []string |
| | | for _, v := range slf.PurchaseTypeList { |
| | | if v != 0 { |
| | | typeList = append(typeList, cast.ToString(v)) |
| | | } |
| | | } |
| | | slf.PurchaseTypes = strings.Join(typeList, ",") |
| | | if len(slf.PurchaseTypeList) == 1 { |
| | | slf.PurchaseType = constvar.PurchaseType(slf.PurchaseTypeList[0]) |
| | | } |
| | | } |
| | | return |
| | | } |
| | | |
| | | func (slf *Material) BeforeUpdate(tx *gorm.DB) (err error) { |
| | | return slf.BeforeCreate(tx) |
| | | } |
| | | |
| | | func NewMaterialSearch() *MaterialSearch { |
| | | return &MaterialSearch{Orm: mysqlx.GetDB().Where("is_storage = ?", 1)} //只查询有库存的 |
| | | } |