Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
2f4f59d6ab
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 阶梯价结构
|
// 阶梯价结构
|
||||||
@ -173,11 +174,11 @@ func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, prod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取每个产品最低价格
|
// 获取每个产品最低价格
|
||||||
func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productIds []int64) (productMinPrice map[int64]int64, err error) {
|
func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productIds []int64, mapProductMinPrice map[int64]int64) error {
|
||||||
//获取产品模型价格列表
|
//获取产品模型价格列表
|
||||||
modelList, err := d.GetAllByProductIdsTags(ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price")
|
modelList, err := d.GetAllByProductIdsTags(ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return errors.New("failed to get model list")
|
||||||
}
|
}
|
||||||
mapModelMinPrice := make(map[int64]int64)
|
mapModelMinPrice := make(map[int64]int64)
|
||||||
//每个模型/配件存储最小价格
|
//每个模型/配件存储最小价格
|
||||||
@ -185,23 +186,25 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI
|
|||||||
switch *modelInfo.Tag {
|
switch *modelInfo.Tag {
|
||||||
case constants.TAG_MODEL: //模型
|
case constants.TAG_MODEL: //模型
|
||||||
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
|
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
|
||||||
return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id))
|
return errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id))
|
||||||
}
|
}
|
||||||
var stepPrice StepPriceJsonStruct
|
var stepPrice StepPriceJsonStruct
|
||||||
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
|
return errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
|
||||||
}
|
}
|
||||||
lenRange := len(stepPrice.PriceRange)
|
lenRange := len(stepPrice.PriceRange)
|
||||||
if lenRange == 0 {
|
if lenRange == 0 {
|
||||||
return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id))
|
return errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id))
|
||||||
}
|
}
|
||||||
|
sort.SliceStable(stepPrice.PriceRange, func(i, j int) bool {
|
||||||
|
return stepPrice.PriceRange[i].Price > stepPrice.PriceRange[j].Price
|
||||||
|
})
|
||||||
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
|
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
|
||||||
case constants.TAG_PARTS: //配件
|
case constants.TAG_PARTS: //配件
|
||||||
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
|
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
productMinPrice = make(map[int64]int64)
|
|
||||||
//给产品存储最小价格
|
//给产品存储最小价格
|
||||||
for _, v := range modelList {
|
for _, v := range modelList {
|
||||||
if *v.Tag != constants.TAG_MODEL {
|
if *v.Tag != constants.TAG_MODEL {
|
||||||
@ -213,13 +216,13 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI
|
|||||||
itemPrice += fittingPrice
|
itemPrice += fittingPrice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if minPrice, ok := productMinPrice[*v.ProductId]; ok {
|
if minPrice, ok := mapProductMinPrice[*v.ProductId]; ok {
|
||||||
if itemPrice < minPrice {
|
if itemPrice < minPrice {
|
||||||
productMinPrice[*v.ProductId] = itemPrice
|
mapProductMinPrice[*v.ProductId] = itemPrice
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
productMinPrice[*v.ProductId] = itemPrice
|
mapProductMinPrice[*v.ProductId] = itemPrice
|
||||||
}
|
}
|
||||||
return productMinPrice, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -108,14 +108,17 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
|
|||||||
for rIndex, rangeInfo := range stepPrice.PriceRange {
|
for rIndex, rangeInfo := range stepPrice.PriceRange {
|
||||||
//最后一个
|
//最后一个
|
||||||
if rIndex+1 == rangeLen {
|
if rIndex+1 == rangeLen {
|
||||||
|
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
|
||||||
stepRange = append(stepRange, map[string]interface{}{
|
stepRange = append(stepRange, map[string]interface{}{
|
||||||
"range_description": fmt.Sprintf(">=%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity)),
|
"range_description": fmt.Sprintf(">=%s Units", begin),
|
||||||
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
|
||||||
|
end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity))
|
||||||
stepRange = append(stepRange, map[string]interface{}{
|
stepRange = append(stepRange, map[string]interface{}{
|
||||||
"range_description": fmt.Sprintf("%s-%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity), format.NumToStringWithThousandthPercentile(rangeInfo.EndQuantity)),
|
"range_description": fmt.Sprintf("%s-%s Units", begin, end),
|
||||||
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,9 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
|||||||
recommendProductList = append(recommendProductList, v)
|
recommendProductList = append(recommendProductList, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds)
|
//获取产品最低价
|
||||||
if err != nil {
|
mapProductMinPrice := make(map[int64]int64)
|
||||||
|
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
|
||||||
}
|
}
|
||||||
//获取产品标签相关属性
|
//获取产品标签相关属性
|
||||||
|
@ -3,8 +3,6 @@ package logic
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"fusenapi/constants"
|
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
@ -230,51 +228,8 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
//获取产品最低价格
|
//获取产品最低价格
|
||||||
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price")
|
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, req.MapProductMinPrice); err != nil {
|
||||||
if err != nil {
|
return nil, errors.New("failed to get product min price")
|
||||||
logx.Error(err)
|
|
||||||
return nil, errors.New("failed to get model list")
|
|
||||||
}
|
|
||||||
mapModelMinPrice := make(map[int64]int64)
|
|
||||||
//每个模型/配件存储最小价格
|
|
||||||
for _, modelInfo := range modelList {
|
|
||||||
switch *modelInfo.Tag {
|
|
||||||
case constants.TAG_MODEL: //模型
|
|
||||||
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
|
|
||||||
return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id))
|
|
||||||
}
|
|
||||||
var stepPrice gmodel.StepPriceJsonStruct
|
|
||||||
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
|
|
||||||
}
|
|
||||||
lenRange := len(stepPrice.PriceRange)
|
|
||||||
if lenRange == 0 {
|
|
||||||
return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id))
|
|
||||||
}
|
|
||||||
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
|
|
||||||
case constants.TAG_PARTS: //配件
|
|
||||||
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//给产品存储最小价格
|
|
||||||
for _, v := range modelList {
|
|
||||||
if *v.Tag != constants.TAG_MODEL {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
itemPrice := mapModelMinPrice[v.Id]
|
|
||||||
if *v.PartId > 0 {
|
|
||||||
if fittingPrice, ok := mapModelMinPrice[*v.PartId]; ok {
|
|
||||||
itemPrice += fittingPrice
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if minPrice, ok := req.MapProductMinPrice[*v.ProductId]; ok {
|
|
||||||
if itemPrice < minPrice {
|
|
||||||
req.MapProductMinPrice[*v.ProductId] = itemPrice
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
req.MapProductMinPrice[*v.ProductId] = itemPrice
|
|
||||||
}
|
}
|
||||||
//获取模板
|
//获取模板
|
||||||
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")
|
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")
|
||||||
@ -290,7 +245,6 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
|||||||
req.MapProductTemplate[*v.ProductId] = v.Id
|
req.MapProductTemplate[*v.ProductId] = v.Id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取产品尺寸数量
|
//获取产品尺寸数量
|
||||||
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -112,8 +112,8 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||||||
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
||||||
}
|
}
|
||||||
//获取产品最低价格
|
//获取产品最低价格
|
||||||
mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds)
|
mapProductMinPrice := make(map[int64]int64)
|
||||||
if err != nil {
|
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price")
|
||||||
}
|
}
|
||||||
//获取模板(只是获取产品product_id)
|
//获取模板(只是获取产品product_id)
|
||||||
|
@ -1,18 +1,31 @@
|
|||||||
package format
|
package format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 数字变成带千分位的字符串
|
// 数字变成带千分位的字符串
|
||||||
func NumToStringWithThousandthPercentile(number int64) string {
|
func NumToStringWithThousandthPercentile(numberStr string) string {
|
||||||
s := fmt.Sprintf("%d", number)
|
if _, err := strconv.ParseFloat(numberStr, 64); err != nil {
|
||||||
|
log.Fatalln("is not a number")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
sliceList := strings.Split(numberStr, ".")
|
||||||
|
s := sliceList[0]
|
||||||
|
f := ""
|
||||||
|
if len(sliceList) == 2 {
|
||||||
|
f = "." + sliceList[1]
|
||||||
|
}
|
||||||
l := len(s)
|
l := len(s)
|
||||||
if l <= 3 {
|
if l <= 3 {
|
||||||
return s
|
return s + f
|
||||||
}
|
}
|
||||||
r := l % 3 //前面第几位开始加入千分位
|
r := l % 3 //前面第几位开始加入千分位
|
||||||
|
if r == 0 {
|
||||||
|
r = 3
|
||||||
|
}
|
||||||
b := strings.Builder{}
|
b := strings.Builder{}
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
b.WriteString(string(s[i]))
|
b.WriteString(string(s[i]))
|
||||||
@ -21,5 +34,6 @@ func NumToStringWithThousandthPercentile(number int64) string {
|
|||||||
r += 3
|
r += 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b.WriteString(f)
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user