finish product list api

This commit is contained in:
laodaming 2023-06-05 10:18:31 +08:00
parent 92b29d8006
commit 94212b1003
2 changed files with 29 additions and 6 deletions

View File

@ -14,7 +14,6 @@ import (
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"sort"
"strconv"
"strings"
"time"
@ -94,14 +93,17 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
//存储产品最小价格
mapProductMinPrice := make(map[int64]int64)
for _, v := range productPriceList {
priceSlic := strings.Split(v.Price, ",")
sort.Strings(priceSlic)
min, err := strconv.ParseInt(priceSlic[0], 10, 64)
priceStrSlic := strings.Split(v.Price, ",")
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "parse min product price err"}, nil
return &types.Response{Code: 510, Message: err.Error()}, nil
}
mapProductMinPrice[v.ProductId] = min
if len(priceSlice) == 0 {
continue
}
sort.Ints(priceSlice)
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
//获取模板
productTemplateModel := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)

View File

@ -0,0 +1,21 @@
package format
import (
"strconv"
)
// 字符串切片转int切片
func StrSlicToIntSlice(input []string) ([]int, error) {
priceSlic := make([]int, 0, len(input))
for _, p := range input {
if p == "" {
continue
}
price, err := strconv.Atoi(p)
if err != nil {
return nil, err
}
priceSlic = append(priceSlic, price)
}
return priceSlic, nil
}