fix
This commit is contained in:
parent
6b96a3ecbe
commit
852fca2afa
|
@ -24,12 +24,18 @@ func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (s *FsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int64, err error) {
|
|
||||||
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`status` = ? limit 1", status).Count(&total).Error
|
type CountProductSizeByStatusRsp struct {
|
||||||
if err != nil {
|
ProductId int64 `json:"product_id"`
|
||||||
return 0, err
|
Num int64 `json:"num"`
|
||||||
}
|
}
|
||||||
return
|
func (s *FsProductSizeModel) GetGroupProductSizeByStatus(ctx context.Context,productIds []int64, status int) (resp []CountProductSizeByStatusRsp, err error) {
|
||||||
|
err = s.db.WithContext(ctx).Model(&FsProductSize{}).
|
||||||
|
Select("product_id,count(*) as num").
|
||||||
|
Where("`product_id` in (?) and `status` = ?",productIds ,status).
|
||||||
|
Group("product_id").
|
||||||
|
Find(&resp).Error
|
||||||
|
return resp,err
|
||||||
}
|
}
|
||||||
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
|
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
|
||||||
if len(productIds) == 0 {
|
if len(productIds) == 0 {
|
||||||
|
|
|
@ -124,11 +124,15 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
||||||
}
|
}
|
||||||
//获取产品尺寸数量
|
//获取产品尺寸数量
|
||||||
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||||
productSizeCount, err := productSizeModel.CountByStatus(l.ctx, 1)
|
productSizeCountList, err := productSizeModel.GetGroupProductSizeByStatus(l.ctx, productIds,1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err")
|
||||||
}
|
}
|
||||||
|
mapProductSizeCount := make(map[int64]int64)
|
||||||
|
for _,v := range productSizeCountList{
|
||||||
|
mapProductSizeCount[v.ProductId] = v.Num
|
||||||
|
}
|
||||||
//拼接返回
|
//拼接返回
|
||||||
itemList := make([]types.Items, 0, productLen)
|
itemList := make([]types.Items, 0, productLen)
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
|
@ -138,6 +142,10 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
||||||
if !ok || !tmpOk {
|
if !ok || !tmpOk {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
sizeNum := int64(0)
|
||||||
|
if mapSizeNum,ok := mapProductSizeCount[v.Id];ok{
|
||||||
|
sizeNum = mapSizeNum
|
||||||
|
}
|
||||||
item := types.Items{
|
item := types.Items{
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
Sn: *v.Sn,
|
Sn: *v.Sn,
|
||||||
|
@ -145,7 +153,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
||||||
Intro: *v.Intro,
|
Intro: *v.Intro,
|
||||||
IsEnv: *v.IsProtection,
|
IsEnv: *v.IsProtection,
|
||||||
IsMicro: *v.IsMicrowave,
|
IsMicro: *v.IsMicrowave,
|
||||||
SizeNum: uint32(productSizeCount),
|
SizeNum: uint32(sizeNum),
|
||||||
MiniPrice: format.CentoDollar(minPrice),
|
MiniPrice: format.CentoDollar(minPrice),
|
||||||
}
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
|
|
Loading…
Reference in New Issue
Block a user