fix
This commit is contained in:
parent
262c8dc1b5
commit
d2bb801fb4
|
@ -12,7 +12,7 @@ func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort
|
|||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
db := s.db.Model(&FsProductSize{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
||||
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
||||
switch sort {
|
||||
case "sort-asc":
|
||||
db = db.Order("`sort` ASC")
|
||||
|
@ -112,3 +112,12 @@ func (s *FsProductSizeModel) FindOneByIdProductId(ctx context.Context, id int64,
|
|||
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? and product_id = ?", id, productId).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (s *FsProductSizeModel) GetAllByModelIdsJoinModeld(ctx context.Context, modelIds []int64) (resp []FsProductSize, err error) {
|
||||
if len(modelIds) == 0 {
|
||||
return
|
||||
}
|
||||
err = s.db.WithContext(ctx).Table(s.name + " as s").
|
||||
Joins("left join fs_product_model3d as m on s.id = m.size_id").
|
||||
Select("s.*").Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
|
@ -86,9 +87,11 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||
mapTagProp = make(map[int64][]types.CoverDefaultItem)
|
||||
mapProductHaveOptionFitting = make(map[int64]struct{})
|
||||
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
|
||||
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
||||
mapProductTemplate = make(map[int64]int64) //产品模板map
|
||||
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
|
||||
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
||||
mapProductTemplate = make(map[int64]int64) //产品模板map
|
||||
mapResourceMetadata = make(map[string]map[string]interface{}) //资源元数据
|
||||
mapProductDefaultSize = make(map[int64]int64)
|
||||
)
|
||||
//携带产品
|
||||
if req.WithProduct {
|
||||
|
@ -101,6 +104,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
MapProductMinPrice: mapProductMinPrice,
|
||||
MapProductSizeCount: mapProductSizeCount,
|
||||
MapProductTemplate: mapProductTemplate,
|
||||
MapProductDefaultSize: mapProductDefaultSize,
|
||||
MapResourceMetadata: mapResourceMetadata,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
|
@ -121,6 +126,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
MapProductSizeCount: mapProductSizeCount,
|
||||
MapTagLevel: mapTagLevel,
|
||||
MapProductHaveOptionFitting: mapProductHaveOptionFitting,
|
||||
MapResourceMetadata: mapResourceMetadata,
|
||||
MapProductDefaultSize: mapProductDefaultSize,
|
||||
Size: req.Size,
|
||||
User: user,
|
||||
MinLevel: &minLevel,
|
||||
|
@ -146,6 +153,8 @@ type getProductRelationInfoReq struct {
|
|||
MapProductMinPrice map[int64]int64
|
||||
MapProductSizeCount map[int64]int64
|
||||
MapProductTemplate map[int64]int64
|
||||
MapResourceMetadata map[string]map[string]interface{}
|
||||
MapProductDefaultSize map[int64]int64
|
||||
}
|
||||
|
||||
func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationInfoReq) (productList []gmodel.FsProduct, err error) {
|
||||
|
@ -153,6 +162,7 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
|||
productTemplatesV2List []gmodel.FsProductTemplateV2
|
||||
productSizeCountList []gmodel.CountProductSizeByStatusRsp
|
||||
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp
|
||||
resourceIds = make([]string, 0, 200) //涉及资源的id集合
|
||||
)
|
||||
//查询符合的产品列表
|
||||
pIsDel := int64(0)
|
||||
|
@ -174,6 +184,16 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
|||
productIds := make([]int64, 0, len(productList))
|
||||
for _, product := range productList {
|
||||
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)
|
||||
|
@ -196,10 +216,31 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
|||
logx.Error(err)
|
||||
return nil, errors.New("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 nil, errors.New("failed to get resource list")
|
||||
}
|
||||
for _, v := range resourceMetadataList {
|
||||
var metadata map[string]interface{}
|
||||
if v.Metadata != nil {
|
||||
_ = json.Unmarshal([]byte(*v.Metadata), &metadata)
|
||||
}
|
||||
req.MapResourceMetadata[*v.ResourceUrl] = metadata
|
||||
}
|
||||
for _, v := range productTagPropList {
|
||||
req.MapTagProp[*v.ProductId] = append(req.MapTagProp[*v.ProductId], types.CoverDefaultItem{
|
||||
Tag: v.TemplateTag,
|
||||
Cover: *v.Cover,
|
||||
Tag: v.TemplateTag,
|
||||
Cover: *v.Cover,
|
||||
CoverMetadata: req.MapResourceMetadata[*v.Cover],
|
||||
})
|
||||
}
|
||||
//获取产品价格列表
|
||||
|
@ -229,22 +270,40 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
|||
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||
}
|
||||
}
|
||||
//获取模板(只是获取产品product_id,id)
|
||||
if req.TemplateTag != "" { //指定模板tag
|
||||
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "sort ASC", "product_id,id")
|
||||
} else { //没指定模板tag
|
||||
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id")
|
||||
}
|
||||
//获取模板
|
||||
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, errors.New("failed to get product templates")
|
||||
}
|
||||
//只存第一个
|
||||
mapModelId := make(map[int64]struct{})
|
||||
for _, v := range productTemplatesV2List {
|
||||
if _, ok := req.MapProductTemplate[*v.ProductId]; ok {
|
||||
//标签符合不为空且遍历等于传入的模板标签
|
||||
if *v.TemplateTag == req.TemplateTag {
|
||||
req.MapProductTemplate[*v.ProductId] = v.Id
|
||||
mapModelId[*v.ModelId] = struct{}{}
|
||||
continue
|
||||
}
|
||||
req.MapProductTemplate[*v.ProductId] = v.Id
|
||||
//如果已经有了则不用管
|
||||
if _, ok := req.MapProductTemplate[*v.ProductId]; ok {
|
||||
continue
|
||||
} else { //否则设置一个值
|
||||
req.MapProductTemplate[*v.ProductId] = v.Id
|
||||
mapModelId[*v.ModelId] = struct{}{}
|
||||
}
|
||||
}
|
||||
modelIds := make([]int64, 0, len(mapModelId))
|
||||
for modelId, _ := range mapModelId {
|
||||
modelIds = append(modelIds, modelId)
|
||||
}
|
||||
//根据modelIds查询尺寸
|
||||
defaultSizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByModelIdsJoinModeld(l.ctx, modelIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, errors.New("get product default model3d list err")
|
||||
}
|
||||
for _, v := range defaultSizeList {
|
||||
req.MapProductDefaultSize[*v.ProductId] = v.Id
|
||||
}
|
||||
//获取产品尺寸数量
|
||||
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
||||
|
@ -270,6 +329,8 @@ type dealWithTagMenuDataReq struct {
|
|||
MapProductSizeCount map[int64]int64
|
||||
MapTagLevel map[string]*types.TagItem
|
||||
MapProductHaveOptionFitting map[int64]struct{}
|
||||
MapResourceMetadata map[string]map[string]interface{}
|
||||
MapProductDefaultSize map[int64]int64
|
||||
Size uint32
|
||||
User gmodel.FsUser
|
||||
MinLevel *int //层级最小的
|
||||
|
@ -302,6 +363,8 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
|||
MapProductTemplate: req.MapProductTemplate,
|
||||
MapProductSizeCount: req.MapProductSizeCount,
|
||||
MapProductHaveOptionFitting: req.MapProductHaveOptionFitting,
|
||||
MapResourceMetadata: req.MapResourceMetadata,
|
||||
MapProductDefaultSize: req.MapProductDefaultSize,
|
||||
Size: req.Size,
|
||||
User: req.User,
|
||||
})
|
||||
|
@ -378,6 +441,8 @@ type getTagProductsReq struct {
|
|||
MapProductTemplate map[int64]int64
|
||||
MapProductSizeCount map[int64]int64
|
||||
MapProductHaveOptionFitting map[int64]struct{}
|
||||
MapResourceMetadata map[string]map[string]interface{}
|
||||
MapProductDefaultSize map[int64]int64
|
||||
Size uint32
|
||||
User gmodel.FsUser
|
||||
}
|
||||
|
@ -406,6 +471,11 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
|||
if _, ok = req.MapProductHaveOptionFitting[productInfo.Id]; ok {
|
||||
haveOptionalFitting = true
|
||||
}
|
||||
//默认尺寸id
|
||||
defaultSizeId := int64(0)
|
||||
if sizeId, ok := req.MapProductDefaultSize[productInfo.Id]; ok {
|
||||
defaultSizeId = sizeId
|
||||
}
|
||||
item := types.TagProduct{
|
||||
ProductId: productInfo.Id,
|
||||
Sn: *productInfo.Sn,
|
||||
|
@ -413,10 +483,12 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
|||
SizeNum: uint32(sizeNum),
|
||||
CoverDefault: []types.CoverDefaultItem{},
|
||||
DefaultTemplateId: templateId,
|
||||
DefaultSizeId: defaultSizeId,
|
||||
MinPrice: minPrice,
|
||||
HaveOptionalFitting: haveOptionalFitting,
|
||||
Recommended: *productInfo.IsRecommend > 0,
|
||||
Cover: *productInfo.Cover,
|
||||
CoverMetadata: req.MapResourceMetadata[*productInfo.Cover],
|
||||
}
|
||||
if _, ok = req.MapTagProp[productInfo.Id]; ok {
|
||||
item.CoverDefault = req.MapTagProp[productInfo.Id]
|
||||
|
|
|
@ -273,10 +273,12 @@ type TagProduct 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"`
|
||||
DefaultTemplateId int64 `json:"default_template_id"`
|
||||
DefaultSizeId int64 `json:"default_size_id"`
|
||||
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
||||
Recommended bool `json:"recommended"`
|
||||
}
|
||||
|
|
|
@ -318,15 +318,17 @@ type TagItem {
|
|||
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||
}
|
||||
type TagProduct {
|
||||
ProductId int64 `json:"product_id"`
|
||||
Sn string `json:"sn"`
|
||||
Title string `json:"title"`
|
||||
Cover string `json:"cover"`
|
||||
SizeNum uint32 `json:"size_num"`
|
||||
MinPrice int64 `json:"min_price"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
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"`
|
||||
DefaultTemplateId int64 `json:"default_template_id"`
|
||||
DefaultSizeId int64 `json:"default_size_id"`
|
||||
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
||||
Recommended bool `json:"recommended"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user