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] 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"`