This commit is contained in:
laodaming 2023-11-07 12:17:35 +08:00
parent e90af652ca
commit 1ef3b816a7
2 changed files with 51 additions and 4 deletions

View File

@ -1,6 +1,9 @@
package logic
import (
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/service/repositories"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@ -34,13 +37,57 @@ func (l *GetCartNumLogic) GetCartNum(req *types.Request, userinfo *auth.UserInfo
if !userinfo.IsUser() {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
}
count, err := l.svcCtx.AllModels.FsShoppingCart.CountUserCart(l.ctx, userinfo.UserId)
currentPage := constants.DEFAULT_PAGE
limit := 1000
//获取用户购物车列表
carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
UserId: userinfo.UserId,
Sort: "id DESC",
Page: currentPage,
Limit: limit,
})
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get cart num")
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts")
}
var (
mapSize = make(map[int64]gmodel.FsProductSize)
mapModel = make(map[int64]gmodel.FsProductModel3d)
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
mapProduct = make(map[int64]gmodel.FsProduct)
mapResourceMetadata = make(map[string]interface{})
)
//获取相关信息
err = NewGetCartsLogic(l.ctx, l.svcCtx).GetRelationInfo(GetRelationInfoReq{
Carts: carts,
MapSize: mapSize,
MapModel: mapModel,
MapTemplate: mapTemplate,
MapProduct: mapProduct,
MapResourceMetadata: mapResourceMetadata,
})
if err != nil {
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
}
//定义map收集变更信息
mapCartChange := make(map[int64]string)
mapSnapshot := make(map[int64]gmodel.CartSnapshot)
//校验购物车数据是否变更
err = l.svcCtx.Repositories.NewShoppingCart.VerifyShoppingCartSnapshotDataChange(repositories.VerifyShoppingCartSnapshotDataChangeReq{
Carts: carts,
MapSize: mapSize,
MapModel: mapModel,
MapTemplate: mapTemplate,
MapCartChange: mapCartChange,
MapSnapshot: mapSnapshot,
MapProduct: mapProduct,
})
if err != nil {
logx.Error("VerifyShoppingCartSnapshotDataChange err:", err.Error())
return resp.SetStatusWithMessage(basic.CodeServiceErr, "system err:failed to check shopping cart change data")
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCartNumRsp{
TotalCount: count,
TotalCount: total - int64(len(mapCartChange)),
})
}

View File

@ -42,7 +42,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
}
currentPage := constants.DEFAULT_PAGE
limit := 300
limit := 1000
//获取用户购物车列表
var cartIds []int64
if req.CartId > 0 {