Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
6b3ad339c6
|
@ -68,18 +68,22 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
|||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", priceInfo.Id))
|
||||
}
|
||||
if len(stepPriceSlice) == 0 || len(stepNumSlice) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "number of step num or step price is zero")
|
||||
}
|
||||
lenStepNum := len(stepNumSlice)
|
||||
itemList := make([]types.PriceItem, 0, 10)
|
||||
for *priceInfo.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) {
|
||||
tmpMinBuyNum := *priceInfo.MinBuyNum
|
||||
for tmpMinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) {
|
||||
itemList = append(itemList, types.PriceItem{
|
||||
Num: *priceInfo.MinBuyNum,
|
||||
TotalNum: (*priceInfo.MinBuyNum) * (*priceInfo.EachBoxNum),
|
||||
Price: step_price.GetCentStepPrice(int(*priceInfo.MinBuyNum), stepNumSlice, stepPriceSlice),
|
||||
Num: tmpMinBuyNum,
|
||||
TotalNum: tmpMinBuyNum * (*priceInfo.EachBoxNum),
|
||||
Price: step_price.GetCentStepPrice(int(tmpMinBuyNum), stepNumSlice, stepPriceSlice),
|
||||
})
|
||||
*priceInfo.MinBuyNum++
|
||||
tmpMinBuyNum++
|
||||
}
|
||||
//组装阶梯数量范围价格
|
||||
stepListRsp := l.dealWithStepRange(stepNumSlice, stepPriceSlice, priceInfo)
|
||||
stepRange := l.dealWithStepRange(stepNumSlice, stepPriceSlice, priceInfo)
|
||||
//排序(必须放在其他逻辑之后)
|
||||
sort.Ints(stepPriceSlice)
|
||||
minPrice := float64(stepPriceSlice[0]) / 100
|
||||
|
@ -89,17 +93,17 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
|||
Items: itemList,
|
||||
MinPrice: minPrice,
|
||||
MaxPrice: maxPrice,
|
||||
StepPrice: stepListRsp,
|
||||
StepRange: stepRange,
|
||||
}
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
||||
}
|
||||
|
||||
// 组装阶梯价格范围
|
||||
func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []int, priceInfo gmodel.FsProductPrice) []types.StepPrice {
|
||||
func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []int, priceInfo gmodel.FsProductPrice) []types.StepRange {
|
||||
lenStepNum := len(stepNumSlice)
|
||||
lenStepPrice := len(stepPriceSlice)
|
||||
stepListRsp := make([]types.StepPrice, 0, lenStepNum)
|
||||
stepListRsp := make([]types.StepRange, 0, lenStepNum)
|
||||
for numKey, stepNum := range stepNumSlice {
|
||||
//先取最后一个
|
||||
tmpPrice := float64(stepPriceSlice[lenStepPrice-1]) / 100
|
||||
|
@ -108,20 +112,22 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in
|
|||
tmpPrice = float64(stepPriceSlice[numKey]) / 100
|
||||
}
|
||||
num := int64(stepNum) * (*priceInfo.EachBoxNum)
|
||||
rangeNum := ""
|
||||
if numKey < lenStepNum-1 { //前面的
|
||||
begin := int64(0)
|
||||
end := int64(0)
|
||||
if numKey == 0 { //第一个
|
||||
begin = *priceInfo.MinBuyNum * (*priceInfo.EachBoxNum)
|
||||
end = num - 1
|
||||
} else if numKey < lenStepNum-1 { //中间的
|
||||
nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum)
|
||||
//第一个
|
||||
if numKey == 0 {
|
||||
rangeNum = fmt.Sprintf("%d-%dPCS", num, nextNum-1)
|
||||
} else {
|
||||
rangeNum = fmt.Sprintf("%d-%dPCS", num, nextNum-1)
|
||||
}
|
||||
} else { //最后一个
|
||||
rangeNum = fmt.Sprintf(">=%dPCS", num)
|
||||
begin = num
|
||||
end = nextNum - 1
|
||||
} else { //最后的
|
||||
begin = num
|
||||
end = -1
|
||||
}
|
||||
stepListRsp = append(stepListRsp, types.StepPrice{
|
||||
Range: rangeNum,
|
||||
stepListRsp = append(stepListRsp, types.StepRange{
|
||||
Begin: begin,
|
||||
End: end,
|
||||
Price: tmpPrice,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -142,6 +142,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
if len(priceSlice) == 0 {
|
||||
continue
|
||||
}
|
||||
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
|
||||
sort.Ints(priceSlice)
|
||||
if min, ok := mapProductMinPrice[v.ProductId]; ok {
|
||||
if min > int64(priceSlice[0]) {
|
||||
|
@ -173,6 +174,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
//map tag菜单
|
||||
mapTagLevel := make(map[string]*types.TagItem)
|
||||
//处理tags数据
|
||||
minLevel := 0 //层级最高层(即prefix层级路径最短)
|
||||
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
|
||||
TagList: tagList,
|
||||
WithProduct: req.WithProduct,
|
||||
|
@ -183,23 +185,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
MapTagLevel: mapTagLevel,
|
||||
MapProductHaveOptionFitting: mapProductHaveOptionFitting,
|
||||
Size: req.Size,
|
||||
user: user,
|
||||
User: user,
|
||||
MinLevel: &minLevel,
|
||||
}); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||
TotalCategoryProduct: len(productList),
|
||||
TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系
|
||||
TagList: l.organizationLevelRelation(minLevel, mapTagLevel), //组装等级从属关系
|
||||
})
|
||||
}
|
||||
|
||||
// 排序推荐产品结构体
|
||||
type sortRecommendProduct struct {
|
||||
ProductId int64
|
||||
Sort int64
|
||||
}
|
||||
|
||||
// 处理tag菜单数据
|
||||
type dealWithTagMenuDataReq struct {
|
||||
TagList []gmodel.FsTags
|
||||
|
@ -211,11 +208,17 @@ type dealWithTagMenuDataReq struct {
|
|||
MapTagLevel map[string]*types.TagItem
|
||||
MapProductHaveOptionFitting map[int64]struct{}
|
||||
Size uint32
|
||||
user gmodel.FsUser
|
||||
User gmodel.FsUser
|
||||
MinLevel *int //层级最小的
|
||||
}
|
||||
|
||||
func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error {
|
||||
for _, tagInfo := range req.TagList {
|
||||
prefixSlice := strings.Split(*tagInfo.LevelPrefix, "/")
|
||||
lenLevel := len(prefixSlice)
|
||||
if *req.MinLevel > lenLevel || *req.MinLevel == 0 {
|
||||
*req.MinLevel = lenLevel
|
||||
}
|
||||
tagTem := types.TagItem{
|
||||
TagProductList: nil,
|
||||
TypeName: *tagInfo.Title,
|
||||
|
@ -238,7 +241,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
|||
MapProductSizeCount: req.MapProductSizeCount,
|
||||
MapProductHaveOptionFitting: req.MapProductHaveOptionFitting,
|
||||
Size: req.Size,
|
||||
User: req.user,
|
||||
User: req.User,
|
||||
})
|
||||
//赋值
|
||||
tagTem.TagProductList = productListRsp
|
||||
|
@ -250,15 +253,15 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
|||
}
|
||||
|
||||
// 组织等级从属关系
|
||||
func (l *GetTagProductListLogic) organizationLevelRelation(mapTagLevel map[string]*types.TagItem) []types.TagItem {
|
||||
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) []types.TagItem {
|
||||
mapTop := make(map[string]struct{})
|
||||
for prefix, tagItem := range mapTagLevel {
|
||||
//最上级没有父级
|
||||
if !strings.Contains(prefix, "/") {
|
||||
prefixSlice := strings.Split(prefix, "/")
|
||||
//存储最高等级
|
||||
if len(prefixSlice) == minLevel {
|
||||
mapTop[prefix] = struct{}{}
|
||||
continue
|
||||
}
|
||||
prefixSlice := strings.Split(prefix, "/")
|
||||
//有父级
|
||||
parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/")
|
||||
parent, ok := mapTagLevel[parentPrefix]
|
||||
|
|
|
@ -309,11 +309,12 @@ type GetPriceByPidRsp struct {
|
|||
Items []PriceItem `json:"items"`
|
||||
MinPrice float64 `json:"min_price"`
|
||||
MaxPrice float64 `json:"max_price"`
|
||||
StepPrice []StepPrice `json:"step_price"`
|
||||
StepRange []StepRange `json:"step_range"`
|
||||
}
|
||||
|
||||
type StepPrice struct {
|
||||
Range string `json:"range"`
|
||||
type StepRange struct {
|
||||
Begin int64 `json:"begin"`
|
||||
End int64 `json:"end"`
|
||||
Price float64 `json:"price"`
|
||||
}
|
||||
|
||||
|
|
|
@ -357,10 +357,11 @@ type GetPriceByPidRsp {
|
|||
Items []PriceItem `json:"items"`
|
||||
MinPrice float64 `json:"min_price"`
|
||||
MaxPrice float64 `json:"max_price"`
|
||||
StepPrice []StepPrice `json:"step_price"`
|
||||
StepRange []StepRange `json:"step_range"`
|
||||
}
|
||||
type StepPrice {
|
||||
Range string `json:"range"`
|
||||
type StepRange {
|
||||
Begin int64 `json:"begin"`
|
||||
End int64 `json:"end"`
|
||||
Price float64 `json:"price"`
|
||||
}
|
||||
type PriceItem {
|
||||
|
|
Loading…
Reference in New Issue
Block a user