fix
This commit is contained in:
parent
fe270ed8e3
commit
4fbbbb27df
|
@ -104,7 +104,17 @@ func (m *FsResourceModel) Trans(ctx context.Context, fn func(ctx context.Context
|
|||
|
||||
// return err
|
||||
}
|
||||
|
||||
func (m *FsResourceModel) FindAllByResourceIds(ctx context.Context, resourceIds []string, fields ...string) (resp []FsResource, err error) {
|
||||
if len(resourceIds) == 0 {
|
||||
return
|
||||
}
|
||||
db := m.db.WithContext(ctx).Model(&FsResource{}).Where("resource_id in (?)", resourceIds)
|
||||
if len(fields) != 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (m *FsResourceModel) TableName() string {
|
||||
return m.name
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
|
@ -80,6 +81,8 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse recommend product")
|
||||
}
|
||||
//资源id集合
|
||||
resourceIds := make([]string, 0, 100)
|
||||
//获取列表推荐产品
|
||||
recommendProductList, err = l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, recommendProductIds, "sort-desc")
|
||||
if err != nil {
|
||||
|
@ -92,6 +95,16 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||
productIds := make([]int64, 0, len(recommendProductList))
|
||||
for _, product := range recommendProductList {
|
||||
productIds = append(productIds, product.Id)
|
||||
coverSlice := strings.Split(*product.Cover, "/")
|
||||
coverImgSlice := strings.Split(*product.CoverImg, "/")
|
||||
lenCoverSlice := len(coverSlice)
|
||||
lenCoverImgSlice := len(coverImgSlice)
|
||||
if lenCoverSlice > 1 {
|
||||
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
|
||||
}
|
||||
if lenCoverImgSlice > 1 {
|
||||
resourceIds = append(resourceIds, coverImgSlice[lenCoverImgSlice-1])
|
||||
}
|
||||
}
|
||||
//获取商品可选配件
|
||||
productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds)
|
||||
|
@ -158,11 +171,33 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property")
|
||||
}
|
||||
for _, v := range productTagPropList {
|
||||
coverSlice := strings.Split(*v.Cover, "/")
|
||||
lenCoverSlice := len(coverSlice)
|
||||
if lenCoverSlice > 1 {
|
||||
resourceIds = append(resourceIds, coverSlice[lenCoverSlice-1])
|
||||
}
|
||||
}
|
||||
//根据resourceUrls找到对应的元数据
|
||||
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get resource list")
|
||||
}
|
||||
mapResourceMetadata := make(map[string]map[string]interface{})
|
||||
for _, v := range resourceMetadataList {
|
||||
var metadata map[string]interface{}
|
||||
if v.Metadata != nil {
|
||||
_ = json.Unmarshal([]byte(*v.Metadata), &metadata)
|
||||
}
|
||||
mapResourceMetadata[*v.ResourceUrl] = metadata
|
||||
}
|
||||
mapTagProp := make(map[int64][]types.CoverDefaultItem)
|
||||
for _, v := range productTagPropList {
|
||||
mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{
|
||||
Tag: v.TemplateTag,
|
||||
Cover: *v.Cover,
|
||||
Tag: v.TemplateTag,
|
||||
Cover: *v.Cover,
|
||||
CoverMetadata: mapResourceMetadata[*v.Cover],
|
||||
})
|
||||
}
|
||||
//组装返回
|
||||
|
@ -188,6 +223,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||
Sn: *productInfo.Sn,
|
||||
Title: *productInfo.Title,
|
||||
Cover: *productInfo.Cover,
|
||||
CoverMetadata: mapResourceMetadata[*productInfo.Cover],
|
||||
CoverDefault: []types.CoverDefaultItem{},
|
||||
SizeNum: uint32(sizeNum),
|
||||
MinPrice: minPrice,
|
||||
|
|
|
@ -282,8 +282,9 @@ type TagProduct struct {
|
|||
}
|
||||
|
||||
type CoverDefaultItem struct {
|
||||
Tag string `json:"tag"`
|
||||
Cover string `json:"cover"`
|
||||
Tag string `json:"tag"`
|
||||
Cover string `json:"cover"`
|
||||
CoverMetadata interface{} `json:"cover_metadata"`
|
||||
}
|
||||
|
||||
type GetRenderDesignReq struct {
|
||||
|
@ -401,6 +402,7 @@ type HomePageRecommendProductListRsp struct {
|
|||
Sn string `json:"sn"`
|
||||
Title string `json:"title"`
|
||||
Cover string `json:"cover"`
|
||||
CoverMetadata interface{} `json:"cover_metadata"`
|
||||
SizeNum uint32 `json:"size_num"`
|
||||
MinPrice int64 `json:"min_price"`
|
||||
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||
|
|
|
@ -331,8 +331,9 @@ type TagProduct {
|
|||
Recommended bool `json:"recommended"`
|
||||
}
|
||||
type CoverDefaultItem {
|
||||
Tag string `json:"tag"`
|
||||
Cover string `json:"cover"`
|
||||
Tag string `json:"tag"`
|
||||
Cover string `json:"cover"`
|
||||
CoverMetadata interface{} `json:"cover_metadata"`
|
||||
}
|
||||
//获取云渲染设计方案信息
|
||||
type GetRenderDesignReq {
|
||||
|
@ -443,6 +444,7 @@ type HomePageRecommendProductListRsp {
|
|||
Sn string `json:"sn"`
|
||||
Title string `json:"title"`
|
||||
Cover string `json:"cover"`
|
||||
CoverMetadata interface{} `json:"cover_metadata"`
|
||||
SizeNum uint32 `json:"size_num"`
|
||||
MinPrice int64 `json:"min_price"`
|
||||
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user