From 3e714a5db6eab333e14e1d138d685c85ba114891 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 12 Sep 2023 15:23:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/getsizebypidlogic.go | 39 ++++++++++++++----- server/product/internal/types/types.go | 4 +- server_api/product.api | 4 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/server/product/internal/logic/getsizebypidlogic.go b/server/product/internal/logic/getsizebypidlogic.go index 3f508762..7548a407 100644 --- a/server/product/internal/logic/getsizebypidlogic.go +++ b/server/product/internal/logic/getsizebypidlogic.go @@ -38,6 +38,9 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a if req.Pid == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty") } + if req.TemplateTag == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:template_tag is empty") + } //获取产品信息(只是获取id) productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id") if err != nil { @@ -66,6 +69,26 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list") } mapProductMinPrice := make(map[int64]int64) + //根据尺寸id集合获取模型列表 + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list") + } + mapSizeModel := make(map[int64]int) //size id为key + for k, v := range modelList { + mapSizeModel[*v.SizeId] = k + } + modelIds := make([]int64, 0, len(modelList)) + templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, req.TemplateTag, "sort ASC", "id") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list") + } + mapTemplate := make(map[int64]int64) + for _, v := range templateList { + mapTemplate[*v.ModelId] = v.Id + } //存储产品最小价格 for _, v := range productPriceList { priceStrSlic := strings.Split(v.Price, ",") @@ -87,16 +110,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a mapProductMinPrice[v.ProductId] = int64(priceSlice[0]) } } - //获取对应模型数据 - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list") - } - mapSizeModel := make(map[int64]int) //size id为key - for k, v := range modelList { - mapSizeModel[*v.SizeId] = k - } + //处理 listRsp := make([]types.GetSizeByPidRsp, 0, len(sizeList)) for _, sizeInfo := range sizeList { @@ -111,6 +125,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a if price, ok := mapProductMinPrice[*sizeInfo.ProductId]; ok { minPrice = price } + templateId := int64(0) + if tid, ok := mapTemplate[modelList[modelIndex].Id]; ok { + templateId = tid + } listRsp = append(listRsp, types.GetSizeByPidRsp{ Id: sizeInfo.Id, Title: title, @@ -120,6 +138,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a ModelId: modelList[modelIndex].Id, IsPopular: *sizeInfo.IsHot > 0, MinPrice: float64(minPrice) / 100, + TemplateId: templateId, }) } return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 7aed63d2..942c245d 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -332,7 +332,8 @@ type PriceItem struct { } type GetSizeByPidReq struct { - Pid string `form:"pid"` + Pid string `form:"pid"` + TemplateTag string `form:"template_tag"` } type GetSizeByPidRsp struct { @@ -344,6 +345,7 @@ type GetSizeByPidRsp struct { ModelId int64 `json:"model_id"` //产品主模型id IsPopular bool `json:"is_popular"` //是否受欢迎 MinPrice float64 `json:"min_price"` //最小价格 + TemplateId int64 `json:"template_id"` } type GetTemplateByPidReq struct { diff --git a/server_api/product.api b/server_api/product.api index 8a507386..3e1408cf 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -378,7 +378,8 @@ type PriceItem { } //获取产品尺寸列表 type GetSizeByPidReq { - Pid string `form:"pid"` + Pid string `form:"pid"` + TemplateTag string `form:"template_tag"` } type GetSizeByPidRsp { Id int64 `json:"id"` //尺寸id @@ -389,6 +390,7 @@ type GetSizeByPidRsp { ModelId int64 `json:"model_id"` //产品主模型id IsPopular bool `json:"is_popular"` //是否受欢迎 MinPrice float64 `json:"min_price"` //最小价格 + TemplateId int64 `json:"template_id"` } //获取产品模板 type GetTemplateByPidReq {