From 38e6fc986e19d4d215b00ee4db32929617810bca Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 26 九月 2023 09:30:49 +0800 Subject: [PATCH] 产品列表新增字段 --- controllers/product_controller.go | 2 +- models/material.go | 9 ++++++++- request/product_request.go | 3 ++- docs/swagger.yaml | 2 ++ docs/docs.go | 5 +++++ docs/swagger.json | 3 +++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index 15878dc..ea2a74b 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -76,7 +76,7 @@ if params.PageInfo.Check() { search.SetPage(params.Page, params.PageSize) } - products, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find() + products, total, err := search.SetKeyword(params.KeyWord).SetCategoryId(params.CategoryId).SetOrder("created_at desc").Find() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") return diff --git a/docs/docs.go b/docs/docs.go index 3d921fd..5554acc 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2650,6 +2650,9 @@ "request.GetProductList": { "type": "object", "properties": { + "categoryId": { + "type": "integer" + }, "keyWord": { "type": "string" }, @@ -3025,6 +3028,8 @@ Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index a8ff32a..86a516f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2638,6 +2638,9 @@ "request.GetProductList": { "type": "object", "properties": { + "categoryId": { + "type": "integer" + }, "keyWord": { "type": "string" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index f0f0d6e..d43edc4 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -835,6 +835,8 @@ type: object request.GetProductList: properties: + categoryId: + type: integer keyWord: type: string page: diff --git a/models/material.go b/models/material.go index dd74cb1..df61270 100644 --- a/models/material.go +++ b/models/material.go @@ -152,6 +152,10 @@ slf.TemplateID = id return slf } +func (slf *MaterialSearch) SetCategoryId(id int) *MaterialSearch { + slf.CategoryId = id + return slf +} // //func (slf *MaterialSearch) SetSetTemplateType(setType constvar.SetTemplateType) *MaterialSearch { @@ -207,7 +211,7 @@ //} if slf.Keyword != "" { - db = db.Where("name LIKE ? or id LIKE ? ", "%"+slf.Keyword+"%", "%"+slf.Keyword+"%") + db = db.Where("name LIKE ? ", "%"+slf.Keyword+"%") } if slf.Order != "" { @@ -223,6 +227,9 @@ if slf.IsSale { db = db.Where("is_sale = ?", 1) } + if slf.CategoryId > 0 { + db = db.Where("category_id = ?", slf.CategoryId) + } return db } diff --git a/request/product_request.go b/request/product_request.go index 0f16f7b..c33ccea 100644 --- a/request/product_request.go +++ b/request/product_request.go @@ -7,7 +7,8 @@ type GetProductList struct { PageInfo - KeyWord string `json:"keyWord"` + KeyWord string `json:"keyWord"` + CategoryId int `json:"categoryId"` } type QueryOperationList struct { -- Gitblit v1.8.0