diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index 67e67138..45e5fa9e 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -41,32 +41,23 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo if !userinfo.IsUser() { return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in") } - if req.CurrentPage <= 0 { - req.CurrentPage = constants.DEFAULT_PAGE - } + currentPage := constants.DEFAULT_PAGE limit := 300 + if len(req.CartIds) > limit { + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "err param:request cart item is too much") + } //获取用户购物车列表 carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{ + Ids: req.CartIds, UserId: userinfo.UserId, Sort: "id DESC", - Page: req.CurrentPage, + Page: currentPage, Limit: limit, }) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts") } - if len(carts) == 0 { - return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCartsRsp{ - Meta: types.Meta{ - TotalCount: total, - PageCount: int64(math.Ceil(float64(total) / float64(limit))), - CurrentPage: req.CurrentPage, - PerPage: limit, - }, - CartList: nil, - }) - } var ( mapSize = make(map[int64]gmodel.FsProductSize) mapModel = make(map[int64]gmodel.FsProductModel3d) @@ -201,7 +192,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo Meta: types.Meta{ TotalCount: total, PageCount: int64(math.Ceil(float64(total) / float64(limit))), - CurrentPage: req.CurrentPage, + CurrentPage: currentPage, PerPage: limit, }, CartList: list, diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index b30ae342..ccda464c 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -30,7 +30,7 @@ type DeleteCartReq struct { } type GetCartsReq struct { - CurrentPage int `form:"current_page"` //当前页 + CartIds []int64 `json:"cart_id,optional"` //购物车ids可选 } type GetCartsRsp struct { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 5b73ac76..86314683 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -49,7 +49,7 @@ type DeleteCartReq { //获取购物车列表 type GetCartsReq { - CurrentPage int `form:"current_page"` //当前页 + CartIds []int64 `json:"cart_id,optional"` //购物车ids可选 } type GetCartsRsp { Meta Meta `json:"meta"` //分页信息