From 359f2f3fd0da6d69474cce87353beb54bfdbf90c Mon Sep 17 00:00:00 2001 From: lishihai <dslsh@dscom> Date: 星期四, 20 六月 2024 14:24:52 +0800 Subject: [PATCH] 概述->新建或编辑(出库/入库)信息,编辑的时候显示保存的成本单价和销售单价 --- models/attribute.go | 61 ++++++++++++++++++++++++++++-- 1 files changed, 57 insertions(+), 4 deletions(-) diff --git a/models/attribute.go b/models/attribute.go index fde8381..31e6d90 100644 --- a/models/attribute.go +++ b/models/attribute.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "fmt" "gorm.io/gorm" "wms/pkg/mysqlx" @@ -10,9 +11,12 @@ // Attribute 鍔ㄦ�佸睘鎬ц〃 Attribute struct { gorm.Model - Name string `gorm:"type:varchar(100);not null;default:''" json:"name"` //灞炴�у悕绉� - DataType DataType `gorm:"type:tinyint;not null;default:0" json:"dataType"` //缁欒皝鐢ㄧ殑 1 鐗╂枡锛堜骇鍝侊級 - Value string `json:"value" gorm:"-"` //浠嶢ttributeValue鍙栧埌鐨剉alue + Name string `gorm:"type:varchar(100);not null;default:''" json:"name"` //灞炴�у悕绉� + DataType DataType `gorm:"type:tinyint;not null;default:0" json:"dataType"` //鍊肩被鍨嬶紙1瀛楃涓� 2 int 3 涓嬫媺妗� 锛� + EntityType EntityType `gorm:"type:tinyint;not null;default:0" json:"entityType"` //缁欒皝鐢ㄧ殑 1 鐗╂枡锛堜骇鍝侊級 + SelectValues []string `json:"selectValues" gorm:"-"` //dateType=3鏃剁敤 + SelectValue string `json:"-" gorm:"type:text;"` + Value string `json:"value" gorm:"-"` //浠嶢ttributeValue鍙栧埌鐨剉alue } AttributeSearch struct { @@ -27,11 +31,53 @@ type DataType int const ( - DateTypeProduct = 1 + DataTypeString = 1 //鎵嬪~瀛楃涓� + DataTypeInt = 2 //鎵嬪~鏁村瀷 + DataTypeSelect = 3 //涓嬫媺妗� +) + +type EntityType int + +const ( + EntityTypeProduct = 1 ) func (slf *Attribute) TableName() string { return "wms_attribute" +} + +func (slf *Attribute) BeforeCreate(tx *gorm.DB) (err error) { + if len(slf.SelectValues) != 0 { + bts, err := json.Marshal(slf.SelectValues) + if err != nil { + return err + } + slf.SelectValue = string(bts) + } + return nil +} + +func (slf *Attribute) BeforeUpdate(tx *gorm.DB) (err error) { + if len(slf.SelectValues) != 0 { + bts, err := json.Marshal(slf.SelectValues) + if err != nil { + return err + } + slf.SelectValue = string(bts) + } + return nil +} + +func (slf *Attribute) AfterFind(tx *gorm.DB) (err error) { + if slf.SelectValue != "" { + var list []string + err = json.Unmarshal([]byte(slf.SelectValue), &list) + if err != nil { + return err + } + slf.SelectValues = list + } + return nil } func NewAttributeSearch() *AttributeSearch { @@ -62,6 +108,10 @@ slf.Name = name return slf } +func (slf *AttributeSearch) SetEntityType(entityType EntityType) *AttributeSearch { + slf.EntityType = entityType + return slf +} func (slf *AttributeSearch) build() *gorm.DB { var db = slf.Orm.Table(slf.TableName()) @@ -73,6 +123,9 @@ if slf.Order != "" { db = db.Order(slf.Order) } + if slf.EntityType != 0 { + db = db.Where("entity_type = ?", slf.EntityType) + } if slf.Name != "" { db = db.Where("name = ?", slf.Name) -- Gitblit v1.8.0