From 0b5270f3b7140795003a2e2a2bd7ce2d6f49f8f3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 16:14:42 +0800 Subject: [PATCH 1/9] fix --- .../internal/logic/gettagproductlistlogic.go | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 1d6a1a18..2b4aed13 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -173,6 +173,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR //map tag菜单 mapTagLevel := make(map[string]*types.TagItem) //处理tags数据 + minLevel := 0 //层级最高层(即prefix层级路径最短) if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{ TagList: tagList, WithProduct: req.WithProduct, @@ -183,23 +184,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR MapTagLevel: mapTagLevel, MapProductHaveOptionFitting: mapProductHaveOptionFitting, Size: req.Size, - user: user, + User: user, + MinLevel: &minLevel, }); err != nil { logx.Error(err) return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ TotalCategoryProduct: len(productList), - TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系 + TagList: l.organizationLevelRelation(minLevel, mapTagLevel), //组装等级从属关系 }) } -// 排序推荐产品结构体 -type sortRecommendProduct struct { - ProductId int64 - Sort int64 -} - // 处理tag菜单数据 type dealWithTagMenuDataReq struct { TagList []gmodel.FsTags @@ -211,11 +207,17 @@ type dealWithTagMenuDataReq struct { MapTagLevel map[string]*types.TagItem MapProductHaveOptionFitting map[int64]struct{} Size uint32 - user gmodel.FsUser + User gmodel.FsUser + MinLevel *int //层级最小的 } func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error { for _, tagInfo := range req.TagList { + prefixSlice := strings.Split(*tagInfo.LevelPrefix, "/") + lenLevel := len(prefixSlice) + if *req.MinLevel > lenLevel || *req.MinLevel == 0 { + *req.MinLevel = lenLevel + } tagTem := types.TagItem{ TagProductList: nil, TypeName: *tagInfo.Title, @@ -238,7 +240,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) MapProductSizeCount: req.MapProductSizeCount, MapProductHaveOptionFitting: req.MapProductHaveOptionFitting, Size: req.Size, - User: req.user, + User: req.User, }) //赋值 tagTem.TagProductList = productListRsp @@ -250,15 +252,15 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) } // 组织等级从属关系 -func (l *GetTagProductListLogic) organizationLevelRelation(mapTagLevel map[string]*types.TagItem) []types.TagItem { +func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) []types.TagItem { mapTop := make(map[string]struct{}) for prefix, tagItem := range mapTagLevel { - //最上级没有父级 - if !strings.Contains(prefix, "/") { + prefixSlice := strings.Split(prefix, "/") + //存储最高等级 + if len(prefixSlice) == minLevel { mapTop[prefix] = struct{}{} continue } - prefixSlice := strings.Split(prefix, "/") //有父级 parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/") parent, ok := mapTagLevel[parentPrefix] From 53a4df065c0db337d4f02cb817d48ab5360036d0 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 16:19:59 +0800 Subject: [PATCH 2/9] fix --- server/product/internal/logic/gettagproductlistlogic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 2b4aed13..f8d76155 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -142,6 +142,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR if len(priceSlice) == 0 { continue } + //正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算) sort.Ints(priceSlice) if min, ok := mapProductMinPrice[v.ProductId]; ok { if min > int64(priceSlice[0]) { From 133af63064d2da3542723aa1b195aceddd35a6ca Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 17:20:46 +0800 Subject: [PATCH 3/9] fix --- .../internal/logic/getpricebypidlogic.go | 27 ++++++++++--------- server/product/internal/types/types.go | 9 +++++-- server_api/product.api | 8 ++++-- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 5319555f..6c76d77a 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -108,21 +108,24 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in tmpPrice = float64(stepPriceSlice[numKey]) / 100 } num := int64(stepNum) * (*priceInfo.EachBoxNum) - rangeNum := "" - if numKey < lenStepNum-1 { //前面的 - nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) - //第一个 - if numKey == 0 { - rangeNum = fmt.Sprintf("%d-%dPCS", num, nextNum-1) - } else { - rangeNum = fmt.Sprintf("%d-%dPCS", num, nextNum-1) + rangeNum := types.RangeNum{} + //只有1个 + if lenStepNum == 1 { + rangeNum.Begin = num + rangeNum.End = 99999999999 + } else { + if numKey < lenStepNum-1 { //前面的 + nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) + rangeNum.Begin = num + rangeNum.End = nextNum - 1 + } else { //最后一个 + rangeNum.Begin = num + rangeNum.End = 99999999999 } - } else { //最后一个 - rangeNum = fmt.Sprintf(">=%dPCS", num) } stepListRsp = append(stepListRsp, types.StepPrice{ - Range: rangeNum, - Price: tmpPrice, + RangeNum: rangeNum, + Price: tmpPrice, }) } return stepListRsp diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index d073cec1..7df0dbda 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -313,8 +313,13 @@ type GetPriceByPidRsp struct { } type StepPrice struct { - Range string `json:"range"` - Price float64 `json:"price"` + RangeNum RangeNum `json:"range_num"` + Price float64 `json:"price"` +} + +type RangeNum struct { + Begin int64 `json:"begin"` + End int64 `json:"end"` } type PriceItem struct { diff --git a/server_api/product.api b/server_api/product.api index 26d504cd..7382f386 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -360,8 +360,12 @@ type GetPriceByPidRsp { StepPrice []StepPrice `json:"step_price"` } type StepPrice { - Range string `json:"range"` - Price float64 `json:"price"` + RangeNum RangeNum `json:"range_num"` + Price float64 `json:"price"` +} +type RangeNum { + Begin int64 `json:"begin"` + End int64 `json:"end"` } type PriceItem { Num int64 `json:"num"` From 83fc1b30c7122915abe3496cfb09458e98c016e5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 17:21:31 +0800 Subject: [PATCH 4/9] fix --- .../product/internal/logic/getpricebypidlogic.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 6c76d77a..7b02d9bd 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -109,19 +109,13 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in } num := int64(stepNum) * (*priceInfo.EachBoxNum) rangeNum := types.RangeNum{} - //只有1个 - if lenStepNum == 1 { + if numKey < lenStepNum-1 { //前面的 + nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) + rangeNum.Begin = num + rangeNum.End = nextNum - 1 + } else { //最后一个 rangeNum.Begin = num rangeNum.End = 99999999999 - } else { - if numKey < lenStepNum-1 { //前面的 - nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) - rangeNum.Begin = num - rangeNum.End = nextNum - 1 - } else { //最后一个 - rangeNum.Begin = num - rangeNum.End = 99999999999 - } } stepListRsp = append(stepListRsp, types.StepPrice{ RangeNum: rangeNum, From fef5d33f08806a8c53951218417e2106a1c8e3e3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 17:23:48 +0800 Subject: [PATCH 5/9] fix --- server/product/internal/logic/getpricebypidlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 7b02d9bd..e8224153 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -115,7 +115,7 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in rangeNum.End = nextNum - 1 } else { //最后一个 rangeNum.Begin = num - rangeNum.End = 99999999999 + rangeNum.End = -1 } stepListRsp = append(stepListRsp, types.StepPrice{ RangeNum: rangeNum, From 001716785dfadac27817ddc1f1f7f68c5db46b46 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 17:27:31 +0800 Subject: [PATCH 6/9] fix --- server/product/internal/logic/getpricebypidlogic.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index e8224153..56fe942e 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -68,6 +68,9 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo if err != nil { return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", priceInfo.Id)) } + if len(stepPriceSlice) == 0 || len(stepNumSlice) == 0 { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "number of step num or step price is zero") + } lenStepNum := len(stepNumSlice) itemList := make([]types.PriceItem, 0, 10) for *priceInfo.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) { From 91131161c9a021959083e0ee351d8d0eccd8346b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 17:31:28 +0800 Subject: [PATCH 7/9] fix --- server/product/internal/logic/getpricebypidlogic.go | 10 +++++----- server/product/internal/types/types.go | 4 ++-- server_api/product.api | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 56fe942e..c8fb8c57 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -82,7 +82,7 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo *priceInfo.MinBuyNum++ } //组装阶梯数量范围价格 - stepListRsp := l.dealWithStepRange(stepNumSlice, stepPriceSlice, priceInfo) + stepRange := l.dealWithStepRange(stepNumSlice, stepPriceSlice, priceInfo) //排序(必须放在其他逻辑之后) sort.Ints(stepPriceSlice) minPrice := float64(stepPriceSlice[0]) / 100 @@ -92,17 +92,17 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo Items: itemList, MinPrice: minPrice, MaxPrice: maxPrice, - StepPrice: stepListRsp, + StepRange: stepRange, } } return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) } // 组装阶梯价格范围 -func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []int, priceInfo gmodel.FsProductPrice) []types.StepPrice { +func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []int, priceInfo gmodel.FsProductPrice) []types.StepRange { lenStepNum := len(stepNumSlice) lenStepPrice := len(stepPriceSlice) - stepListRsp := make([]types.StepPrice, 0, lenStepNum) + stepListRsp := make([]types.StepRange, 0, lenStepNum) for numKey, stepNum := range stepNumSlice { //先取最后一个 tmpPrice := float64(stepPriceSlice[lenStepPrice-1]) / 100 @@ -120,7 +120,7 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in rangeNum.Begin = num rangeNum.End = -1 } - stepListRsp = append(stepListRsp, types.StepPrice{ + stepListRsp = append(stepListRsp, types.StepRange{ RangeNum: rangeNum, Price: tmpPrice, }) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 7df0dbda..8e21b3e8 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -309,10 +309,10 @@ type GetPriceByPidRsp struct { Items []PriceItem `json:"items"` MinPrice float64 `json:"min_price"` MaxPrice float64 `json:"max_price"` - StepPrice []StepPrice `json:"step_price"` + StepRange []StepRange `json:"step_price"` } -type StepPrice struct { +type StepRange struct { RangeNum RangeNum `json:"range_num"` Price float64 `json:"price"` } diff --git a/server_api/product.api b/server_api/product.api index 7382f386..f3cac168 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -357,9 +357,9 @@ type GetPriceByPidRsp { Items []PriceItem `json:"items"` MinPrice float64 `json:"min_price"` MaxPrice float64 `json:"max_price"` - StepPrice []StepPrice `json:"step_price"` + StepRange []StepRange `json:"step_price"` } -type StepPrice { +type StepRange { RangeNum RangeNum `json:"range_num"` Price float64 `json:"price"` } From 9400fcfaeb4804dc4fcdc4210d228df88ba3e46d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 17:32:15 +0800 Subject: [PATCH 8/9] fix --- server/product/internal/types/types.go | 2 +- server_api/product.api | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 8e21b3e8..9859cb9f 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -309,7 +309,7 @@ type GetPriceByPidRsp struct { Items []PriceItem `json:"items"` MinPrice float64 `json:"min_price"` MaxPrice float64 `json:"max_price"` - StepRange []StepRange `json:"step_price"` + StepRange []StepRange `json:"step_range"` } type StepRange struct { diff --git a/server_api/product.api b/server_api/product.api index f3cac168..11354e6f 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -357,7 +357,7 @@ type GetPriceByPidRsp { Items []PriceItem `json:"items"` MinPrice float64 `json:"min_price"` MaxPrice float64 `json:"max_price"` - StepRange []StepRange `json:"step_price"` + StepRange []StepRange `json:"step_range"` } type StepRange { RangeNum RangeNum `json:"range_num"` From 80a94de6df6310c7b06c342e3bb282c70239c19f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 17:49:02 +0800 Subject: [PATCH 9/9] fix --- .../internal/logic/getpricebypidlogic.go | 34 +++++++++++-------- server/product/internal/types/types.go | 10 ++---- server_api/product.api | 9 ++--- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index c8fb8c57..44bfe67a 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -73,13 +73,14 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo } lenStepNum := len(stepNumSlice) itemList := make([]types.PriceItem, 0, 10) - for *priceInfo.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) { + tmpMinBuyNum := *priceInfo.MinBuyNum + for tmpMinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) { itemList = append(itemList, types.PriceItem{ - Num: *priceInfo.MinBuyNum, - TotalNum: (*priceInfo.MinBuyNum) * (*priceInfo.EachBoxNum), - Price: step_price.GetCentStepPrice(int(*priceInfo.MinBuyNum), stepNumSlice, stepPriceSlice), + Num: tmpMinBuyNum, + TotalNum: tmpMinBuyNum * (*priceInfo.EachBoxNum), + Price: step_price.GetCentStepPrice(int(tmpMinBuyNum), stepNumSlice, stepPriceSlice), }) - *priceInfo.MinBuyNum++ + tmpMinBuyNum++ } //组装阶梯数量范围价格 stepRange := l.dealWithStepRange(stepNumSlice, stepPriceSlice, priceInfo) @@ -111,18 +112,23 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in tmpPrice = float64(stepPriceSlice[numKey]) / 100 } num := int64(stepNum) * (*priceInfo.EachBoxNum) - rangeNum := types.RangeNum{} - if numKey < lenStepNum-1 { //前面的 + begin := int64(0) + end := int64(0) + if numKey == 0 { //第一个 + begin = *priceInfo.MinBuyNum * (*priceInfo.EachBoxNum) + end = num - 1 + } else if numKey < lenStepNum-1 { //中间的 nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) - rangeNum.Begin = num - rangeNum.End = nextNum - 1 - } else { //最后一个 - rangeNum.Begin = num - rangeNum.End = -1 + begin = num + end = nextNum - 1 + } else { //最后的 + begin = num + end = -1 } stepListRsp = append(stepListRsp, types.StepRange{ - RangeNum: rangeNum, - Price: tmpPrice, + Begin: begin, + End: end, + Price: tmpPrice, }) } return stepListRsp diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 9859cb9f..c45e4775 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -313,13 +313,9 @@ type GetPriceByPidRsp struct { } type StepRange struct { - RangeNum RangeNum `json:"range_num"` - Price float64 `json:"price"` -} - -type RangeNum struct { - Begin int64 `json:"begin"` - End int64 `json:"end"` + Begin int64 `json:"begin"` + End int64 `json:"end"` + Price float64 `json:"price"` } type PriceItem struct { diff --git a/server_api/product.api b/server_api/product.api index 11354e6f..fdfdbc0c 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -360,12 +360,9 @@ type GetPriceByPidRsp { StepRange []StepRange `json:"step_range"` } type StepRange { - RangeNum RangeNum `json:"range_num"` - Price float64 `json:"price"` -} -type RangeNum { - Begin int64 `json:"begin"` - End int64 `json:"end"` + Begin int64 `json:"begin"` + End int64 `json:"end"` + Price float64 `json:"price"` } type PriceItem { Num int64 `json:"num"`