zhangqian
2024-07-31 076f911a3b8d09364d1d8c98a92b48e601ae6a21
位置对应产品列表增加产品类别筛选
3个文件已修改
31 ■■■■ 已修改文件
controllers/location_product_amount.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/location_product_amount.go 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/location_product_amount.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/location_product_amount.go
@@ -181,6 +181,7 @@
        SetPage(params.Page, params.PageSize).
        SetOrder("id desc").
        SetPreload(true).
        SetCategoryIds(params.CategoryIds).
        FindByPage()
    if err != nil {
        util.ResponseFormat(c, code.InternalError, "查询失败")
models/location_product_amount.go
@@ -36,11 +36,13 @@
        Orm      *gorm.DB
        Preload  bool
        //LocationProductIds []int
        LocationIds []int
        ProductIds  []string
        Ids         []int
        Query       string
        Fields      string
        LocationIds     []int
        ProductIds      []string
        Ids             []int
        Query           string
        Fields          string
        CategoryIds     []int
        JoinedMaterials bool
    }
    LocationProductAmountWithOperation struct {
@@ -172,6 +174,11 @@
    return slf
}
func (slf *LocationProductAmountSearch) SetCategoryIds(ids []int) *LocationProductAmountSearch {
    slf.CategoryIds = ids
    return slf
}
func (slf *LocationProductAmountSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&LocationProductAmount{})
@@ -183,6 +190,10 @@
    }
    if slf.Keyword != "" {
        if !slf.JoinedMaterials {
            db = db.Joins("left join material on wms_location_product_amount.product_id = material.id")
            slf.JoinedMaterials = true
        }
        db = db.Joins("left join wms_location on wms_location_product_amount.location_id = wms_location.id").
            Joins("left join material on wms_location_product_amount.product_id = material.id").
            Joins("left join wms_product_category on wms_location_product_amount.product_category_id = wms_product_category.id").
@@ -226,6 +237,14 @@
        db = db.Select(slf.Fields)
    }
    if len(slf.CategoryIds) > 0 {
        if !slf.JoinedMaterials {
            db = db.Joins("left join material on wms_location_product_amount.product_id = material.id")
            slf.JoinedMaterials = true
        }
        db = db.Where("material.category_id in ?", slf.CategoryIds)
    }
    return db
}
request/location_product_amount.go
@@ -44,4 +44,5 @@
    Keyword     string `json:"keyword"`
    WarehouseId int    `json:"warehouseId"`
    LocationId  int    `json:"locationId"`
    CategoryIds []int  `json:"categoryIds"`
}