finish product list api
This commit is contained in:
parent
92b29d8006
commit
94212b1003
|
@ -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)
|
||||
|
|
21
utils/format/str_to_int_slice.go
Normal file
21
utils/format/str_to_int_slice.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user