From 48afd3105f5778c9524f2791c352a8a934be015d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 11 Aug 2023 18:59:03 +0800 Subject: [PATCH 01/11] fix --- model/gmodel/fs_product_model3d_logic.go | 11 +++ model/gmodel/fs_product_template_v2_gen.go | 1 + model/gmodel/fs_product_template_v2_logic.go | 16 ---- .../internal/logic/gettemplatebypidlogic.go | 91 +++++++++++-------- server_api/product.api | 5 - 5 files changed, 65 insertions(+), 59 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 9cb2fe91..741fdac2 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -101,3 +101,14 @@ func (d *FsProductModel3dModel) FindOneJoinSize(ctx context.Context, productId i Order("s.sort ASC").Take(&resp).Error return resp, err } + +func (d *FsProductModel3dModel) GetOneBySizeIdTag(ctx context.Context, sizeId int64, tag int64, fields ...string) (resp *FsProductModel3d, err error) { + db := d.db.WithContext(ctx).Model(&FsProductModel3d{}). + Where("`size_id` = ? and `tag` = ? and `status` = ?", sizeId, tag, 1). + Order("sort DESC") + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_template_v2_gen.go b/model/gmodel/fs_product_template_v2_gen.go index 5e14427f..d72b388a 100644 --- a/model/gmodel/fs_product_template_v2_gen.go +++ b/model/gmodel/fs_product_template_v2_gen.go @@ -22,6 +22,7 @@ type FsProductTemplateV2 struct { Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 Tag *string `gorm:"default:'';" json:"tag"` // 标签(用户自填) IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除 + SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // 开关信息 GroupOptions *string `gorm:"default:'';" json:"group_options"` // 颜色分组 Version *int64 `gorm:"default:0;" json:"version"` // } diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index c29c285d..57109ca8 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -140,22 +140,6 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont return resp, err } -// 获取产品某个物料下的第一个模板 -func (t *FsProductTemplateV2Model) GetSizeLatestTemplate(ctx context.Context, ids []int64, productId int64) (resp *FsProductTemplateV2, err error) { - err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). - Where("id in (?) and product_id = ? and status = ? and is_del = ?", ids, productId, 1, 0). - Order("sort ASC").Take(&resp).Error - return resp, err -} - -// 获取产品第一个物料下的第一个模板 -func (t *FsProductTemplateV2Model) GetProductLatestTemplate(ctx context.Context, ids []int64, productId int64) (resp *FsProductTemplateV2, err error) { - err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). - Where("id in (?) and product_id = ? and status = ? and is_del = ?", ids, productId, 1, 0). - Order("sort ASC").Take(&resp).Error - return resp, err -} - // 获取产品在指定模板标签下的所有模板 func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Context, templateTagId string, productId int64, fields ...string) (resp []FsProductTemplateV2, err error) { db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index 876f6274..51432f3d 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "fmt" - "fusenapi/model/gmodel" + "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/basic" "gorm.io/gorm" @@ -40,7 +40,6 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, if req.ProductTemplateTagId <= 0 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id") } - //获取产品信息(只获取id) productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id") if err != nil { @@ -50,46 +49,62 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") } - //获取该产品该模板标签下的模板列表(只获取id) - templateList, err := l.svcCtx.AllModels.FsProductTemplateV2. - GetListByProductAndTemplateTag(l.ctx, fmt.Sprintf("%d", req.ProductTemplateTagId), productInfo.Id, "id") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get templates") - } - if len(templateList) == 0 { - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "templates are not exists") - } - templateIds := make([]int64, 0, len(templateList)) - for _, v := range templateList { - templateIds = append(templateIds, v.Id) - } - var ( - templateInfo *gmodel.FsProductTemplateV2 - ) - //传了指定物料,则获取该物料的第一个模板 - if req.ProductSizeId > 0 { - templateInfo, err = l.svcCtx.AllModels.FsProductTemplateV2.GetSizeLatestTemplate(l.ctx, templateIds, productInfo.Id) - } else { //没有指定物料则获取第一个物料的第一个模板 - templateInfo, err = l.svcCtx.AllModels.FsProductTemplateV2.GetProductLatestTemplate(l.ctx, templateIds, productInfo.Id) - } - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template info not found") + //没有指定物料 + sizeIds := make([]int64, 0, 10) + if req.ProductSizeId <= 0 { + //获取产品所有物料 + sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "failed to get product size list") } + if len(sizeList) == 0 { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product size list is empty") + } + for _, v := range sizeList { + sizeIds = append(sizeIds, v.Id) + } + } else { //指定物料 + sizeIds = append(sizeIds, req.ProductSizeId) + } + //根据尺寸id获取模型id + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id") + if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template info") + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list") } - if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" { - return resp.SetStatusWithMessage(basic.CodeJsonErr, "template info is not set") + if len(modelList) == 0 { + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "model list is empty") } - var info interface{} - if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil { + modelIds := make([]int64, 0, len(modelList)) + for _, v := range modelList { + modelIds = append(modelIds, v.Id) + } + //查询模型ids下对应tag标签的模板 + templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "") + if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json product template info:", templateInfo.Id) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list") } - return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTemplateByPidRsp{ - TemplateId: templateInfo.Id, - TemplateInfo: info, - }) + rspList := make([]interface{}, 0, len(templateList)) + for _, templateInfo := range templateList { + //没有设置模板据不要 + if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" { + continue + } + //基础模板信息 + var info interface{} + if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json product template info:", templateInfo.Id) + } + //后台隐藏/显示信息 + var switchInfo interface{} + if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" { + _ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo) + } + // todo 继续下周 + rspList = append(rspList, map[string]interface{}{}) + } + return nil } diff --git a/server_api/product.api b/server_api/product.api index 28ca4ae7..e710a978 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -387,11 +387,6 @@ type GetSizeByPidRsp { type GetTemplateByPidReq { Pid string `form:"pid"` ProductTemplateTagId int64 `form:"product_template_tag_id"` - ProductSizeId int64 `form:"product_size_id,optional"` -} -type GetTemplateByPidRsp { - TemplateId int64 `json:"template_id"` //模板id - TemplateInfo interface{} `json:"template_info"` //模板信息 } //获取产品配件数据 type GetFittingByPidReq { From 538d9ff4cf35c91f53f387bee0a6297d545103ef Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 10:51:39 +0800 Subject: [PATCH 02/11] fix --- .../internal/logic/gettemplatebypidlogic.go | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index 51432f3d..e036fa15 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -67,8 +67,8 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, } else { //指定物料 sizeIds = append(sizeIds, req.ProductSizeId) } - //根据尺寸id获取模型id - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id") + //根据尺寸id获取模型 + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list") @@ -77,8 +77,10 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "model list is empty") } modelIds := make([]int64, 0, len(modelList)) - for _, v := range modelList { + mapModel := make(map[int64]int) + for k, v := range modelList { modelIds = append(modelIds, v.Id) + mapModel[v.Id] = k } //查询模型ids下对应tag标签的模板 templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "") @@ -86,25 +88,38 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list") } - rspList := make([]interface{}, 0, len(templateList)) + rsp := make(map[string][]interface{}) for _, templateInfo := range templateList { //没有设置模板据不要 if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" { continue } + modelIndex, ok := mapModel[*templateInfo.ModelId] + if !ok { + continue + } //基础模板信息 - var info interface{} + var info map[string]map[string]interface{} if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json product template info:", templateInfo.Id) + return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id)) } //后台隐藏/显示信息 var switchInfo interface{} if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" { _ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo) } - // todo 继续下周 - rspList = append(rspList, map[string]interface{}{}) + modelInfo := modelList[modelIndex] + var material interface{} + if info["module_data"] != nil && info["module_data"]["material"] != nil { + material = info["module_data"]["material"] + } + mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId) + rsp[mapKey] = append(rsp[mapKey], map[string]interface{}{ + "id": templateInfo.Id, + "material": material, + "material_data": switchInfo, + }) } - return nil + return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp) } From cfc7b2209069a021500f72b71a264ff49c7ceec7 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 11:04:25 +0800 Subject: [PATCH 03/11] fix --- model/gmodel/fs_merchant_category_gen.go | 25 +++++++++++++++++++ model/gmodel/fs_merchant_category_logic.go | 2 ++ model/gmodel/fs_product_recommend_gen.go | 9 ++++--- model/gmodel/fs_product_recommend_logic.go | 10 +++++--- model/gmodel/fs_product_template_v2_gen.go | 16 ++++++------ model/gmodel/var_gen.go | 2 ++ .../homepagerecommendproductlistlogic.go | 7 +++--- server/product/internal/types/types.go | 9 ++----- server_api/product.api | 3 ++- 9 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 model/gmodel/fs_merchant_category_gen.go create mode 100644 model/gmodel/fs_merchant_category_logic.go diff --git a/model/gmodel/fs_merchant_category_gen.go b/model/gmodel/fs_merchant_category_gen.go new file mode 100644 index 00000000..732ec88b --- /dev/null +++ b/model/gmodel/fs_merchant_category_gen.go @@ -0,0 +1,25 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_merchant_category 商户类型表 +type FsMerchantCategory struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Id + ZnName *string `gorm:"default:'';" json:"zn_name"` // 中文名 + EnName *string `gorm:"default:'';" json:"en_name"` // 英文名 + Icon *string `gorm:"default:'';" json:"icon"` // 图标 + RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品 + Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 + Status *int64 `gorm:"default:0;" json:"status"` // 状态 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 +} +type FsMerchantCategoryModel struct { + db *gorm.DB + name string +} + +func NewFsMerchantCategoryModel(db *gorm.DB) *FsMerchantCategoryModel { + return &FsMerchantCategoryModel{db: db, name: "fs_merchant_category"} +} diff --git a/model/gmodel/fs_merchant_category_logic.go b/model/gmodel/fs_merchant_category_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_merchant_category_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_product_recommend_gen.go b/model/gmodel/fs_product_recommend_gen.go index 930a3da8..111494f6 100644 --- a/model/gmodel/fs_product_recommend_gen.go +++ b/model/gmodel/fs_product_recommend_gen.go @@ -6,10 +6,11 @@ import ( // fs_product_recommend 推荐商品表 type FsProductRecommend struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // - ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID - Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // + ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID + MerchantType *int64 `gorm:"default:0;" json:"merchant_type"` // 商家类型 + Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 } type FsProductRecommendModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_recommend_logic.go b/model/gmodel/fs_product_recommend_logic.go index 02e33584..0646203d 100644 --- a/model/gmodel/fs_product_recommend_logic.go +++ b/model/gmodel/fs_product_recommend_logic.go @@ -7,9 +7,10 @@ import ( ) type GetRecommendProductListReq struct { - Ctx context.Context - Page int - Limit int + Ctx context.Context + MerchantType int64 + Page int + Limit int } func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) { @@ -18,6 +19,9 @@ func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProduc Joins("inner join fs_product as p on r.product_id = p.id"). Where("r.status = ? ", 1). Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1) + if req.MerchantType > 0 { + db = db.Where("merchant_type = ?", req.MerchantType) + } if err = db.Limit(1).Count(&total).Error; err != nil { return nil, 0, err } diff --git a/model/gmodel/fs_product_template_v2_gen.go b/model/gmodel/fs_product_template_v2_gen.go index d72b388a..07ad37fc 100644 --- a/model/gmodel/fs_product_template_v2_gen.go +++ b/model/gmodel/fs_product_template_v2_gen.go @@ -9,21 +9,21 @@ type FsProductTemplateV2 struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID ModelId *int64 `gorm:"default:0;" json:"model_id"` // 模型ID - Title *string `gorm:"default:'';" json:"title"` // 模板(sku),预留字段 - Name *string `gorm:"default:'';" json:"name"` // 名称 - CoverImg *string `gorm:"default:'';" json:"cover_img"` // 模板背景图 - TemplateInfo *string `gorm:"default:'';" json:"template_info"` // 模板详情 - MaterialImg *string `gorm:"default:'';" json:"material_img"` // 合成好的贴图 + Title *string `gorm:"default:'';" json:"title"` // + Name *string `gorm:"default:'';" json:"name"` // + CoverImg *string `gorm:"default:'';" json:"cover_img"` // + TemplateInfo *string `gorm:"default:'';" json:"template_info"` // + MaterialImg *string `gorm:"default:'';" json:"material_img"` // Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 LogoWidth *int64 `gorm:"default:0;" json:"logo_width"` // logo图最大宽度 LogoHeight *int64 `gorm:"default:0;" json:"logo_height"` // logo图最大高度 IsPublic *int64 `gorm:"default:0;" json:"is_public"` // 是否可公用(1:可以,0:不可以) Status *int64 `gorm:"default:0;" json:"status"` // 状态1正常 2异常 Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 - Tag *string `gorm:"default:'';" json:"tag"` // 标签(用户自填) + Tag *string `gorm:"default:'';" json:"tag"` // IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除 - SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // 开关信息 - GroupOptions *string `gorm:"default:'';" json:"group_options"` // 颜色分组 + SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // + GroupOptions *string `gorm:"default:'';" json:"group_options"` // Version *int64 `gorm:"default:0;" json:"version"` // } type FsProductTemplateV2Model struct { diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index 46818f31..905e8301 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -45,6 +45,7 @@ type AllModelsGen struct { FsLog *FsLogModel // fs_log 日志表 FsMapLibrary *FsMapLibraryModel // fs_map_library 贴图库 FsMenu *FsMenuModel // fs_menu 后台菜单 + FsMerchantCategory *FsMerchantCategoryModel // fs_merchant_category 商户类型表 FsMigration *FsMigrationModel // fs_migration 版本库 FsOrder *FsOrderModel // fs_order FsOrderAffiliate *FsOrderAffiliateModel // fs_order_affiliate 订单附属表-流程控制时间等 @@ -140,6 +141,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen { FsLog: NewFsLogModel(gdb), FsMapLibrary: NewFsMapLibraryModel(gdb), FsMenu: NewFsMenuModel(gdb), + FsMerchantCategory: NewFsMerchantCategoryModel(gdb), FsMigration: NewFsMigrationModel(gdb), FsOrder: NewFsOrderModel(gdb), FsOrderAffiliate: NewFsOrderAffiliateModel(gdb), diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index b41c7dd0..e542aec4 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -54,9 +54,10 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty ) //获取列表推荐产品 recommendProductList, _, err = l.svcCtx.AllModels.FsProductRecommend.GetRecommendProductList(gmodel.GetRecommendProductListReq{ - Ctx: l.ctx, - Page: 1, - Limit: 500, //设置最大500 + Ctx: l.ctx, + MerchantType: req.MerchantType, + Page: 1, + Limit: 500, //设置最大500 }) if len(recommendProductList) == 0 { return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{}) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 8e718fb7..5cb5c2d4 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -342,12 +342,6 @@ type GetSizeByPidRsp struct { type GetTemplateByPidReq struct { Pid string `form:"pid"` ProductTemplateTagId int64 `form:"product_template_tag_id"` - ProductSizeId int64 `form:"product_size_id,optional"` -} - -type GetTemplateByPidRsp struct { - TemplateId int64 `json:"template_id"` //模板id - TemplateInfo interface{} `json:"template_info"` //模板信息 } type GetFittingByPidReq struct { @@ -395,7 +389,8 @@ type GetLastProductDesignRsp struct { } type HomePageRecommendProductListReq struct { - Size uint32 `form:"size"` + Size uint32 `form:"size"` + MerchantType int64 `form:"merchant_type"` } type HomePageRecommendProductListRsp struct { diff --git a/server_api/product.api b/server_api/product.api index e710a978..1f37a789 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -432,7 +432,8 @@ type GetLastProductDesignRsp { } //获取列表页推荐产品(返回是这个维度数组) type HomePageRecommendProductListReq { - Size uint32 `form:"size"` + Size uint32 `form:"size"` + MerchantType int64 `form:"merchant_type"` } type HomePageRecommendProductListRsp { Id int64 `json:"id"` From 2bb1c73e4a29c1a75a5070e572861a456101aa0f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 11:35:23 +0800 Subject: [PATCH 04/11] fix --- model/gmodel/fs_merchant_category_gen.go | 2 +- model/gmodel/fs_merchant_category_logic.go | 13 +++++- model/gmodel/fs_product_recommend_gen.go | 22 ---------- model/gmodel/fs_product_recommend_logic.go | 43 ------------------- model/gmodel/var_gen.go | 2 - .../homepagerecommendproductlistlogic.go | 34 ++++++++++++--- server/product/internal/types/types.go | 1 + server_api/product.api | 1 + 8 files changed, 43 insertions(+), 75 deletions(-) delete mode 100644 model/gmodel/fs_product_recommend_gen.go delete mode 100644 model/gmodel/fs_product_recommend_logic.go diff --git a/model/gmodel/fs_merchant_category_gen.go b/model/gmodel/fs_merchant_category_gen.go index 732ec88b..37944dce 100644 --- a/model/gmodel/fs_merchant_category_gen.go +++ b/model/gmodel/fs_merchant_category_gen.go @@ -11,7 +11,7 @@ type FsMerchantCategory struct { EnName *string `gorm:"default:'';" json:"en_name"` // 英文名 Icon *string `gorm:"default:'';" json:"icon"` // 图标 RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品 - Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 + Sort *int64 `gorm:"default:128;" json:"sort"` // 排序 Status *int64 `gorm:"default:0;" json:"status"` // 状态 Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 } diff --git a/model/gmodel/fs_merchant_category_logic.go b/model/gmodel/fs_merchant_category_logic.go index e68225aa..66b709d5 100644 --- a/model/gmodel/fs_merchant_category_logic.go +++ b/model/gmodel/fs_merchant_category_logic.go @@ -1,2 +1,13 @@ package gmodel -// TODO: 使用model的属性做你想做的 \ No newline at end of file + +import "context" + +// TODO: 使用model的属性做你想做的 +func (m *FsMerchantCategoryModel) FindOne(ctx context.Context, id int64) (resp *FsMerchantCategory, err error) { + err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("id = ? and status = ?", id, 1).Take(&resp).Error + return resp, err +} +func (m *FsMerchantCategoryModel) FindRandOne(ctx context.Context) (resp *FsMerchantCategory, err error) { + err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ?", 1).Order("RAND()").Take(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_recommend_gen.go b/model/gmodel/fs_product_recommend_gen.go deleted file mode 100644 index 111494f6..00000000 --- a/model/gmodel/fs_product_recommend_gen.go +++ /dev/null @@ -1,22 +0,0 @@ -package gmodel - -import ( - "gorm.io/gorm" -) - -// fs_product_recommend 推荐商品表 -type FsProductRecommend struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // - ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID - MerchantType *int64 `gorm:"default:0;" json:"merchant_type"` // 商家类型 - Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 -} -type FsProductRecommendModel struct { - db *gorm.DB - name string -} - -func NewFsProductRecommendModel(db *gorm.DB) *FsProductRecommendModel { - return &FsProductRecommendModel{db: db, name: "fs_product_recommend"} -} diff --git a/model/gmodel/fs_product_recommend_logic.go b/model/gmodel/fs_product_recommend_logic.go deleted file mode 100644 index 0646203d..00000000 --- a/model/gmodel/fs_product_recommend_logic.go +++ /dev/null @@ -1,43 +0,0 @@ -package gmodel - -import ( - "context" - "errors" - "gorm.io/gorm" -) - -type GetRecommendProductListReq struct { - Ctx context.Context - MerchantType int64 - Page int - Limit int -} - -func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) { - db := r.db.WithContext(req.Ctx). - Table("fs_product_recommend as r"). - Joins("inner join fs_product as p on r.product_id = p.id"). - Where("r.status = ? ", 1). - Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1) - if req.MerchantType > 0 { - db = db.Where("merchant_type = ?", req.MerchantType) - } - if err = db.Limit(1).Count(&total).Error; err != nil { - return nil, 0, err - } - db = db.Select("p.*") - offset := (req.Page - 1) * req.Limit - err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error - return resp, total, err -} -func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, data *FsProductRecommend) error { - var info FsProductRecommend - err := r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Take(&info).Error - if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return err - } - if info.Id == 0 { - return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Create(data).Error - } - return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Updates(data).Error -} diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index 905e8301..b62e2377 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -62,7 +62,6 @@ type AllModelsGen struct { FsProductModel3dLight *FsProductModel3dLightModel // fs_product_model3d_light 模型-灯光组表 FsProductOption *FsProductOptionModel // fs_product_option 产品选项表(已废弃) FsProductPrice *FsProductPriceModel // fs_product_price 阶梯价格表 - FsProductRecommend *FsProductRecommendModel // fs_product_recommend 推荐商品表 FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表 FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表 @@ -158,7 +157,6 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen { FsProductModel3dLight: NewFsProductModel3dLightModel(gdb), FsProductOption: NewFsProductOptionModel(gdb), FsProductPrice: NewFsProductPriceModel(gdb), - FsProductRecommend: NewFsProductRecommendModel(gdb), FsProductRenderDesign: NewFsProductRenderDesignModel(gdb), FsProductScene: NewFsProductSceneModel(gdb), FsProductSize: NewFsProductSizeModel(gdb), diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index e542aec4..61708dfa 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -42,6 +42,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err") } var ( + merchantInfo *gmodel.FsMerchantCategory recommendProductList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方) productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表 mapProductHaveOptionFitting = make(map[int64]struct{}) @@ -52,13 +53,34 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map mapProductTemplate = make(map[int64]struct{}) //产品模板map ) + //选了商家类型 + if req.MerchantType > 0 { + merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType) + } else { + //随机获取一个商家类型 + merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindRandOne(l.ctx) + } + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of merchant type found") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant type info") + } + if *merchantInfo.RecommendProduct == "" { + return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{}) + } + recommendProductIds, err := format.StrSlicToInt64Slice(strings.Split(*merchantInfo.RecommendProduct, ",")) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse recommend product") + } //获取列表推荐产品 - recommendProductList, _, err = l.svcCtx.AllModels.FsProductRecommend.GetRecommendProductList(gmodel.GetRecommendProductListReq{ - Ctx: l.ctx, - MerchantType: req.MerchantType, - Page: 1, - Limit: 500, //设置最大500 - }) + recommendProductList, err = l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, recommendProductIds, "sort-desc") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list") + } if len(recommendProductList) == 0 { return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{}) } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 5cb5c2d4..435229a7 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -341,6 +341,7 @@ type GetSizeByPidRsp struct { type GetTemplateByPidReq struct { Pid string `form:"pid"` + ProductSizeId int64 `form:"product_size_id,optional"` ProductTemplateTagId int64 `form:"product_template_tag_id"` } diff --git a/server_api/product.api b/server_api/product.api index 1f37a789..0fd841bf 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -386,6 +386,7 @@ type GetSizeByPidRsp { //获取产品模板 type GetTemplateByPidReq { Pid string `form:"pid"` + ProductSizeId int64 `form:"product_size_id,optional"` ProductTemplateTagId int64 `form:"product_template_tag_id"` } //获取产品配件数据 From 76b291c02a7373c86a669c885d4b80678b3a356c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 11:46:29 +0800 Subject: [PATCH 05/11] fix --- server/product/internal/logic/gettagproductlistlogic.go | 5 +++-- .../internal/logic/homepagerecommendproductlistlogic.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 8c6f5a3c..480e2bc1 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -366,12 +366,13 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, Recommended: *productInfo.IsRecommend > 0, + Cover: *productInfo.Cover, } if _, ok = req.MapTagProp[productInfo.Id]; ok { item.CoverDefault = req.MapTagProp[productInfo.Id] } //千人千面处理 - r := image.ThousandFaceImageFormatReq{ + /*r := image.ThousandFaceImageFormatReq{ Size: int(req.Size), IsThousandFace: 0, Cover: *productInfo.Cover, @@ -383,7 +384,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL r.IsThousandFace = int(*req.User.IsThousandFace) } image.ThousandFaceImageFormat(&r) - item.Cover = r.Cover + item.Cover = r.Cover*/ //加入分类产品切片 productListRsp = append(productListRsp, item) } diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 61708dfa..77a24069 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -170,12 +170,14 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty Id: productInfo.Id, Sn: *productInfo.Sn, Title: *productInfo.Title, + Cover: *productInfo.Cover, + CoverDefault: *productInfo.Cover, SizeNum: uint32(sizeNum), MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, } //千人千面处理 - r := image.ThousandFaceImageFormatReq{ + /*r := image.ThousandFaceImageFormatReq{ Size: int(req.Size), IsThousandFace: 0, Cover: *productInfo.Cover, @@ -189,7 +191,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty } image.ThousandFaceImageFormat(&r) item.Cover = r.Cover - item.CoverDefault = r.CoverDefault + item.CoverDefault = r.CoverDefault*/ //加入分类产品切片 listRsp = append(listRsp, item) } From aa895fda51e756b169f1905d5598b8cda13a3213 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 11:49:02 +0800 Subject: [PATCH 06/11] fix --- .../internal/logic/homepagerecommendproductlistlogic.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 77a24069..6273a99a 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -7,7 +7,6 @@ import ( "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/format" - "fusenapi/utils/image" "gorm.io/gorm" "sort" "strings" @@ -36,7 +35,7 @@ func NewHomePageRecommendProductListLogic(ctx context.Context, svcCtx *svc.Servi func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *types.HomePageRecommendProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) { //查询用户信息(不用判断存在) - user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) + _, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err") From 06e32e6af9c757605c4190e6f0797ee902d54380 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 11:53:16 +0800 Subject: [PATCH 07/11] fix --- .../logic/homepagerecommendproductlistlogic.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 6273a99a..3656f78e 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -44,13 +44,13 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty merchantInfo *gmodel.FsMerchantCategory recommendProductList []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 + mapProductHaveOptionFitting = make(map[int64]struct{}) //是否有配件map + 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.MerchantType > 0 { From 5bc6f411bed552831f181774a57365d089bae98c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 12:05:22 +0800 Subject: [PATCH 08/11] fix --- server/render/consumer/assemble_render_data.go | 8 ++++---- utils/websocket_data/render_data.go | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index 5b041711..bf368975 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -183,10 +183,10 @@ func getCombineImage(ctx context.Context, svcCtx *svc.ServiceContext, parseInfo //需要替换的参数 replaceData := map[string]interface{}{ "logo_url": parseInfo.RenderData.Logo, - "website": "", - "slogan": "", - "address": "", - "phone": "", + "website": parseInfo.RenderData.Website, + "slogan": parseInfo.RenderData.Slogan, + "address": parseInfo.RenderData.Address, + "phone": parseInfo.RenderData.Phone, "colors": []string{}, "template_tagid": []string{"b1a"}, "is_crop": false, diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 8bde5dbe..fcec9690 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -16,6 +16,10 @@ type RenderData struct { ProductId int64 `json:"product_id"` //产品id UserMaterialId int64 `json:"user_material_id"` //用户素材id Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) + Website string `json:"website"` //网站 + Slogan string `json:"slogan"` //slogan + Address string `json:"address"` //地址 + Phone string `json:"phone"` //电话 UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) } From 35b02302ebf55add154543537fb122228b6e6c44 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 12:30:14 +0800 Subject: [PATCH 09/11] fix --- .../logic/getrecommandproductlistlogic.go | 46 +++++++++++++------ .../homepagerecommendproductlistlogic.go | 17 ++++++- server/product/internal/types/types.go | 36 +++++++-------- server_api/product.api | 36 +++++++-------- 4 files changed, 83 insertions(+), 52 deletions(-) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index f3bf72be..3d4e9734 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -113,14 +113,27 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec } } //获取用户信息(不用判断存在) - user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) + /*user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user") + }*/ + //获取产品标签相关属性 + productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property") + } + mapTagProp := make(map[int64][]types.CoverDefaultItem) + for _, v := range productTagPropList { + mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{ + Tag: v.Title, + Cover: *v.Cover, + }) } list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList)) for _, v := range recommendProductList { - r := image.ThousandFaceImageFormatReq{ + /*r := image.ThousandFaceImageFormatReq{ Size: int(req.Size), IsThousandFace: 0, Cover: *v.Cover, @@ -133,7 +146,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec r.IsThousandFace = int(*user.IsThousandFace) } //千人前面处理 - image.ThousandFaceImageFormat(&r) + image.ThousandFaceImageFormat(&r)*/ isRecommend := int64(0) if _, ok := mapRecommend[v.Id]; ok { isRecommend = 1 @@ -142,18 +155,21 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec if minVal, ok := mapProductMinPrice[v.Id]; ok { minPrice = minVal } - list = append(list, types.GetRecommandProductListRsp{ - Id: v.Id, - Sn: *v.Sn, - Title: *v.Title, - TitleCn: *v.TitleCn, - Cover: r.Cover, - CoverImg: r.CoverImg, - CoverDefault: r.CoverDefault, - Intro: *v.Intro, - IsRecommend: isRecommend, - MinPrice: minPrice, - }) + item := types.GetRecommandProductListRsp{ + Id: v.Id, + Sn: *v.Sn, + Title: *v.Title, + TitleCn: *v.TitleCn, + Cover: *productInfo.Cover, + CoverImg: *productInfo.CoverImg, + Intro: *v.Intro, + IsRecommend: isRecommend, + MinPrice: minPrice, + } + if _, ok := mapTagProp[productInfo.Id]; ok { + item.CoverDefault = mapTagProp[productInfo.Id] + } + list = append(list, item) } return resp.SetStatusWithMessage(basic.CodeOK, "success", list) } diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 3656f78e..4e5740c9 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -147,6 +147,19 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty for _, v := range productSizeCountList { mapProductSizeCount[v.ProductId] = v.Num } + //获取产品标签相关属性 + productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property") + } + mapTagProp := make(map[int64][]types.CoverDefaultItem) + for _, v := range productTagPropList { + mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{ + Tag: v.Title, + Cover: *v.Cover, + }) + } //组装返回 listRsp := make([]types.HomePageRecommendProductListRsp, 0, len(recommendProductList)) for _, productInfo := range recommendProductList { @@ -170,11 +183,13 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty Sn: *productInfo.Sn, Title: *productInfo.Title, Cover: *productInfo.Cover, - CoverDefault: *productInfo.Cover, SizeNum: uint32(sizeNum), MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, } + if _, ok = mapTagProp[productInfo.Id]; ok { + item.CoverDefault = mapTagProp[productInfo.Id] + } //千人千面处理 /*r := image.ThousandFaceImageFormatReq{ Size: int(req.Size), diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 435229a7..e44a240f 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -234,16 +234,16 @@ type GetRecommandProductListReq struct { } type GetRecommandProductListRsp struct { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - TitleCn string `json:"title_cn"` - Cover string `json:"cover"` - CoverImg string `json:"cover_img"` - CoverDefault string `json:"cover_default"` - Intro string `json:"intro"` - IsRecommend int64 `json:"is_recommend"` - MinPrice int64 `json:"min_price"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + TitleCn string `json:"title_cn"` + Cover string `json:"cover"` + CoverImg string `json:"cover_img"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + Intro string `json:"intro"` + IsRecommend int64 `json:"is_recommend"` + MinPrice int64 `json:"min_price"` } type GetTagProductListReq struct { @@ -395,14 +395,14 @@ type HomePageRecommendProductListReq struct { } type HomePageRecommendProductListRsp struct { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - SizeNum uint32 `json:"size_num"` - MinPrice int64 `json:"min_price"` - CoverDefault string `json:"cover_default"` - HaveOptionalFitting bool `json:"have_optional_fitting"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + Cover string `json:"cover"` + SizeNum uint32 `json:"size_num"` + MinPrice int64 `json:"min_price"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + HaveOptionalFitting bool `json:"have_optional_fitting"` } type Request struct { diff --git a/server_api/product.api b/server_api/product.api index 0fd841bf..cbdc734f 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -286,16 +286,16 @@ type GetRecommandProductListReq { Sn string `form:"sn"` } type GetRecommandProductListRsp { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - TitleCn string `json:"title_cn"` - Cover string `json:"cover"` - CoverImg string `json:"cover_img"` - CoverDefault string `json:"cover_default"` - Intro string `json:"intro"` - IsRecommend int64 `json:"is_recommend"` - MinPrice int64 `json:"min_price"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + TitleCn string `json:"title_cn"` + Cover string `json:"cover"` + CoverImg string `json:"cover_img"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + Intro string `json:"intro"` + IsRecommend int64 `json:"is_recommend"` + MinPrice int64 `json:"min_price"` } //获取分类产品列表 type GetTagProductListReq { @@ -437,12 +437,12 @@ type HomePageRecommendProductListReq { MerchantType int64 `form:"merchant_type"` } type HomePageRecommendProductListRsp { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - SizeNum uint32 `json:"size_num"` - MinPrice int64 `json:"min_price"` - CoverDefault string `json:"cover_default"` - HaveOptionalFitting bool `json:"have_optional_fitting"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + Cover string `json:"cover"` + SizeNum uint32 `json:"size_num"` + MinPrice int64 `json:"min_price"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + HaveOptionalFitting bool `json:"have_optional_fitting"` } \ No newline at end of file From 68441426032f3d7b32bb38d07bb91061da51605a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 12:31:49 +0800 Subject: [PATCH 10/11] fix --- .../logic/getrecommandproductlistlogic.go | 19 ++++++++++--------- .../homepagerecommendproductlistlogic.go | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 3d4e9734..018d68a4 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -156,15 +156,16 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec minPrice = minVal } item := types.GetRecommandProductListRsp{ - Id: v.Id, - Sn: *v.Sn, - Title: *v.Title, - TitleCn: *v.TitleCn, - Cover: *productInfo.Cover, - CoverImg: *productInfo.CoverImg, - Intro: *v.Intro, - IsRecommend: isRecommend, - MinPrice: minPrice, + Id: v.Id, + Sn: *v.Sn, + Title: *v.Title, + TitleCn: *v.TitleCn, + Cover: *productInfo.Cover, + CoverImg: *productInfo.CoverImg, + CoverDefault: []types.CoverDefaultItem{}, + Intro: *v.Intro, + IsRecommend: isRecommend, + MinPrice: minPrice, } if _, ok := mapTagProp[productInfo.Id]; ok { item.CoverDefault = mapTagProp[productInfo.Id] diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 4e5740c9..a8bd03df 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -183,6 +183,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty Sn: *productInfo.Sn, Title: *productInfo.Title, Cover: *productInfo.Cover, + CoverDefault: []types.CoverDefaultItem{}, SizeNum: uint32(sizeNum), MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, From bdd9a70a2dedef60edda6edea1a6281488d31c16 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 14 Aug 2023 14:21:14 +0800 Subject: [PATCH 11/11] fix --- server/product/internal/logic/gettemplatebypidlogic.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index e036fa15..d13dbd0a 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -88,7 +88,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list") } - rsp := make(map[string][]interface{}) + rsp := make(map[string]interface{}) for _, templateInfo := range templateList { //没有设置模板据不要 if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" { @@ -115,11 +115,11 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, material = info["module_data"]["material"] } mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId) - rsp[mapKey] = append(rsp[mapKey], map[string]interface{}{ + rsp[mapKey] = map[string]interface{}{ "id": templateInfo.Id, "material": material, "material_data": switchInfo, - }) + } } return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp) }