Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson
2023-06-08 10:52:31 +08:00
15 changed files with 402 additions and 36 deletions

View File

@@ -22,17 +22,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/product/success-recommand",
Handler: GetSuccessRecommandHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/product/get-size-by-product",
Handler: GetSizeByProductHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
)
}

View File

@@ -157,22 +157,18 @@ func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product
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))
if len(stepNum) == 0 || len(stepPrice) == 0 {
return nil, errors.New(fmt.Sprintf("stepNum count or stepPrice count is empty: 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),
})
}
index := 0
// 最小购买数量小于 最大阶梯数量+5
for int(price.MinBuyNum) < (stepNum[len(stepNum)-1]+5) && index < 3 {
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})
index++
}
data := types.ChildrenObj{
Id: productSize.Id,
@@ -184,9 +180,15 @@ func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product
return
}
func (l *GetSizeByProductLogic) GetPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 {
if minBuyNum > stepNum[len(stepNum)-1] {
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
}
for k, v := range stepNum {
if minBuyNum <= v {
return float64(stepPrice[k]) / float64(100)
if k <= (len(stepPrice) - 1) {
return float64(stepPrice[k]) / float64(100)
}
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
}
}
return float64(stepPrice[len(stepPrice)-1]) / float64(100)