This commit is contained in:
laodaming 2023-09-22 17:04:01 +08:00
parent bea1fd230a
commit 2054b9ec97
3 changed files with 9 additions and 18 deletions

View File

@ -41,32 +41,23 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
if !userinfo.IsUser() { if !userinfo.IsUser() {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in") return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
} }
if req.CurrentPage <= 0 { currentPage := constants.DEFAULT_PAGE
req.CurrentPage = constants.DEFAULT_PAGE
}
limit := 300 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{ carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
Ids: req.CartIds,
UserId: userinfo.UserId, UserId: userinfo.UserId,
Sort: "id DESC", Sort: "id DESC",
Page: req.CurrentPage, Page: currentPage,
Limit: limit, Limit: limit,
}) })
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts") 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 ( var (
mapSize = make(map[int64]gmodel.FsProductSize) mapSize = make(map[int64]gmodel.FsProductSize)
mapModel = make(map[int64]gmodel.FsProductModel3d) mapModel = make(map[int64]gmodel.FsProductModel3d)
@ -201,7 +192,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
Meta: types.Meta{ Meta: types.Meta{
TotalCount: total, TotalCount: total,
PageCount: int64(math.Ceil(float64(total) / float64(limit))), PageCount: int64(math.Ceil(float64(total) / float64(limit))),
CurrentPage: req.CurrentPage, CurrentPage: currentPage,
PerPage: limit, PerPage: limit,
}, },
CartList: list, CartList: list,

View File

@ -30,7 +30,7 @@ type DeleteCartReq struct {
} }
type GetCartsReq struct { type GetCartsReq struct {
CurrentPage int `form:"current_page"` //当前页 CartIds []int64 `json:"cart_id,optional"` //购物车ids可选
} }
type GetCartsRsp struct { type GetCartsRsp struct {

View File

@ -49,7 +49,7 @@ type DeleteCartReq {
//获取购物车列表 //获取购物车列表
type GetCartsReq { type GetCartsReq {
CurrentPage int `form:"current_page"` //当前页 CartIds []int64 `json:"cart_id,optional"` //购物车ids可选
} }
type GetCartsRsp { type GetCartsRsp {
Meta Meta `json:"meta"` //分页信息 Meta Meta `json:"meta"` //分页信息