Merge branch 'develop' into feature/auth

This commit is contained in:
eson
2023-08-22 10:34:21 +08:00
79 changed files with 1360 additions and 495 deletions

View File

@@ -73,7 +73,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us
partIds = append(partIds, *v.PartId)
}
//获取配件数据
fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "is_popular DESC,price ASC")
fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "is_hot DESC,price ASC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get part list")
@@ -110,7 +110,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us
Title: *fitting.Title,
Price: *fitting.Price,
ModelInfo: modelInfo,
IsPopular: *fitting.IsPopular > 0,
IsPopular: *fitting.IsHot > 0,
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)

View File

@@ -99,7 +99,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
}
//获取模板
productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds)
productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")

View File

@@ -48,7 +48,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//获取产品尺寸列表(需要正序排序)
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_popular DESC,sort ASC")
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_hot DESC,sort ASC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
@@ -118,7 +118,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
Cover: *sizeInfo.Cover,
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
ModelId: modelList[modelIndex].Id,
IsPopular: *sizeInfo.IsPopular > 0,
IsPopular: *sizeInfo.IsHot > 0,
MinPrice: float64(minPrice) / 100,
})
}

View File

@@ -63,6 +63,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info")
}
//前台用的分类是1
if *tagData.Category != 1 {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "invalid tag")
}
@@ -90,7 +91,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表select 字段需要看查询的地方)
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表select 字段需要看查询的地方)
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
mapProductTemplate = make(map[int64]struct{}) //产品模板map
mapProductTemplate = make(map[int64]int64) //产品模板map
)
//携带产品
if req.WithProduct {
@@ -169,14 +170,22 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
}
//获取模板(只是获取产品product_id)
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id")
//获取模板(只是获取产品product_id,id)
if req.TemplateTag != "" { //指定模板tag
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "sort ASC", "product_id,id")
} else { //没指定模板tag
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id")
}
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product templates")
}
//只存第一个
for _, v := range productTemplatesV2 {
mapProductTemplate[*v.ProductId] = struct{}{}
if _, ok := mapProductTemplate[*v.ProductId]; ok {
continue
}
mapProductTemplate[*v.ProductId] = v.Id
}
//获取产品尺寸数量
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
@@ -209,9 +218,11 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
logx.Error(err)
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
}
//组装等级从属关系
rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel)
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
TotalCategoryProduct: len(productList),
TagList: l.organizationLevelRelation(minLevel, mapTagLevel), //组装等级从属关系
TotalCategoryProduct: TotalCategoryProduct,
TagList: rspTagList,
})
}
@@ -223,7 +234,7 @@ type dealWithTagMenuDataReq struct {
MapTagProp map[int64][]types.CoverDefaultItem
ProductTagPropList []gmodel.FsProductTagProp
MapProductMinPrice map[int64]int64
MapProductTemplate map[int64]struct{}
MapProductTemplate map[int64]int64
MapProductSizeCount map[int64]int64
MapTagLevel map[string]*types.TagItem
MapProductHaveOptionFitting map[int64]struct{}
@@ -274,7 +285,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
}
// 组织等级从属关系
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) []types.TagItem {
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) (rspTagList []types.TagItem, productCount int) {
mapTop := make(map[string]struct{})
//设置归属关系
for prefix, tagItem := range mapTagLevel {
@@ -316,22 +327,23 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL
if len(mapTagLevel[prefix].TagProductList) == 0 {
continue
}
productCount += len(mapTagLevel[prefix].TagProductList)
rspList = append(rspList, *mapTagLevel[prefix])
}
//排序
sort.SliceStable(rspList, func(i, j int) bool {
return rspList[i].Sort < rspList[j].Sort
})
return rspList
return rspList, productCount
}
// 获取对应tag的产品列表
// 获取某个tag的直属产品
type getTagProductsReq struct {
TagId int64
ProductList []gmodel.FsProduct
MapTagProp map[int64][]types.CoverDefaultItem
MapProductMinPrice map[int64]int64
MapProductTemplate map[int64]struct{}
MapProductTemplate map[int64]int64
MapProductSizeCount map[int64]int64
MapProductHaveOptionFitting map[int64]struct{}
Size uint32
@@ -347,7 +359,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
continue
}
minPrice, ok := req.MapProductMinPrice[productInfo.Id]
_, tmpOk := req.MapProductTemplate[productInfo.Id]
templateId, tmpOk := req.MapProductTemplate[productInfo.Id]
//无最小价格则不显示 || 没有模板也不显示
if !ok || !tmpOk {
continue
@@ -367,6 +379,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
Title: *productInfo.Title,
SizeNum: uint32(sizeNum),
CoverDefault: []types.CoverDefaultItem{},
DefaultTemplateId: templateId,
MinPrice: minPrice,
HaveOptionalFitting: haveOptionalFitting,
Recommended: *productInfo.IsRecommend > 0,

View File

@@ -37,8 +37,8 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
if req.Pid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
}
if req.ProductTemplateTagId <= 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id")
if req.TemplateTag == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:template_tag")
}
//获取产品信息(只获取id)
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
@@ -67,15 +67,6 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
} else { //指定物料
sizeIds = append(sizeIds, req.ProductSizeId)
}
//获取templatetag信息
templateTagInfo, err := l.svcCtx.AllModels.FsProductTemplateTags.FindOne(l.ctx, req.ProductTemplateTagId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template tag is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "failed to get template tag")
}
//根据尺寸id获取模型
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL)
if err != nil {
@@ -92,7 +83,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
mapModel[v.Id] = k
}
//查询模型ids下对应tag标签的模板
templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, *templateTagInfo.TemplateTag, "")
templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, req.TemplateTag, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list")
@@ -113,17 +104,42 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id))
}
//后台隐藏/显示信息
var switchInfo interface{}
//后台隐藏/显示信息(现在下面是写死了)
/*var switchInfo interface{}
if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" {
_ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo)
}
}*/
modelInfo := modelList[modelIndex]
mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId)
rsp[mapKey] = map[string]interface{}{
"id": templateInfo.Id,
"material": *templateInfo.MaterialImg,
"material_data": switchInfo,
"id": templateInfo.Id,
"material": *templateInfo.MaterialImg,
//写死的数据
"material_data": map[string]interface{}{
"QRcode": map[string]interface{}{
"if_show": true,
"text": "1111",
"default_value": "11111",
},
"Website": map[string]interface{}{
"if_show": true,
"text": "2222",
"default_value": "2222",
},
"Address": map[string]interface{}{
"if_show": true,
"text": "address",
"default_value": "address",
},
"Phone": map[string]interface{}{
"if_show": true,
"text": "phone",
"default_value": "默认phone",
},
"Logo": map[string]interface{}{
"material": "/image/logo/aHnT1_rzubdwax_scale.png",
},
},
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp)

View File

@@ -130,7 +130,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
}
}
//获取模板(只是获取产品product_id)
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id")
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "", "product_id")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")

View File

@@ -249,6 +249,7 @@ type GetRecommandProductListRsp struct {
type GetTagProductListReq struct {
Cid int64 `form:"cid,optional"` //分类id
Size uint32 `form:"size,optional"` //尺寸
TemplateTag string `form:"template_tag,optional"` //模板标签
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
}
@@ -275,6 +276,7 @@ type TagProduct struct {
SizeNum uint32 `json:"size_num"`
MinPrice int64 `json:"min_price"`
CoverDefault []CoverDefaultItem `json:"cover_default"`
DefaultTemplateId int64 `json:"default_template_id"`
HaveOptionalFitting bool `json:"have_optional_fitting"`
Recommended bool `json:"recommended"`
}
@@ -340,9 +342,9 @@ type GetSizeByPidRsp struct {
}
type GetTemplateByPidReq struct {
Pid string `form:"pid"`
ProductSizeId int64 `form:"product_size_id,optional"`
ProductTemplateTagId int64 `form:"product_template_tag_id"`
Pid string `form:"pid"`
ProductSizeId int64 `form:"product_size_id,optional"`
TemplateTag string `form:"template_tag"`
}
type GetFittingByPidReq struct {