| | |
| | | package models |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | |
| | | // 嘉联仓储添加 SilkMarket、SilkMarketClose |
| | | SilkMarket string `json:"silkMarket" gorm:"type:varchar(255);comment:庄口"` // 庄口 |
| | | SilkMarketClose string `json:"silkMarketClose" gorm:"type:varchar(10);comment:庄口关闭"` // 庄口关闭 |
| | | |
| | | MoreUnitList []UnitItems `json:"moreUnitList" gorm:"-"` |
| | | MoreUnitValue string `json:"-" gorm:"type:varchar(255);comment:多单位值"` |
| | | } |
| | | |
| | | OperationDetailsSearch struct { |
| | |
| | | return &OperationDetailsSearch{Orm: mysqlx.GetDB()} |
| | | } |
| | | |
| | | func (slf *OperationDetails) AfterFind(tx *gorm.DB) (err error) { |
| | | if slf.MoreUnitValue != "" { |
| | | var arr []UnitItems |
| | | err := json.Unmarshal([]byte(slf.MoreUnitValue), &arr) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | slf.MoreUnitList = arr |
| | | } |
| | | |
| | | return |
| | | } |
| | | |
| | | func (slf *OperationDetails) BeforeCreate(tx *gorm.DB) (err error) { |
| | | 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 *OperationDetailsSearch) SetOrm(tx *gorm.DB) *OperationDetailsSearch { |
| | | slf.Orm = tx |
| | | return slf |