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

This commit is contained in:
Hiven 2023-07-21 18:17:43 +08:00
commit 6b3ad339c6
4 changed files with 52 additions and 41 deletions

View File

@ -68,18 +68,22 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
if err != nil { if err != nil {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", priceInfo.Id)) 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) lenStepNum := len(stepNumSlice)
itemList := make([]types.PriceItem, 0, 10) 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{ itemList = append(itemList, types.PriceItem{
Num: *priceInfo.MinBuyNum, Num: tmpMinBuyNum,
TotalNum: (*priceInfo.MinBuyNum) * (*priceInfo.EachBoxNum), TotalNum: tmpMinBuyNum * (*priceInfo.EachBoxNum),
Price: step_price.GetCentStepPrice(int(*priceInfo.MinBuyNum), stepNumSlice, stepPriceSlice), 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) sort.Ints(stepPriceSlice)
minPrice := float64(stepPriceSlice[0]) / 100 minPrice := float64(stepPriceSlice[0]) / 100
@ -89,17 +93,17 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
Items: itemList, Items: itemList,
MinPrice: minPrice, MinPrice: minPrice,
MaxPrice: maxPrice, MaxPrice: maxPrice,
StepPrice: stepListRsp, StepRange: stepRange,
} }
} }
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) 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) lenStepNum := len(stepNumSlice)
lenStepPrice := len(stepPriceSlice) lenStepPrice := len(stepPriceSlice)
stepListRsp := make([]types.StepPrice, 0, lenStepNum) stepListRsp := make([]types.StepRange, 0, lenStepNum)
for numKey, stepNum := range stepNumSlice { for numKey, stepNum := range stepNumSlice {
//先取最后一个 //先取最后一个
tmpPrice := float64(stepPriceSlice[lenStepPrice-1]) / 100 tmpPrice := float64(stepPriceSlice[lenStepPrice-1]) / 100
@ -108,20 +112,22 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in
tmpPrice = float64(stepPriceSlice[numKey]) / 100 tmpPrice = float64(stepPriceSlice[numKey]) / 100
} }
num := int64(stepNum) * (*priceInfo.EachBoxNum) num := int64(stepNum) * (*priceInfo.EachBoxNum)
rangeNum := "" begin := int64(0)
if numKey < lenStepNum-1 { //前面的 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) nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum)
//第一个 begin = num
if numKey == 0 { end = nextNum - 1
rangeNum = fmt.Sprintf("%d-%dPCS", num, nextNum-1) } else { //最后的
} else { begin = num
rangeNum = fmt.Sprintf("%d-%dPCS", num, nextNum-1) end = -1
} }
} else { //最后一个 stepListRsp = append(stepListRsp, types.StepRange{
rangeNum = fmt.Sprintf(">=%dPCS", num) Begin: begin,
} End: end,
stepListRsp = append(stepListRsp, types.StepPrice{
Range: rangeNum,
Price: tmpPrice, Price: tmpPrice,
}) })
} }

View File

@ -142,6 +142,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
if len(priceSlice) == 0 { if len(priceSlice) == 0 {
continue continue
} }
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
sort.Ints(priceSlice) sort.Ints(priceSlice)
if min, ok := mapProductMinPrice[v.ProductId]; ok { if min, ok := mapProductMinPrice[v.ProductId]; ok {
if min > int64(priceSlice[0]) { if min > int64(priceSlice[0]) {
@ -173,6 +174,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
//map tag菜单 //map tag菜单
mapTagLevel := make(map[string]*types.TagItem) mapTagLevel := make(map[string]*types.TagItem)
//处理tags数据 //处理tags数据
minLevel := 0 //层级最高层即prefix层级路径最短
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{ if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
TagList: tagList, TagList: tagList,
WithProduct: req.WithProduct, WithProduct: req.WithProduct,
@ -183,23 +185,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
MapTagLevel: mapTagLevel, MapTagLevel: mapTagLevel,
MapProductHaveOptionFitting: mapProductHaveOptionFitting, MapProductHaveOptionFitting: mapProductHaveOptionFitting,
Size: req.Size, Size: req.Size,
user: user, User: user,
MinLevel: &minLevel,
}); err != nil { }); err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
} }
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
TotalCategoryProduct: len(productList), TotalCategoryProduct: len(productList),
TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系 TagList: l.organizationLevelRelation(minLevel, mapTagLevel), //组装等级从属关系
}) })
} }
// 排序推荐产品结构体
type sortRecommendProduct struct {
ProductId int64
Sort int64
}
// 处理tag菜单数据 // 处理tag菜单数据
type dealWithTagMenuDataReq struct { type dealWithTagMenuDataReq struct {
TagList []gmodel.FsTags TagList []gmodel.FsTags
@ -211,11 +208,17 @@ type dealWithTagMenuDataReq struct {
MapTagLevel map[string]*types.TagItem MapTagLevel map[string]*types.TagItem
MapProductHaveOptionFitting map[int64]struct{} MapProductHaveOptionFitting map[int64]struct{}
Size uint32 Size uint32
user gmodel.FsUser User gmodel.FsUser
MinLevel *int //层级最小的
} }
func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error { func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error {
for _, tagInfo := range req.TagList { 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{ tagTem := types.TagItem{
TagProductList: nil, TagProductList: nil,
TypeName: *tagInfo.Title, TypeName: *tagInfo.Title,
@ -238,7 +241,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
MapProductSizeCount: req.MapProductSizeCount, MapProductSizeCount: req.MapProductSizeCount,
MapProductHaveOptionFitting: req.MapProductHaveOptionFitting, MapProductHaveOptionFitting: req.MapProductHaveOptionFitting,
Size: req.Size, Size: req.Size,
User: req.user, User: req.User,
}) })
//赋值 //赋值
tagTem.TagProductList = productListRsp 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{}) mapTop := make(map[string]struct{})
for prefix, tagItem := range mapTagLevel { for prefix, tagItem := range mapTagLevel {
//最上级没有父级 prefixSlice := strings.Split(prefix, "/")
if !strings.Contains(prefix, "/") { //存储最高等级
if len(prefixSlice) == minLevel {
mapTop[prefix] = struct{}{} mapTop[prefix] = struct{}{}
continue continue
} }
prefixSlice := strings.Split(prefix, "/")
//有父级 //有父级
parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/") parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/")
parent, ok := mapTagLevel[parentPrefix] parent, ok := mapTagLevel[parentPrefix]

View File

@ -309,11 +309,12 @@ 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"` StepRange []StepRange `json:"step_range"`
} }
type StepPrice struct { type StepRange struct {
Range string `json:"range"` Begin int64 `json:"begin"`
End int64 `json:"end"`
Price float64 `json:"price"` Price float64 `json:"price"`
} }

View File

@ -357,10 +357,11 @@ 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"` StepRange []StepRange `json:"step_range"`
} }
type StepPrice { type StepRange {
Range string `json:"range"` Begin int64 `json:"begin"`
End int64 `json:"end"`
Price float64 `json:"price"` Price float64 `json:"price"`
} }
type PriceItem { type PriceItem {