74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"fusenapi/model"
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/image"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
"strings"
|
|
|
|
"fusenapi/product/internal/svc"
|
|
"fusenapi/product/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetProductInfoLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductInfoLogic {
|
|
return &GetProductInfoLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
// 获取产品详情
|
|
func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response, err error) {
|
|
//校验前台登录情况
|
|
if loginInfo.UserId == 0 {
|
|
return &types.Response{Code: 402, Message: "please sign in"}, nil
|
|
}
|
|
req.Pid = strings.Trim(req.Pid, " ")
|
|
req.ClientNo = strings.Trim(req.ClientNo, " ")
|
|
if req.Size > 0 {
|
|
req.Size = image.GetCurrentSize(req.Size)
|
|
}
|
|
//获取产品详情
|
|
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
|
productInfo, err := productModel.FindOneBySn(l.ctx, req.Pid)
|
|
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
|
|
logx.Error(err)
|
|
return &types.Response{Code: 510, Message: "failed to get product info"}, nil
|
|
}
|
|
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
|
|
}
|