From 70e86bec4055bdc2fdbff8e1aa8e8bc41c32b2f0 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期六, 21 十月 2023 17:42:42 +0800
Subject: [PATCH] 产品添加限制修改
---
models/location_product.go | 34 +++++++++++++++++++++++++---------
1 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/models/location_product.go b/models/location_product.go
index bc98181..f42e2fe 100644
--- a/models/location_product.go
+++ b/models/location_product.go
@@ -22,12 +22,13 @@
LocationProductSearch struct {
LocationProduct
- Order string
- PageNum int
- PageSize int
- Keyword string
- Orm *gorm.DB
- Preload bool
+ Order string
+ PageNum int
+ PageSize int
+ Keyword string
+ Orm *gorm.DB
+ Preload bool
+ LocationIds []int
}
)
@@ -79,6 +80,11 @@
return slf
}
+func (slf *LocationProductSearch) SetLocationIds(locationIds []int) *LocationProductSearch {
+ slf.LocationIds = locationIds
+ return slf
+}
+
func (slf *LocationProductSearch) build() *gorm.DB {
var db = slf.Orm.Model(&LocationProduct{})
@@ -90,7 +96,13 @@
}
if slf.Keyword != "" {
- db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
+ //db = db.Where("Product.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
+ db.Joins("left join wms_location on wms_location_product.location_id = wms_location.id").
+ Joins("left join material on wms_location_product.product_id = material.id").
+ Joins("left join wms_product_category on wms_location_product.product_category_id = wms_product_category.id").
+ Where("wms_location.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)).
+ Or("material.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)).
+ Or("wms_product_category.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
}
if slf.Preload {
@@ -103,6 +115,10 @@
if slf.ProductId != "" {
db = db.Where("product_id=?", slf.ProductId)
+ }
+
+ if len(slf.LocationIds) > 0 {
+ db = db.Where("location_id in (?)", slf.LocationIds)
}
return db
@@ -171,7 +187,7 @@
if slf.PageNum*slf.PageSize > 0 {
db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
}
- if err := db.Find(&records).Error; err != nil {
+ if err := db.Preload("Location").Preload("ProductCategory").Preload("Product").Find(&records).Error; err != nil {
return records, total, fmt.Errorf("find records err: %v", err)
}
@@ -184,7 +200,7 @@
db = slf.build()
)
- if err := db.Find(&records).Error; err != nil {
+ if err := db.Preload("Location").Preload("ProductCategory").Preload("Product").Find(&records).Error; err != nil {
return records, fmt.Errorf("find records err: %v", err)
}
--
Gitblit v1.8.0