From ebf654c57e65b074ce4cc3b7016cf157a85fb3ad Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 11 三月 2024 15:18:24 +0800
Subject: [PATCH] wms采购范围

---
 models/material.go |   36 ++++++++++++++++++++++++++++++++++++
 docs/swagger.yaml  |    4 ++++
 docs/docs.go       |    6 ++++++
 docs/swagger.json  |    6 ++++++
 4 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/docs/docs.go b/docs/docs.go
index 422dacf..9c1cc47 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -3326,6 +3326,12 @@
                 "purchaseType": {
                     "$ref": "#/definitions/constvar.PurchaseType"
                 },
+                "purchaseTypeList": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
                 "reorderRuleNum": {
                     "type": "integer"
                 },
diff --git a/docs/swagger.json b/docs/swagger.json
index f858031..ba2a3f4 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -3314,6 +3314,12 @@
                 "purchaseType": {
                     "$ref": "#/definitions/constvar.PurchaseType"
                 },
+                "purchaseTypeList": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
                 "reorderRuleNum": {
                     "type": "integer"
                 },
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index ee77203..b3019db 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -565,6 +565,10 @@
         type: number
       purchaseType:
         $ref: '#/definitions/constvar.PurchaseType'
+      purchaseTypeList:
+        items:
+          type: integer
+        type: array
       reorderRuleNum:
         type: integer
       salePrice:
diff --git a/models/material.go b/models/material.go
index 721368f..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"`
@@ -109,6 +113,38 @@
 	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().Where("is_storage = ?", 1)} //鍙煡璇㈡湁搴撳瓨鐨�
 }

--
Gitblit v1.8.0