From aeed976c2999e2cea097cdee38d8baeefe323f3d Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期六, 30 三月 2024 16:15:59 +0800
Subject: [PATCH] 修改

---
 models/material.go |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/models/material.go b/models/material.go
index fd2e51b..3db5575 100644
--- a/models/material.go
+++ b/models/material.go
@@ -3,7 +3,9 @@
 import (
 	"fmt"
 	"github.com/shopspring/decimal"
+	"github.com/spf13/cast"
 	"gorm.io/gorm"
+	"strings"
 	"wms/constvar"
 	"wms/pkg/mysqlx"
 )
@@ -34,6 +36,8 @@
 		//ProduceAheadDay   int                     `gorm:"type:int(11);comment:鍒堕�犳彁鍓嶆湡(澶�)" json:"produceAheadDay"`
 		MinPurchaseAmount decimal.Decimal       `gorm:"type:decimal(35,18);comment:鏈�灏忛噰璐噺" json:"minPurchaseAmount"` //鏈�灏忛噰璐噺
 		PurchaseType      constvar.PurchaseType `gorm:"type:int(11);comment:閲囪喘绫诲瀷" json:"purchaseType"`
+		PurchaseTypes     string                `gorm:"type:varchar(255);comment:閲囪喘绫诲瀷鑼冨洿" json:"-"`
+		PurchaseTypeList  []int                 `gorm:"-" json:"purchaseTypeList"`
 		IsSale            bool                  `gorm:"type:tinyint(1);comment:鏄惁閿�鍞�" json:"isSale"`        //鏄惁閿�鍞�
 		SalePrice         decimal.Decimal       `gorm:"type:decimal(35,18);comment:閿�鍞崟浠�" json:"salePrice"` //閿�鍞崟浠�
 		AutoIncr          uint                  `gorm:"type:int(11);comment:鑷ID;default:0;" json:"autoIncr"`
@@ -59,7 +63,7 @@
 		ControlStrategy     constvar.InvoicingStrategy `gorm:"type:int(11);comment:鎺у埗绛栫暐" json:"controlStrategy"`             //鎺у埗绛栫暐
 		BuyExplain          string                     `gorm:"type:varchar(512);comment:閲囪喘璇存槑" json:"buyExplain"`             //閲囪喘璇存槑
 		Principal           string                     `gorm:"type:varchar(255);comment:璐熻矗浜�" json:"principal"`               //璐熻矗浜�
-		Weight              decimal.Decimal            `gorm:"type:decimal(20,2);comment:閲嶉噺" json:"weight"`                  //閲嶉噺
+		Weight              decimal.Decimal            `gorm:"type:decimal(20,3);comment:閲嶉噺" json:"weight"`                  //閲嶉噺
 		Volume              decimal.Decimal            `gorm:"type:decimal(20,2);comment:浣撶Н" json:"volume"`                  //浣撶Н
 		MakeAdvanceTime     decimal.Decimal            `gorm:"type:decimal(20,2);comment:鍒堕�犲墠缃椂闂�" json:"makeAdvanceTime"`     //鍒堕�犲墠缃椂闂�(澶�)
 		OrderAdvanceTime    decimal.Decimal            `gorm:"type:decimal(20,2);comment:璁㈠崟鍑嗗澶╂暟" json:"orderAdvanceTime"`    //璁㈠崟鍑嗗澶╂暟(澶�)
@@ -71,7 +75,18 @@
 		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"`
-		AttachmentIDs           []uint        `json:"attachmentIDs" gorm:"-"`
+		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"`
+
+		//浠ヤ笅涓轰笉瀛樺簱鐨勫瓧娈�
+		AttachmentIDs    []uint          `json:"attachmentIDs" gorm:"-"`
+		PredictionAmount decimal.Decimal `json:"predictionAmount" gorm:"-"`
+		InputAmount      decimal.Decimal `json:"inputAmount" gorm:"-"`
+		OutputAmount     decimal.Decimal `json:"outputAmount" gorm:"-"`
+		MinInventoryRule decimal.Decimal `json:"minInventoryRule" gorm:"-"` //鏈�灏忓簱瀛�
+		MaxInventoryRule decimal.Decimal `json:"maxInventoryRule" gorm:"-"` //鏈�澶у簱瀛�
+
 	}
 
 	MaterialSearch struct {
@@ -98,8 +113,40 @@
 	return "material"
 }
 
+func (slf *Material) AfterFind(tx *gorm.DB) (err error) {
+	if slf.PurchaseTypes != "" && strings.Contains(slf.PurchaseTypes, ",") {
+		list := strings.Split(slf.PurchaseTypes, ",")
+		for _, v := range list {
+			slf.PurchaseTypeList = append(slf.PurchaseTypeList, cast.ToInt(v))
+		}
+	} else if slf.PurchaseType != 0 { //鍏煎鏃ф暟鎹�
+		slf.PurchaseTypeList = append(slf.PurchaseTypeList, int(slf.PurchaseType))
+	}
+	return
+}
+
+func (slf *Material) BeforeCreate(tx *gorm.DB) (err error) {
+	if len(slf.PurchaseTypeList) > 0 {
+		var typeList []string
+		for _, v := range slf.PurchaseTypeList {
+			if v != 0 {
+				typeList = append(typeList, cast.ToString(v))
+			}
+		}
+		slf.PurchaseTypes = strings.Join(typeList, ",")
+		if len(slf.PurchaseTypeList) == 1 {
+			slf.PurchaseType = constvar.PurchaseType(slf.PurchaseTypeList[0])
+		}
+	}
+	return
+}
+
+func (slf *Material) BeforeUpdate(tx *gorm.DB) (err error) {
+	return slf.BeforeCreate(tx)
+}
+
 func NewMaterialSearch() *MaterialSearch {
-	return &MaterialSearch{Orm: mysqlx.GetDB()}
+	return &MaterialSearch{Orm: mysqlx.GetDB().Where("is_storage = ?", 1)} //鍙煡璇㈡湁搴撳瓨鐨�
 }
 
 func (slf *MaterialSearch) SetOrm(tx *gorm.DB) *MaterialSearch {

--
Gitblit v1.8.0