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

View File

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

View File

@ -311,17 +311,18 @@ 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"`
Intro string `json:"intro"`
CoverImg string `json:"cover_img"`
IsEnv int64 `json:"is_env"`
IsMicro int64 `json:"is_micro"`
SizeNum uint32 `json:"size_num"`
MiniPrice int64 `json:"mini_price"`
CoverDefault string `json:"cover_default"`
ProductId int64 `json:"product_id"`
Sn string `json:"sn"`
Title string `json:"title"`
Cover string `json:"cover"`
Intro string `json:"intro"`
CoverImg string `json:"cover_img"`
IsEnv int64 `json:"is_env"`
IsMicro int64 `json:"is_micro"`
SizeNum uint32 `json:"size_num"`
MiniPrice int64 `json:"mini_price"`
CoverDefault string `json:"cover_default"`
HaveOptionalFitting bool `json:"have_optional_fitting"`
}
//获取云渲染设计方案信息
type GetRenderDesignReq {