fix
This commit is contained in:
parent
4e13550044
commit
eb25e5bfcc
|
@ -3,6 +3,7 @@ package logic
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
|
@ -68,7 +69,6 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", priceInfo.Id))
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", priceInfo.Id))
|
||||||
}
|
}
|
||||||
lenStepNum := len(stepNumSlice)
|
lenStepNum := len(stepNumSlice)
|
||||||
lenStepPrice := len(stepPriceSlice)
|
|
||||||
itemList := make([]types.PriceItem, 0, 10)
|
itemList := make([]types.PriceItem, 0, 10)
|
||||||
for *priceInfo.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) {
|
for *priceInfo.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) {
|
||||||
itemList = append(itemList, types.PriceItem{
|
itemList = append(itemList, types.PriceItem{
|
||||||
|
@ -79,6 +79,26 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
||||||
*priceInfo.MinBuyNum++
|
*priceInfo.MinBuyNum++
|
||||||
}
|
}
|
||||||
//组装阶梯数量范围价格
|
//组装阶梯数量范围价格
|
||||||
|
stepListRsp := l.dealWithStepRange(stepNumSlice, stepPriceSlice, priceInfo)
|
||||||
|
//排序(必须放在其他逻辑之后)
|
||||||
|
sort.Ints(stepPriceSlice)
|
||||||
|
minPrice := float64(stepPriceSlice[0]) / 100
|
||||||
|
maxPrice := float64(stepPriceSlice[len(stepPriceSlice)-1]) / 100
|
||||||
|
mapKey := l.getSizePriceMapKey(*priceInfo.SizeId)
|
||||||
|
mapRsp[mapKey] = &types.GetPriceByPidRsp{
|
||||||
|
Items: itemList,
|
||||||
|
MinPrice: minPrice,
|
||||||
|
MaxPrice: maxPrice,
|
||||||
|
StepPrice: stepListRsp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组装阶梯价格范围
|
||||||
|
func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []int, priceInfo gmodel.FsProductPrice) []types.StepPrice {
|
||||||
|
lenStepNum := len(stepNumSlice)
|
||||||
|
lenStepPrice := len(stepPriceSlice)
|
||||||
stepListRsp := make([]types.StepPrice, 0, lenStepNum)
|
stepListRsp := make([]types.StepPrice, 0, lenStepNum)
|
||||||
for numKey, stepNum := range stepNumSlice {
|
for numKey, stepNum := range stepNumSlice {
|
||||||
//先取最后一个
|
//先取最后一个
|
||||||
|
@ -104,22 +124,11 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
||||||
Range: rangeNum,
|
Range: rangeNum,
|
||||||
Price: tmpPrice,
|
Price: tmpPrice,
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
//排序(必须放在其他逻辑之后)
|
return stepListRsp
|
||||||
sort.Ints(stepPriceSlice)
|
|
||||||
minPrice := float64(stepPriceSlice[0]) / 100
|
|
||||||
maxPrice := float64(stepPriceSlice[len(stepPriceSlice)-1]) / 100
|
|
||||||
mapKey := l.getSizePriceMapKey(*priceInfo.SizeId)
|
|
||||||
mapRsp[mapKey] = &types.GetPriceByPidRsp{
|
|
||||||
Items: itemList,
|
|
||||||
MinPrice: minPrice,
|
|
||||||
MaxPrice: maxPrice,
|
|
||||||
StepPrice: stepListRsp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取mapKey
|
||||||
func (l *GetPriceByPidLogic) getSizePriceMapKey(sizeId int64) string {
|
func (l *GetPriceByPidLogic) getSizePriceMapKey(sizeId int64) string {
|
||||||
return fmt.Sprintf("_%d", sizeId)
|
return fmt.Sprintf("_%d", sizeId)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user