From 155f70979af20ca520a55b89c6ec8cd46c43f8a5 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 31 七月 2024 15:47:33 +0800 Subject: [PATCH] 产品流水表增加多单位存储 --- models/move_history.go | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/models/move_history.go b/models/move_history.go index 4d7b10d..edaeb2e 100644 --- a/models/move_history.go +++ b/models/move_history.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "fmt" "github.com/shopspring/decimal" "gorm.io/gorm" @@ -29,6 +30,9 @@ ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id ToLocation string `json:"toLocation" gorm:"type:varchar(255);not null;comment:鐩爣浣嶇疆"` //鐩爣浣嶇疆 Operator string `json:"operator" gorm:"type:varchar(255);not null;comment:鎿嶄綔鑰�"` //鎿嶄綔鑰� + + MoreUnitList []UnitItems `json:"moreUnitList" gorm:"-"` + MoreUnitValue string `json:"-" gorm:"type:varchar(255);comment:澶氬崟浣嶅��"` } MoveHistorySearch struct { @@ -46,6 +50,37 @@ return "wms_move_history" } +func (slf *MoveHistory) 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 *MoveHistory) 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 NewMoveHistorySearch() *MoveHistorySearch { return &MoveHistorySearch{Orm: mysqlx.GetDB()} } -- Gitblit v1.8.0