fix
This commit is contained in:
parent
44a3666d68
commit
985fc93d00
|
@ -8,6 +8,7 @@ import (
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/step_price"
|
"fusenapi/utils/step_price"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
@ -57,38 +58,57 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
||||||
}
|
}
|
||||||
//处理价格信息
|
//处理价格信息
|
||||||
mapRsp := make(map[string]*types.GetPriceByPidRsp)
|
mapRsp := make(map[string]*types.GetPriceByPidRsp)
|
||||||
for _, price := range priceList {
|
for _, priceInfo := range priceList {
|
||||||
stepNumSlice, err := format.StrSlicToIntSlice(strings.Split(*price.StepNum, ","))
|
stepNumSlice, err := format.StrSlicToIntSlice(strings.Split(*priceInfo.StepNum, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step num,price_id=%d", price.Id))
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step num,price_id=%d", priceInfo.Id))
|
||||||
}
|
}
|
||||||
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*price.StepPrice, ","))
|
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*priceInfo.StepPrice, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", price.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 *price.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) {
|
for *priceInfo.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) {
|
||||||
itemList = append(itemList, types.PriceItem{
|
itemList = append(itemList, types.PriceItem{
|
||||||
Num: *price.MinBuyNum,
|
Num: *priceInfo.MinBuyNum,
|
||||||
TotalNum: (*price.MinBuyNum) * (*price.EachBoxNum),
|
TotalNum: (*priceInfo.MinBuyNum) * (*priceInfo.EachBoxNum),
|
||||||
Price: step_price.GetCentStepPrice(int(*price.MinBuyNum), stepNumSlice, stepPriceSlice),
|
Price: step_price.GetCentStepPrice(int(*priceInfo.MinBuyNum), stepNumSlice, stepPriceSlice),
|
||||||
})
|
})
|
||||||
*price.MinBuyNum++
|
*priceInfo.MinBuyNum++
|
||||||
}
|
}
|
||||||
minPrice := float64(stepPriceSlice[len(stepPriceSlice)-1]) / 100
|
stepListRsp := make([]types.StepPrice, 0, lenStepNum)
|
||||||
maxPrice := float64(stepPriceSlice[0]) / 100
|
for numKey, stepNum := range stepNumSlice {
|
||||||
mapKey := l.getSizePriceMapKey(*price.SizeId)
|
//先取最后一个
|
||||||
if _, ok := mapRsp[mapKey]; ok {
|
tmpPrice := float64(stepPriceSlice[lenStepPrice-1]) / 100
|
||||||
mapRsp[mapKey].Items = append(mapRsp[mapKey].Items, itemList...)
|
//如果同下标下面有价格
|
||||||
mapRsp[mapKey].MinPrice = minPrice
|
if numKey < lenStepPrice {
|
||||||
mapRsp[mapKey].MaxPrice = maxPrice
|
tmpPrice = float64(stepPriceSlice[numKey]) / 100
|
||||||
} else {
|
|
||||||
mapRsp[mapKey] = &types.GetPriceByPidRsp{
|
|
||||||
Items: itemList,
|
|
||||||
MinPrice: minPrice,
|
|
||||||
MaxPrice: maxPrice,
|
|
||||||
}
|
}
|
||||||
|
num := int64(stepNum) * (*priceInfo.EachBoxNum)
|
||||||
|
rangeNum := fmt.Sprintf("%dPCS", num)
|
||||||
|
//不是最后一个
|
||||||
|
if numKey < lenStepNum-1 {
|
||||||
|
nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum)
|
||||||
|
rangeNum = fmt.Sprintf("%d-%dPCS", num, nextNum-1)
|
||||||
|
}
|
||||||
|
stepListRsp = append(stepListRsp, types.StepPrice{
|
||||||
|
Range: rangeNum,
|
||||||
|
Price: tmpPrice,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
//排序(必须放在其他逻辑之后)
|
||||||
|
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)
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
||||||
|
|
|
@ -306,9 +306,15 @@ type GetPriceByPidReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetPriceByPidRsp struct {
|
type GetPriceByPidRsp struct {
|
||||||
Items []PriceItem `json:"items"`
|
Items []PriceItem `json:"items"`
|
||||||
MinPrice float64 `json:"min_price"`
|
MinPrice float64 `json:"min_price"`
|
||||||
MaxPrice float64 `json:"max_price"`
|
MaxPrice float64 `json:"max_price"`
|
||||||
|
StepPrice []StepPrice `json:"step_price"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StepPrice struct {
|
||||||
|
Range string `json:"range"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PriceItem struct {
|
type PriceItem struct {
|
||||||
|
|
|
@ -354,9 +354,14 @@ type GetPriceByPidReq {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
}
|
}
|
||||||
type GetPriceByPidRsp {
|
type GetPriceByPidRsp {
|
||||||
Items []PriceItem `json:"items"`
|
Items []PriceItem `json:"items"`
|
||||||
MinPrice float64 `json:"min_price"`
|
MinPrice float64 `json:"min_price"`
|
||||||
MaxPrice float64 `json:"max_price"`
|
MaxPrice float64 `json:"max_price"`
|
||||||
|
StepPrice []StepPrice `json:"step_price"`
|
||||||
|
}
|
||||||
|
type StepPrice {
|
||||||
|
Range string `json:"range"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
}
|
}
|
||||||
type PriceItem {
|
type PriceItem {
|
||||||
Num int64 `json:"num"`
|
Num int64 `json:"num"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user