From ea02a2a9a8219d44b103f0a31cf9fc81ff8495e1 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期六, 23 九月 2023 16:57:48 +0800 Subject: [PATCH] 产品列表添加类型名称 --- controllers/product_controller.go | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index 0f57587..a47c9a1 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -74,6 +74,22 @@ return } + ids := make([]int, 0) + for _, product := range products { + ids = append(ids, product.CategoryId) + } + categories, err := models.NewProductCategorySearch().SetIds(ids).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷鏌ユ壘澶辫触") + return + } + for _, product := range products { + for _, category := range categories { + if product.CategoryId == int(category.ID) { + product.CategoryName = category.Name + } + } + } util.ResponseFormatList(c, code.Success, products, int(total)) } -- Gitblit v1.8.0