From 19f988eccd9fc203d596dda20f039806f3e1ad80 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 5 Jun 2023 12:21:15 +0800 Subject: [PATCH] fix --- product.api | 4 ++-- .../internal/handler/getproductinfohandler.go | 1 + .../internal/handler/getproductlisthandler.go | 1 + product/internal/logic/getproductinfologic.go | 21 +++++++++++++++++++ product/internal/logic/getproductlistlogic.go | 12 +++++------ product/internal/types/types.go | 4 ++-- utils/format/price.go | 2 +- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/product.api b/product.api index d5bc11c8..200e2c57 100644 --- a/product.api +++ b/product.api @@ -57,8 +57,8 @@ type Items { Cover string `json:"cover"` Intro string `json:"intro"` CoverImg string `json:"cover_img"` - IsEnv uint32 `json:"isEnv"` - IsMicro uint32 `json:"isMicro"` + IsEnv int64 `json:"isEnv"` + IsMicro int64 `json:"isMicro"` SizeNum uint32 `json:"sizeNum"` MiniPrice float64 `json:"miniPrice"` CoverDefault string `json:"coverDefault"` diff --git a/product/internal/handler/getproductinfohandler.go b/product/internal/handler/getproductinfohandler.go index 5bcbae0a..2a354242 100644 --- a/product/internal/handler/getproductinfohandler.go +++ b/product/internal/handler/getproductinfohandler.go @@ -10,6 +10,7 @@ import ( "github.com/zeromicro/go-zero/rest/httpx" ) +// 获取产品详情 func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { //检测登录权限 diff --git a/product/internal/handler/getproductlisthandler.go b/product/internal/handler/getproductlisthandler.go index 44245ea1..3777c949 100644 --- a/product/internal/handler/getproductlisthandler.go +++ b/product/internal/handler/getproductlisthandler.go @@ -10,6 +10,7 @@ import ( "github.com/zeromicro/go-zero/rest/httpx" ) +// 获取产品列表 func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { //检测登录权限 diff --git a/product/internal/logic/getproductinfologic.go b/product/internal/logic/getproductinfologic.go index ef8a4c67..dd6e4629 100644 --- a/product/internal/logic/getproductinfologic.go +++ b/product/internal/logic/getproductinfologic.go @@ -2,7 +2,12 @@ package logic import ( "context" + "errors" + "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" @@ -24,10 +29,26 @@ func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge } } +// 获取产品详情 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 + } return } diff --git a/product/internal/logic/getproductlistlogic.go b/product/internal/logic/getproductlistlogic.go index 9bb2081d..a8885dd7 100644 --- a/product/internal/logic/getproductlistlogic.go +++ b/product/internal/logic/getproductlistlogic.go @@ -12,7 +12,7 @@ import ( "fusenapi/utils/auth" "fusenapi/utils/format" "fusenapi/utils/image" - "github.com/zeromicro/go-zero/core/stores/sqlx" + "github.com/zeromicro/go-zero/core/stores/sqlc" "sort" "strings" "time" @@ -59,7 +59,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login //查询用户信息 userModel := model.NewFsUserModel(l.svcCtx.MysqlConn) userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId) - if err != nil && !errors.Is(err, sqlx.ErrNotFound) { + if err != nil && !errors.Is(err, sqlc.ErrNotFound) { logx.Error(err) return &types.Response{Code: 510, Message: "get user info err"}, nil } @@ -118,7 +118,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login //获取分类 tagsModel := model.NewFsTagsModel(l.svcCtx.MysqlConn) tagInfo, err := tagsModel.FindOne(l.ctx, req.Cid) - if err != nil && !errors.Is(err, sqlx.ErrNotFound) { + if err != nil && !errors.Is(err, sqlc.ErrNotFound) { logx.Error(err) return &types.Response{Code: 510, Message: "get classification err "}, nil } @@ -145,10 +145,10 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login Cover: v.Cover, Intro: v.Intro.String, CoverImg: v.CoverImg, - IsEnv: 1, - IsMicro: 1, + IsEnv: v.IsProtection, + IsMicro: v.IsMicrowave, SizeNum: 1, - MiniPrice: format.FentoDollar(minPrice), + MiniPrice: format.CentoDollar(minPrice), } if req.Size > 0 { coverSlice := strings.Split(v.Cover, ".") diff --git a/product/internal/types/types.go b/product/internal/types/types.go index 6a7d556f..f5c1cc76 100644 --- a/product/internal/types/types.go +++ b/product/internal/types/types.go @@ -45,8 +45,8 @@ type Items struct { Cover string `json:"cover"` Intro string `json:"intro"` CoverImg string `json:"cover_img"` - IsEnv uint32 `json:"isEnv"` - IsMicro uint32 `json:"isMicro"` + IsEnv int64 `json:"isEnv"` + IsMicro int64 `json:"isMicro"` SizeNum uint32 `json:"sizeNum"` MiniPrice float64 `json:"miniPrice"` CoverDefault string `json:"coverDefault"` diff --git a/utils/format/price.go b/utils/format/price.go index 4a6e455a..8c7ee70a 100644 --- a/utils/format/price.go +++ b/utils/format/price.go @@ -6,7 +6,7 @@ import ( ) // 美分转美元 -func FentoDollar(price int64) float64 { +func CentoDollar(price int64) float64 { str := fmt.Sprintf("%.2f", float64(price)/float64(100)) dollar, _ := strconv.ParseFloat(str, 64) return dollar