This commit is contained in:
laodaming 2023-06-05 17:38:37 +08:00
parent 52cc2a3d30
commit e6c88d83aa
2 changed files with 34 additions and 0 deletions

View File

@ -28,6 +28,7 @@ type (
Update(ctx context.Context, data *FsProductSize) error
Delete(ctx context.Context, id int64) error
CountByStatus(ctx context.Context, status int) (total int, err error)
FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error)
}
defaultFsProductSizeModel struct {
@ -95,6 +96,20 @@ func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status in
}
return
}
func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) {
query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, m.table)
switch sort {
case 1:
query = fmt.Sprintf("%s order by `sort` ASC", query)
case 2:
query = fmt.Sprintf("%s order by `sort` DESC", query)
}
err = m.conn.QueryRowsCtx(ctx, &resp, query, status)
if err != nil {
return nil, err
}
return
}
func (m *defaultFsProductSizeModel) tableName() string {
return m.table
}

View File

@ -3,6 +3,7 @@ package logic
import (
"context"
"errors"
"fmt"
"fusenapi/model"
"fusenapi/utils/auth"
"fusenapi/utils/image"
@ -50,5 +51,23 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login
if productInfo == nil {
return &types.Response{Code: 510, Message: "product not found"}, nil
}
//获取产品标签
tagModel := model.NewFsTagsModel(l.svcCtx.MysqlConn)
tagInfo, err := tagModel.FindOne(l.ctx, productInfo.Type)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get product tag"}, nil
}
//获取产品尺寸列表
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
productSizeList, err := productSizeModel.FindAllByStatus(l.ctx, 1, 1)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get product size list"}, nil
}
sizeIds := make([]string, 0, len(productSizeList))
for _, v := range productSizeList {
sizeIds = append(sizeIds, fmt.Sprintf("%d", v.Id))
}
return
}