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 { func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
newResp := &Response{ newResp := &Response{
Code: sr.Code, Code: sr.Code,
Message: sr.Message, Message: msg,
} }
if len(data) == 1 { if len(data) == 1 {
newResp.Data = data[0] newResp.Data = data[0]

View File

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