fix
This commit is contained in:
parent
3c0d1a8d7a
commit
6d58e6bb22
model/gmodel
server/product/internal
server_api
|
@ -8,7 +8,7 @@ import (
|
||||||
type FsProductTagProp struct {
|
type FsProductTagProp struct {
|
||||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
||||||
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id
|
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id
|
||||||
TagId *int64 `gorm:"default:0;" json:"tag_id"` // 模板标签id
|
TemplateTagId *int64 `gorm:"default:0;" json:"template_tag_id"` // 模板标签id
|
||||||
Cover *string `gorm:"default:'';" json:"cover"` //
|
Cover *string `gorm:"default:'';" json:"cover"` //
|
||||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态
|
Status *int64 `gorm:"default:1;" json:"status"` // 状态
|
||||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间
|
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间
|
||||||
|
|
|
@ -1,2 +1,21 @@
|
||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// 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/constants"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/format"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
@ -52,8 +54,38 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
|
||||||
}
|
}
|
||||||
sizeIds := make([]int64, 0, len(sizeList))
|
sizeIds := make([]int64, 0, len(sizeList))
|
||||||
|
productIds := make([]int64, 0, len(sizeList))
|
||||||
for _, v := range sizeList {
|
for _, v := range sizeList {
|
||||||
sizeIds = append(sizeIds, v.Id)
|
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")
|
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{}
|
var title interface{}
|
||||||
_ = json.Unmarshal([]byte(*sizeInfo.Title), &title)
|
_ = json.Unmarshal([]byte(*sizeInfo.Title), &title)
|
||||||
|
minPrice := int64(0)
|
||||||
|
if price, ok := mapProductMinPrice[*sizeInfo.ProductId]; ok {
|
||||||
|
minPrice = price
|
||||||
|
}
|
||||||
listRsp = append(listRsp, types.GetSizeByPidRsp{
|
listRsp = append(listRsp, types.GetSizeByPidRsp{
|
||||||
Id: sizeInfo.Id,
|
Id: sizeInfo.Id,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
@ -83,6 +119,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
||||||
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
|
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
|
||||||
ModelId: modelList[modelIndex].Id,
|
ModelId: modelList[modelIndex].Id,
|
||||||
IsPopular: *sizeInfo.IsPopular > 0,
|
IsPopular: *sizeInfo.IsPopular > 0,
|
||||||
|
MinPrice: float64(minPrice) / 100,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
|
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) {
|
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)
|
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
}
|
}
|
||||||
|
//获取合适尺寸
|
||||||
|
if req.Size > 0 {
|
||||||
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
|
}
|
||||||
//查询分类列表
|
//查询分类列表
|
||||||
tStatus := int64(1)
|
tStatus := int64(1)
|
||||||
tReq := gmodel.GetAllTagByParamsReq{
|
tReq := gmodel.GetAllTagByParamsReq{
|
||||||
|
@ -82,6 +82,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||||
|
mapTagProp = make(map[int64][]types.CoverDefaultItem)
|
||||||
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
||||||
mapProductHaveOptionFitting = make(map[int64]struct{})
|
mapProductHaveOptionFitting = make(map[int64]struct{})
|
||||||
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
||||||
|
@ -129,6 +130,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
}
|
}
|
||||||
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
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)
|
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -183,6 +196,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
TagList: tagList,
|
TagList: tagList,
|
||||||
WithProduct: req.WithProduct,
|
WithProduct: req.WithProduct,
|
||||||
ProductList: productList,
|
ProductList: productList,
|
||||||
|
MapTagProp: mapTagProp,
|
||||||
MapProductMinPrice: mapProductMinPrice,
|
MapProductMinPrice: mapProductMinPrice,
|
||||||
MapProductTemplate: mapProductTemplate,
|
MapProductTemplate: mapProductTemplate,
|
||||||
MapProductSizeCount: mapProductSizeCount,
|
MapProductSizeCount: mapProductSizeCount,
|
||||||
|
@ -206,6 +220,8 @@ type dealWithTagMenuDataReq struct {
|
||||||
TagList []gmodel.FsTags
|
TagList []gmodel.FsTags
|
||||||
WithProduct bool
|
WithProduct bool
|
||||||
ProductList []gmodel.FsProduct
|
ProductList []gmodel.FsProduct
|
||||||
|
MapTagProp map[int64][]types.CoverDefaultItem
|
||||||
|
ProductTagPropList []gmodel.FsProductTagProp
|
||||||
MapProductMinPrice map[int64]int64
|
MapProductMinPrice map[int64]int64
|
||||||
MapProductTemplate map[int64]struct{}
|
MapProductTemplate map[int64]struct{}
|
||||||
MapProductSizeCount map[int64]int64
|
MapProductSizeCount map[int64]int64
|
||||||
|
@ -238,6 +254,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
||||||
productListRsp := l.getTagProducts(getTagProductsReq{
|
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||||
TagId: tagInfo.Id,
|
TagId: tagInfo.Id,
|
||||||
ProductList: req.ProductList,
|
ProductList: req.ProductList,
|
||||||
|
MapTagProp: req.MapTagProp,
|
||||||
MapProductMinPrice: req.MapProductMinPrice,
|
MapProductMinPrice: req.MapProductMinPrice,
|
||||||
MapProductTemplate: req.MapProductTemplate,
|
MapProductTemplate: req.MapProductTemplate,
|
||||||
MapProductSizeCount: req.MapProductSizeCount,
|
MapProductSizeCount: req.MapProductSizeCount,
|
||||||
|
@ -308,6 +325,7 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL
|
||||||
type getTagProductsReq struct {
|
type getTagProductsReq struct {
|
||||||
TagId int64
|
TagId int64
|
||||||
ProductList []gmodel.FsProduct
|
ProductList []gmodel.FsProduct
|
||||||
|
MapTagProp map[int64][]types.CoverDefaultItem
|
||||||
MapProductMinPrice map[int64]int64
|
MapProductMinPrice map[int64]int64
|
||||||
MapProductTemplate map[int64]struct{}
|
MapProductTemplate map[int64]struct{}
|
||||||
MapProductSizeCount map[int64]int64
|
MapProductSizeCount map[int64]int64
|
||||||
|
@ -344,17 +362,20 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
||||||
Sn: *productInfo.Sn,
|
Sn: *productInfo.Sn,
|
||||||
Title: *productInfo.Title,
|
Title: *productInfo.Title,
|
||||||
SizeNum: uint32(sizeNum),
|
SizeNum: uint32(sizeNum),
|
||||||
|
CoverDefault: []types.CoverDefaultItem{},
|
||||||
MinPrice: minPrice,
|
MinPrice: minPrice,
|
||||||
HaveOptionalFitting: haveOptionalFitting,
|
HaveOptionalFitting: haveOptionalFitting,
|
||||||
Recommended: *productInfo.IsRecommend > 0,
|
Recommended: *productInfo.IsRecommend > 0,
|
||||||
}
|
}
|
||||||
|
if _, ok = req.MapTagProp[productInfo.Id]; ok {
|
||||||
|
item.CoverDefault = req.MapTagProp[productInfo.Id]
|
||||||
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
r := image.ThousandFaceImageFormatReq{
|
r := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: 0,
|
IsThousandFace: 0,
|
||||||
Cover: *productInfo.Cover,
|
Cover: *productInfo.Cover,
|
||||||
CoverImg: *productInfo.CoverImg,
|
CoverImg: *productInfo.CoverImg,
|
||||||
CoverDefault: *productInfo.CoverImg,
|
|
||||||
ProductId: productInfo.Id,
|
ProductId: productInfo.Id,
|
||||||
UserId: req.User.Id,
|
UserId: req.User.Id,
|
||||||
}
|
}
|
||||||
|
@ -363,7 +384,6 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&r)
|
image.ThousandFaceImageFormat(&r)
|
||||||
item.Cover = r.Cover
|
item.Cover = r.Cover
|
||||||
item.CoverDefault = nil
|
|
||||||
//加入分类产品切片
|
//加入分类产品切片
|
||||||
productListRsp = append(productListRsp, item)
|
productListRsp = append(productListRsp, item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,6 +336,7 @@ type GetSizeByPidRsp struct {
|
||||||
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
||||||
ModelId int64 `json:"model_id"` //产品主模型id
|
ModelId int64 `json:"model_id"` //产品主模型id
|
||||||
IsPopular bool `json:"is_popular"` //是否受欢迎
|
IsPopular bool `json:"is_popular"` //是否受欢迎
|
||||||
|
MinPrice float64 `json:"min_price"` //最小价格
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTemplateByPidReq struct {
|
type GetTemplateByPidReq struct {
|
||||||
|
|
|
@ -381,6 +381,7 @@ type GetSizeByPidRsp {
|
||||||
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
||||||
ModelId int64 `json:"model_id"` //产品主模型id
|
ModelId int64 `json:"model_id"` //产品主模型id
|
||||||
IsPopular bool `json:"is_popular"` //是否受欢迎
|
IsPopular bool `json:"is_popular"` //是否受欢迎
|
||||||
|
MinPrice float64 `json:"min_price"` //最小价格
|
||||||
}
|
}
|
||||||
//获取产品模板列表
|
//获取产品模板列表
|
||||||
type GetTemplateByPidReq {
|
type GetTemplateByPidReq {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user