This commit is contained in:
laodaming 2023-07-20 11:08:35 +08:00
parent 3e1d4d2e4f
commit b8333ecaf8
5 changed files with 128 additions and 84 deletions

View File

@ -75,3 +75,18 @@ func (d *FsProductModel3dModel) GetAll(ctx context.Context) (resp []FsProductMod
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Find(&resp).Error err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Find(&resp).Error
return resp, err return resp, err
} }
type GetGroupPartListByProductIdsRsp struct {
PartList string `json:"part_list"`
ProductId int64 `json:"product_id"`
}
func (d *FsProductModel3dModel) GetGroupPartListByProductIds(ctx context.Context, productIds []int64) (resp []GetGroupPartListByProductIdsRsp, err error) {
if len(productIds) == 0 {
return
}
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).
Select("product_id,group_concat(part_list) as part_list").
Group("product_id").Find(&resp).Error
return resp, err
}

View File

@ -45,7 +45,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
} }
return resp.SetStatusWithMessage(basic.CodeOK, "success", demo) return resp.SetStatusWithMessage(basic.CodeOK, "success", demo)
} }
if req.Page <= 0{ if req.Page <= 0 {
req.Page = constants.DEFAULT_PAGE req.Page = constants.DEFAULT_PAGE
} }
//获取合适尺寸 //获取合适尺寸

View File

@ -60,7 +60,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "param cid is invalid:record not found") return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "param cid is invalid:record not found")
} }
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get tag info") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info")
} }
tReq.LevelPrefixLeftLike = *tagData.LevelPrefix tReq.LevelPrefixLeftLike = *tagData.LevelPrefix
} }
@ -77,13 +77,15 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
typeIds = append(typeIds, v.Id) typeIds = append(typeIds, v.Id)
} }
var ( var (
productList []gmodel.FsProduct //产品列表select 字段需要看查询的地方) productList []gmodel.FsProduct //产品列表select 字段需要看查询的地方)
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表select 字段需要看查询的地方) productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
mapProductMinPrice = make(map[int64]int64) //产品最小价格map mapProductHaveOptionFitting = make(map[int64]struct{})
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表select 字段需要看查询的地方) productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表select 字段需要看查询的地方)
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表select 字段需要看查询的地方) mapProductMinPrice = make(map[int64]int64) //产品最小价格map
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表select 字段需要看查询的地方)
mapProductTemplate = make(map[int64]struct{}) //产品模板map productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表select 字段需要看查询的地方)
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
mapProductTemplate = make(map[int64]struct{}) //产品模板map
) )
//携带产品 //携带产品
if req.WithProduct { if req.WithProduct {
@ -104,9 +106,23 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list") return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
} }
productIds := make([]int64,0,len(productList)) productIds := make([]int64, 0, len(productList))
for _,product := range productList{ for _, product := range productList {
productIds = append(productIds,product.Id) productIds = append(productIds, product.Id)
}
//获取商品可选配件
productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product part list")
}
for _, partList := range productOptionalPartList {
partList.PartList = strings.Trim(partList.PartList, " ")
partList.PartList = strings.Trim(partList.PartList, ",")
if partList.PartList == "" {
continue
}
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
} }
//获取产品价格列表 //获取产品价格列表
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
@ -151,22 +167,23 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
mapTagLevel := make(map[string]*types.TagItem) mapTagLevel := make(map[string]*types.TagItem)
//处理tags数据 //处理tags数据
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{ if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
TagList: tagList, TagList: tagList,
WithProduct: req.WithProduct, WithProduct: req.WithProduct,
ProductList: productList, ProductList: productList,
MapProductMinPrice: mapProductMinPrice, MapProductMinPrice: mapProductMinPrice,
MapProductTemplate: mapProductTemplate, MapProductTemplate: mapProductTemplate,
MapProductSizeCount: mapProductSizeCount, MapProductSizeCount: mapProductSizeCount,
MapTagLevel: mapTagLevel, MapTagLevel: mapTagLevel,
Size: req.Size, MapProductHaveOptionFitting: mapProductHaveOptionFitting,
user: user, Size: req.Size,
user: user,
}); err != nil { }); err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
} }
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
TotalCategoryProduct: len(productList), TotalCategoryProduct: len(productList),
TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系 TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系
}) })
} }
@ -178,41 +195,43 @@ type sortRecommendProduct struct {
// 处理tag菜单数据 // 处理tag菜单数据
type dealWithTagMenuDataReq struct { type dealWithTagMenuDataReq struct {
TagList []gmodel.FsTags TagList []gmodel.FsTags
WithProduct bool WithProduct bool
ProductList []gmodel.FsProduct ProductList []gmodel.FsProduct
MapProductMinPrice map[int64]int64 MapProductMinPrice map[int64]int64
MapProductTemplate map[int64]struct{} MapProductTemplate map[int64]struct{}
MapProductSizeCount map[int64]int64 MapProductSizeCount map[int64]int64
MapTagLevel map[string]*types.TagItem MapTagLevel map[string]*types.TagItem
Size uint32 MapProductHaveOptionFitting map[int64]struct{}
user gmodel.FsUser Size uint32
user gmodel.FsUser
} }
func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error { func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error {
for _, tagInfo := range req.TagList { for _, tagInfo := range req.TagList {
tagTem := types.TagItem{ tagTem := types.TagItem{
TagProductList: nil, TagProductList: nil,
TypeName: *tagInfo.Title, TypeName: *tagInfo.Title,
TypeId: tagInfo.Id, TypeId: tagInfo.Id,
Level: *tagInfo.Level, Level: *tagInfo.Level,
LevelPrefix: *tagInfo.LevelPrefix, LevelPrefix: *tagInfo.LevelPrefix,
Icon: *tagInfo.Icon, Icon: *tagInfo.Icon,
Sort: *tagInfo.Sort, Sort: *tagInfo.Sort,
Description: *tagInfo.Description, Description: *tagInfo.Description,
ChildTagList: make([]*types.TagItem, 0, 50), ChildTagList: make([]*types.TagItem, 0, 50),
} }
//携带产品 //携带产品
if req.WithProduct { if req.WithProduct {
//获取分类产品列表 //获取分类产品列表
productListRsp := l.getTagProducts(getTagProductsReq{ productListRsp := l.getTagProducts(getTagProductsReq{
TagId: tagInfo.Id, TagId: tagInfo.Id,
ProductList: req.ProductList, ProductList: req.ProductList,
MapProductMinPrice: req.MapProductMinPrice, MapProductMinPrice: req.MapProductMinPrice,
MapProductTemplate: req.MapProductTemplate, MapProductTemplate: req.MapProductTemplate,
MapProductSizeCount: req.MapProductSizeCount, MapProductSizeCount: req.MapProductSizeCount,
Size: req.Size, MapProductHaveOptionFitting: req.MapProductHaveOptionFitting,
User: req.user, Size: req.Size,
User: req.user,
}) })
//赋值 //赋值
tagTem.TagProductList = productListRsp tagTem.TagProductList = productListRsp
@ -257,15 +276,17 @@ func (l *GetTagProductListLogic) organizationLevelRelation(mapTagLevel map[strin
}) })
return rspList return rspList
} }
// 获取对应tag的产品列表 // 获取对应tag的产品列表
type getTagProductsReq struct { type getTagProductsReq struct {
TagId int64 TagId int64
ProductList []gmodel.FsProduct ProductList []gmodel.FsProduct
MapProductMinPrice map[int64]int64 MapProductMinPrice map[int64]int64
MapProductTemplate map[int64]struct{} MapProductTemplate map[int64]struct{}
MapProductSizeCount map[int64]int64 MapProductSizeCount map[int64]int64
Size uint32 MapProductHaveOptionFitting map[int64]struct{}
User gmodel.FsUser Size uint32
User gmodel.FsUser
} }
func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productListRsp []types.TagProduct) { func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productListRsp []types.TagProduct) {
@ -286,15 +307,21 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
if mapSizeNum, ok := req.MapProductSizeCount[productInfo.Id]; ok { if mapSizeNum, ok := req.MapProductSizeCount[productInfo.Id]; ok {
sizeNum = mapSizeNum sizeNum = mapSizeNum
} }
//有无可选配件
haveOptionalFitting := false
if _, ok = req.MapProductHaveOptionFitting[productInfo.Id]; ok {
haveOptionalFitting = true
}
item := types.TagProduct{ item := types.TagProduct{
ProductId: productInfo.Id, ProductId: productInfo.Id,
Sn: *productInfo.Sn, Sn: *productInfo.Sn,
Title: *productInfo.Title, Title: *productInfo.Title,
Intro: *productInfo.Intro, Intro: *productInfo.Intro,
IsEnv: *productInfo.IsProtection, IsEnv: *productInfo.IsProtection,
IsMicro: *productInfo.IsMicrowave, IsMicro: *productInfo.IsMicrowave,
SizeNum: uint32(sizeNum), SizeNum: uint32(sizeNum),
MiniPrice: minPrice, MiniPrice: minPrice,
HaveOptionalFitting: haveOptionalFitting,
} }
//千人千面处理 //千人千面处理
r := image.ThousandFaceImageFormatReq{ r := image.ThousandFaceImageFormatReq{

View File

@ -268,17 +268,18 @@ type TagItem struct {
} }
type TagProduct struct { type TagProduct struct {
ProductId int64 `json:"product_id"` ProductId int64 `json:"product_id"`
Sn string `json:"sn"` Sn string `json:"sn"`
Title string `json:"title"` Title string `json:"title"`
Cover string `json:"cover"` Cover string `json:"cover"`
Intro string `json:"intro"` Intro string `json:"intro"`
CoverImg string `json:"cover_img"` CoverImg string `json:"cover_img"`
IsEnv int64 `json:"is_env"` IsEnv int64 `json:"is_env"`
IsMicro int64 `json:"is_micro"` IsMicro int64 `json:"is_micro"`
SizeNum uint32 `json:"size_num"` SizeNum uint32 `json:"size_num"`
MiniPrice int64 `json:"mini_price"` MiniPrice int64 `json:"mini_price"`
CoverDefault string `json:"cover_default"` CoverDefault string `json:"cover_default"`
HaveOptionalFitting bool `json:"have_optional_fitting"`
} }
type GetRenderDesignReq struct { type GetRenderDesignReq struct {

View File

@ -311,17 +311,18 @@ type TagItem {
ChildTagList []*TagItem `json:"child_tag_list"` ChildTagList []*TagItem `json:"child_tag_list"`
} }
type TagProduct { type TagProduct {
ProductId int64 `json:"product_id"` ProductId int64 `json:"product_id"`
Sn string `json:"sn"` Sn string `json:"sn"`
Title string `json:"title"` Title string `json:"title"`
Cover string `json:"cover"` Cover string `json:"cover"`
Intro string `json:"intro"` Intro string `json:"intro"`
CoverImg string `json:"cover_img"` CoverImg string `json:"cover_img"`
IsEnv int64 `json:"is_env"` IsEnv int64 `json:"is_env"`
IsMicro int64 `json:"is_micro"` IsMicro int64 `json:"is_micro"`
SizeNum uint32 `json:"size_num"` SizeNum uint32 `json:"size_num"`
MiniPrice int64 `json:"mini_price"` MiniPrice int64 `json:"mini_price"`
CoverDefault string `json:"cover_default"` CoverDefault string `json:"cover_default"`
HaveOptionalFitting bool `json:"have_optional_fitting"`
} }
//获取云渲染设计方案信息 //获取云渲染设计方案信息
type GetRenderDesignReq { type GetRenderDesignReq {