From 216c9e49dafdb7a5bd025f6d6fa899a33befc38c Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期三, 17 四月 2024 10:33:01 +0800 Subject: [PATCH] 产品添加字段 --- models/material.go | 43 ++++++++++++++++++++++++++++++++++++------- 1 files changed, 36 insertions(+), 7 deletions(-) diff --git a/models/material.go b/models/material.go index 3db5575..5c03da9 100644 --- a/models/material.go +++ b/models/material.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "fmt" "github.com/shopspring/decimal" "github.com/spf13/cast" @@ -71,13 +72,20 @@ //HSCode string `gorm:"type:varchar(255);comment:HS缂栫爜" json:"HSCode"` //HS缂栫爜 //OriginCountryId int `gorm:"type:int(11);comment:鍘熶骇鍦癷d" json:"originCountryId"` //鍘熶骇鍦癷d //OriginCountryName string `gorm:"type:varchar(255);comment:鍘熶骇鍦板悕绉�" json:"originCountryName"` //鍘熶骇鍦板悕绉� - InStorageExplain string `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"` //鍏ュ簱璇存槑 - OutStorageExplain string `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"` //鍑哄簱璇存槑 - InternalTransferExplain string `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑 - AttachmentList []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"` - IsStorage int `gorm:"type:tinyint(1);default:1;comment:鏄惁瀛樺簱(1鏄�2鍚�)" json:"isStorage"` //鏃犲簱瀛樼殑鍦╳ms浠ュ強srm涓渶瑕佽繃婊ゆ帀 - IsVirtual int `json:"isVirtual" gorm:"type:tinyint(1);default:2;comment:鏄惁铏氭嫙鐗╂枡(1鏄�2鍚�)"` //铏氭嫙鐗╂枡鍦∕RP璁$畻鏃惰烦杩囪灞傜骇鐩存帴棰嗙敤涓嬬骇鐗╂枡锛岃櫄鎷熺墿鏂欎笉鐢熸垚宸ュ崟 - ReorderRuleNum int64 `json:"reorderRuleNum"` + InStorageExplain string `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"` //鍏ュ簱璇存槑 + OutStorageExplain string `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"` //鍑哄簱璇存槑 + InternalTransferExplain string `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑 + AttachmentList []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"` + IsStorage int `gorm:"type:tinyint(1);default:1;comment:鏄惁瀛樺簱(1鏄�2鍚�)" json:"isStorage"` //鏃犲簱瀛樼殑鍦╳ms浠ュ強srm涓渶瑕佽繃婊ゆ帀 + IsVirtual int `json:"isVirtual" gorm:"type:tinyint(1);default:2;comment:鏄惁铏氭嫙鐗╂枡(1鏄�2鍚�)"` //铏氭嫙鐗╂枡鍦∕RP璁$畻鏃惰烦杩囪灞傜骇鐩存帴棰嗙敤涓嬬骇鐗╂枡锛岃櫄鎷熺墿鏂欎笉鐢熸垚宸ュ崟 + ReorderRuleNum int64 `json:"reorderRuleNum"` + 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:鍑�閲嶅崟浣�"` //浠ヤ笅涓轰笉瀛樺簱鐨勫瓧娈� AttachmentIDs []uint `json:"attachmentIDs" gorm:"-"` @@ -107,6 +115,12 @@ Id string `json:"id"` Name string `json:"name"` } + + UnitItems struct { + Amount decimal.Decimal `json:"amount"` + Unit string `json:"unit"` + Floating bool `json:"floating"` + } ) func (slf Material) TableName() string { @@ -121,6 +135,14 @@ } } 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 } @@ -138,6 +160,13 @@ slf.PurchaseType = constvar.PurchaseType(slf.PurchaseTypeList[0]) } } + if len(slf.MoreUnitList) != 0 { + str, err := json.Marshal(slf.MoreUnitList) + if err != nil { + return err + } + slf.MoreUnitValue = string(str) + } return } -- Gitblit v1.8.0