fix
This commit is contained in:
parent
3c0d1a8d7a
commit
6d58e6bb22
|
@ -6,12 +6,12 @@ import (
|
|||
|
||||
// fs_product_tag_prop 产品标签相关属性表
|
||||
type FsProductTagProp struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
||||
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id
|
||||
TagId *int64 `gorm:"default:0;" json:"tag_id"` // 模板标签id
|
||||
Cover *string `gorm:"default:'';" json:"cover"` //
|
||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
||||
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id
|
||||
TemplateTagId *int64 `gorm:"default:0;" json:"template_tag_id"` // 模板标签id
|
||||
Cover *string `gorm:"default:'';" json:"cover"` //
|
||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间
|
||||
}
|
||||
type FsProductTagPropModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -1,2 +1,21 @@
|
|||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
type GetTagPropByProductIdsWithProductTagRsp struct {
|
||||
FsProductTagProp
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
func (p *FsProductTagPropModel) GetTagPropByProductIdsWithProductTag(ctx context.Context, productIds []int64) (resp []GetTagPropByProductIdsWithProductTagRsp, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return
|
||||
}
|
||||
err = p.db.WithContext(ctx).Table(p.name+" as p ").
|
||||
Joins("left join fs_product_template_tags as t on p.template_tag_id = t.id").
|
||||
Select("p.*,t.title as title").
|
||||
Where("p.product_id in (?) and p.status = ? and t.status = ?", productIds, 1, 1).
|
||||
Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import (
|
|||
"fusenapi/constants"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"gorm.io/gorm"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
|
@ -52,8 +54,38 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
|
||||
}
|
||||
sizeIds := make([]int64, 0, len(sizeList))
|
||||
productIds := make([]int64, 0, len(sizeList))
|
||||
for _, v := range sizeList {
|
||||
sizeIds = append(sizeIds, v.Id)
|
||||
productIds = append(productIds, *v.ProductId)
|
||||
}
|
||||
//获取产品价格列表
|
||||
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
|
||||
}
|
||||
mapProductMinPrice := make(map[int64]int64)
|
||||
//存储产品最小价格
|
||||
for _, v := range productPriceList {
|
||||
priceStrSlic := strings.Split(v.Price, ",")
|
||||
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
if len(priceSlice) == 0 {
|
||||
continue
|
||||
}
|
||||
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
|
||||
sort.Ints(priceSlice)
|
||||
if min, ok := mapProductMinPrice[v.ProductId]; ok {
|
||||
if min > int64(priceSlice[0]) {
|
||||
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||
}
|
||||
} else {
|
||||
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||
}
|
||||
}
|
||||
//获取对应模型数据
|
||||
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id")
|
||||
|
@ -75,6 +107,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||
}
|
||||
var title interface{}
|
||||
_ = json.Unmarshal([]byte(*sizeInfo.Title), &title)
|
||||
minPrice := int64(0)
|
||||
if price, ok := mapProductMinPrice[*sizeInfo.ProductId]; ok {
|
||||
minPrice = price
|
||||
}
|
||||
listRsp = append(listRsp, types.GetSizeByPidRsp{
|
||||
Id: sizeInfo.Id,
|
||||
Title: title,
|
||||
|
@ -83,6 +119,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
|
||||
ModelId: modelList[modelIndex].Id,
|
||||
IsPopular: *sizeInfo.IsPopular > 0,
|
||||
MinPrice: float64(minPrice) / 100,
|
||||
})
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
|
||||
|
|
|
@ -34,16 +34,16 @@ func NewGetTagProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
}
|
||||
|
||||
func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
//获取合适尺寸
|
||||
if req.Size > 0 {
|
||||
req.Size = image.GetCurrentSize(req.Size)
|
||||
}
|
||||
//查询用户信息(不用判断存在)
|
||||
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.CodeServiceErr, "get user info err")
|
||||
}
|
||||
//获取合适尺寸
|
||||
if req.Size > 0 {
|
||||
req.Size = image.GetCurrentSize(req.Size)
|
||||
}
|
||||
//查询分类列表
|
||||
tStatus := int64(1)
|
||||
tReq := gmodel.GetAllTagByParamsReq{
|
||||
|
@ -81,7 +81,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
typeIds = append(typeIds, v.Id)
|
||||
}
|
||||
var (
|
||||
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||
mapTagProp = make(map[int64][]types.CoverDefaultItem)
|
||||
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
||||
mapProductHaveOptionFitting = make(map[int64]struct{})
|
||||
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
||||
|
@ -129,6 +130,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
}
|
||||
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
||||
}
|
||||
//获取产品标签相关属性
|
||||
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")
|
||||
}
|
||||
for _, v := range productTagPropList {
|
||||
mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{
|
||||
Tag: v.Title,
|
||||
Cover: *v.Cover,
|
||||
})
|
||||
}
|
||||
//获取产品价格列表
|
||||
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||
if err != nil {
|
||||
|
@ -183,6 +196,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||
TagList: tagList,
|
||||
WithProduct: req.WithProduct,
|
||||
ProductList: productList,
|
||||
MapTagProp: mapTagProp,
|
||||
MapProductMinPrice: mapProductMinPrice,
|
||||
MapProductTemplate: mapProductTemplate,
|
||||
MapProductSizeCount: mapProductSizeCount,
|
||||
|
@ -206,6 +220,8 @@ type dealWithTagMenuDataReq struct {
|
|||
TagList []gmodel.FsTags
|
||||
WithProduct bool
|
||||
ProductList []gmodel.FsProduct
|
||||
MapTagProp map[int64][]types.CoverDefaultItem
|
||||
ProductTagPropList []gmodel.FsProductTagProp
|
||||
MapProductMinPrice map[int64]int64
|
||||
MapProductTemplate map[int64]struct{}
|
||||
MapProductSizeCount map[int64]int64
|
||||
|
@ -238,6 +254,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
|||
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||
TagId: tagInfo.Id,
|
||||
ProductList: req.ProductList,
|
||||
MapTagProp: req.MapTagProp,
|
||||
MapProductMinPrice: req.MapProductMinPrice,
|
||||
MapProductTemplate: req.MapProductTemplate,
|
||||
MapProductSizeCount: req.MapProductSizeCount,
|
||||
|
@ -308,6 +325,7 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL
|
|||
type getTagProductsReq struct {
|
||||
TagId int64
|
||||
ProductList []gmodel.FsProduct
|
||||
MapTagProp map[int64][]types.CoverDefaultItem
|
||||
MapProductMinPrice map[int64]int64
|
||||
MapProductTemplate map[int64]struct{}
|
||||
MapProductSizeCount map[int64]int64
|
||||
|
@ -344,17 +362,20 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
|||
Sn: *productInfo.Sn,
|
||||
Title: *productInfo.Title,
|
||||
SizeNum: uint32(sizeNum),
|
||||
CoverDefault: []types.CoverDefaultItem{},
|
||||
MinPrice: minPrice,
|
||||
HaveOptionalFitting: haveOptionalFitting,
|
||||
Recommended: *productInfo.IsRecommend > 0,
|
||||
}
|
||||
if _, ok = req.MapTagProp[productInfo.Id]; ok {
|
||||
item.CoverDefault = req.MapTagProp[productInfo.Id]
|
||||
}
|
||||
//千人千面处理
|
||||
r := image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: 0,
|
||||
Cover: *productInfo.Cover,
|
||||
CoverImg: *productInfo.CoverImg,
|
||||
CoverDefault: *productInfo.CoverImg,
|
||||
ProductId: productInfo.Id,
|
||||
UserId: req.User.Id,
|
||||
}
|
||||
|
@ -363,7 +384,6 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
|||
}
|
||||
image.ThousandFaceImageFormat(&r)
|
||||
item.Cover = r.Cover
|
||||
item.CoverDefault = nil
|
||||
//加入分类产品切片
|
||||
productListRsp = append(productListRsp, item)
|
||||
}
|
||||
|
|
|
@ -336,6 +336,7 @@ type GetSizeByPidRsp struct {
|
|||
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
||||
ModelId int64 `json:"model_id"` //产品主模型id
|
||||
IsPopular bool `json:"is_popular"` //是否受欢迎
|
||||
MinPrice float64 `json:"min_price"` //最小价格
|
||||
}
|
||||
|
||||
type GetTemplateByPidReq struct {
|
||||
|
|
|
@ -381,6 +381,7 @@ type GetSizeByPidRsp {
|
|||
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
||||
ModelId int64 `json:"model_id"` //产品主模型id
|
||||
IsPopular bool `json:"is_popular"` //是否受欢迎
|
||||
MinPrice float64 `json:"min_price"` //最小价格
|
||||
}
|
||||
//获取产品模板列表
|
||||
type GetTemplateByPidReq {
|
||||
|
|
Loading…
Reference in New Issue
Block a user