| | |
| | | package models |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | |
| | | CategoryId int `gorm:"type:int(11);comment:产品类别id" json:"categoryId"` //产品类别id |
| | | CategoryName string `gorm:"type:varchar(255);comment:产品类别名称" json:"categoryName"` //产品类别名称 |
| | | InternalReference string `gorm:"type:varchar(255);comment:内部参考" json:"internalReference"` //内部参考 |
| | | Barcode string `gorm:"type:varchar(255);comment:条码" json:"barcode"` //条码 |
| | | ProductTagId int `gorm:"type:int(11);comment:产品标签id" json:"productTagId"` //产品标签id |
| | | ProductTagName string `gorm:"type:varchar(255);comment:产品标签名称" json:"productTagName"` //产品标签名称 |
| | | CompanyId int `gorm:"type:int(11);comment:公司id" json:"companyId"` //公司id |
| | |
| | | IsStorage int `gorm:"type:tinyint(1);default:1;comment:是否存库(1是2否)" json:"isStorage"` //无库存的在wms以及srm中需要过滤掉 |
| | | IsVirtual int `json:"isVirtual" gorm:"type:tinyint(1);default:2;comment:是否虚拟物料(1是2否)"` //虚拟物料在MRP计算时跳过该层级直接领用下级物料,虚拟物料不生成工单 |
| | | ReorderRuleNum int64 `json:"reorderRuleNum"` |
| | | MoreUnit bool `json:"moreUnit" gorm:"type:tinyint(1);default:false;comment:启动多单位"` |
| | | MoreUnitValue string `json:"moreUnitValue" gorm:"type:varchar(255);comment:多单位值"` |
| | | MoreUnit *bool `json:"moreUnit" gorm:"type:tinyint(1);default:false;comment:启动多单位"` |
| | | MoreUnitList []UnitItems `json:"moreUnitList" gorm:"-"` |
| | | MoreUnitValue string `json:"-" gorm:"type:varchar(255);comment:多单位值"` |
| | | GrossWeight decimal.Decimal `json:"grossWeight" gorm:"type:decimal(20,3);comment:毛重"` |
| | | NetWeight decimal.Decimal `json:"netWeight" gorm:"type:decimal(20,3);comment:净重"` |
| | | GrossUnit string `json:"grossUnit" gorm:"type:varchar(255);comment:毛重单位"` |
| | | NetUnit string `json:"netUnit" gorm:"type:varchar(255);comment:净重单位"` |
| | | Attributes []Attribute `json:"attributes" gorm:"-"` //动态属性 |
| | | |
| | | //以下为不存库的字段 |
| | | AttachmentIDs []uint `json:"attachmentIDs" gorm:"-"` |
| | |
| | | MinInventoryRule decimal.Decimal `json:"minInventoryRule" gorm:"-"` //最小库存 |
| | | MaxInventoryRule decimal.Decimal `json:"maxInventoryRule" gorm:"-"` //最大库存 |
| | | |
| | | CreateBy string `gorm:"type:varchar(255);comment:导入人、创建人" json:"createBy"` //创建人 |
| | | BarCode string `gorm:"type:varchar(255);comment:(商品/产品/物料的)条形码" json:"barCode"` //条码 |
| | | } |
| | | |
| | | MaterialSearch struct { |
| | |
| | | Orm *gorm.DB |
| | | CategoryIds []int |
| | | Preload bool |
| | | Fields string |
| | | } |
| | | |
| | | IdAndName struct { |
| | | Id string `json:"id"` |
| | | Name string `json:"name"` |
| | | } |
| | | |
| | | UnitItems struct { |
| | | Amount decimal.Decimal `json:"amount"` |
| | | Unit string `json:"unit"` |
| | | Floating bool `json:"floating"` //是否浮动利率 |
| | | } |
| | | ) |
| | | |
| | |
| | | } else if slf.PurchaseType != 0 { //兼容旧数据 |
| | | slf.PurchaseTypeList = append(slf.PurchaseTypeList, int(slf.PurchaseType)) |
| | | } |
| | | if slf.MoreUnitValue != "" { |
| | | var arr []UnitItems |
| | | err := json.Unmarshal([]byte(slf.MoreUnitValue), &arr) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | slf.MoreUnitList = arr |
| | | } |
| | | return |
| | | } |
| | | |
| | |
| | | if len(slf.PurchaseTypeList) == 1 { |
| | | slf.PurchaseType = constvar.PurchaseType(slf.PurchaseTypeList[0]) |
| | | } |
| | | } |
| | | if len(slf.MoreUnitList) != 0 { |
| | | items := make([]UnitItems, 0) |
| | | for k, item := range slf.MoreUnitList { |
| | | if item.Unit != "" && !item.Amount.IsZero() { |
| | | items = append(items, slf.MoreUnitList[k]) |
| | | } |
| | | } |
| | | |
| | | str, err := json.Marshal(items) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | slf.MoreUnitValue = string(str) |
| | | } |
| | | return |
| | | } |
| | |
| | | |
| | | func (slf *MaterialSearch) SetID(id string) *MaterialSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MaterialSearch) SetBarCode(barCode string) *MaterialSearch { |
| | | slf.BarCode = barCode |
| | | return slf |
| | | } |
| | | |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MaterialSearch) SetFields(fields string) *MaterialSearch { |
| | | slf.Fields = fields |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MaterialSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | | if slf.ID != "" { |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | if slf.BarCode != "" { |
| | | db = db.Where("bar_code = ?", slf.BarCode) |
| | | } |
| | | |
| | | if slf.Name != "" { |
| | |
| | | } |
| | | if len(slf.CategoryIds) > 0 { |
| | | db = db.Where("category_id in ?", slf.CategoryIds) |
| | | } |
| | | |
| | | if slf.Fields != "" { |
| | | db = db.Select(slf.Fields) |
| | | } |
| | | |
| | | if slf.Preload { |
| | |
| | | OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"` |
| | | ContacterID int `json:"contacterID" gorm:"type:int;comment:联系人ID"` |
| | | ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID-客户"` |
| | | CompanyID string `json:"companyID"` //公司ID-客户 |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称-客户"` |
| | | Comment string `json:"comment" gorm:"type:text;comment:备注"` |
| | | ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id |
| | |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func MaterialMap(records []*Material) (m map[string]*Material) { |
| | | m = make(map[string]*Material, len(records)) |
| | | for _, record := range records { |
| | | m[record.ID] = record |
| | | } |
| | | return m |
| | | } |