This commit is contained in:
laodaming 2023-06-07 18:09:54 +08:00
parent 9007cc8369
commit 996874a253
3 changed files with 50 additions and 41 deletions

View File

@ -41,7 +41,7 @@ func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
newResp := &Response{
Code: sr.Code,
Message: sr.Message,
Message: msg,
}
if len(data) == 1 {
newResp.Data = data[0]

View File

@ -2,6 +2,7 @@ package logic
import (
"context"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model"
@ -127,43 +128,51 @@ func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product
continue
}
priceList := make([]types.PriceObj, 0, len(productSizeList))
price, ok := mapProductPrice[productSize.Id]
//无对应尺寸价格
if price, ok := mapProductPrice[productSize.Id]; !ok {
priceList = []types.PriceObj{
{Num: 1, Price: 0},
{Num: 1, Price: 0},
{Num: 1, Price: 0},
}
} else {
price.StepNum = strings.Trim(price.StepNum, " ")
price.StepPrice = strings.Trim(price.StepPrice, " ")
if price.StepNum == "" || price.StepPrice == "" {
continue
}
//阶梯数量切片
stepNum, err := format.StrSlicToIntSlice(strings.Split(price.StepNum, ","))
if err != nil {
return nil, err
}
//阶梯价格切片
stepPrice, err := format.StrSlicToIntSlice(strings.Split(price.StepPrice, ","))
if err != nil {
return nil, err
}
for i := 0; i < 3; i++ {
// 最小购买数量小于 最大阶梯数量+5
if int(price.MinBuyNum) < (stepNum[len(stepNum)-1] + 5) {
priceList = append(priceList, types.PriceObj{
Num: int(price.MinBuyNum * price.EachBoxNum),
Price: l.GetPrice(int(price.MinBuyNum), stepNum, stepPrice),
})
}
price.MinBuyNum++
}
//如果不够三个则追加伪数据
for len(priceList) < 3 {
priceList = append(priceList, types.PriceObj{Num: 1, Price: 0})
if !ok {
childrenObjList = append(childrenObjList, types.ChildrenObj{
Id: productSize.Id,
Name: productSize.Capacity,
PriceList: []types.PriceObj{
{Num: 1, Price: 0},
{Num: 1, Price: 0},
{Num: 1, Price: 0},
},
})
continue
}
price.StepNum = strings.Trim(price.StepNum, " ")
price.StepPrice = strings.Trim(price.StepPrice, " ")
if price.StepNum == "" || price.StepPrice == "" {
continue
}
//阶梯数量切片
stepNum, err := format.StrSlicToIntSlice(strings.Split(price.StepNum, ","))
if err != nil {
return nil, err
}
//阶梯价格切片
stepPrice, err := format.StrSlicToIntSlice(strings.Split(price.StepPrice, ","))
if err != nil {
return nil, err
}
if len(stepNum) > len(stepPrice) {
return nil, errors.New(fmt.Sprintf("stepNum count not eq stepPrice count: product size id :%d ,product price id :%d", productSize.Id, price.Id))
}
for i := 0; i < 3; i++ {
// 最小购买数量小于 最大阶梯数量+5
if int(price.MinBuyNum) < (stepNum[len(stepNum)-1] + 5) {
priceList = append(priceList, types.PriceObj{
Num: int(price.MinBuyNum * price.EachBoxNum),
Price: l.GetPrice(int(price.MinBuyNum), stepNum, stepPrice),
})
}
price.MinBuyNum++
}
//如果不够三个则追加伪数据
for len(priceList) < 3 {
priceList = append(priceList, types.PriceObj{Num: 1, Price: 0})
}
data := types.ChildrenObj{
Id: productSize.Id,
@ -174,10 +183,10 @@ func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product
}
return
}
func (l *GetSizeByProductLogic) GetPrice(num int, stepNum []int, stepPrice []int) float64 {
for _, v := range stepNum {
if num <= v {
return float64(v) / float64(100)
func (l *GetSizeByProductLogic) GetPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 {
for k, v := range stepNum {
if minBuyNum <= v {
return float64(stepPrice[k]) / float64(100)
}
}
return float64(stepPrice[len(stepPrice)-1]) / float64(100)

View File

@ -148,7 +148,7 @@ func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
newResp := &Response{
Code: sr.Code,
Message: sr.Message,
Message: msg,
}
if len(data) == 1 {
newResp.Data = data[0]