diff --git a/server/marketserver/api/v1/shopcart/shopcart.go b/server/marketserver/api/v1/shopcart/shopcart.go index 87752323..a10bca59 100644 --- a/server/marketserver/api/v1/shopcart/shopcart.go +++ b/server/marketserver/api/v1/shopcart/shopcart.go @@ -121,6 +121,12 @@ func (this *ShopCartApi) Add(c *gin.Context) { c.JSON(200, rspObj) return } + if len(reqJson.Tokens) > constant.SHOPCART_MAX_GOODS_NUM { + rspObj.ErrCode = 2 + rspObj.ErrMsg = "token len error" + c.JSON(200, rspObj) + return + } f5.GetGoStyleDb().OrmSelectOne( constant.BCNFT_DB, diff --git a/server/marketserver/common/types.go b/server/marketserver/common/types.go index e503567e..376866f6 100644 --- a/server/marketserver/common/types.go +++ b/server/marketserver/common/types.go @@ -4,6 +4,7 @@ import ( "q5" "f5" "fmt" + "main/constant" ) type NftHomeMeta struct { @@ -127,6 +128,19 @@ func (this* ShopCart) GetGoods(netId int32, contractAddress string, tokenId stri } func (this* ShopCart) DeleteExcessData() { + q5.Sort[ShopCartGoods](this.Goods, + func (a *ShopCartGoods, b *ShopCartGoods) bool{ + return a.SortIdx > b.SortIdx + }) + newGoods := []*ShopCartGoods{} + for _, val := range this.Goods { + if len(newGoods) < constant.SHOPCART_MAX_GOODS_NUM { + q5.AppendSlice(&newGoods, val) + } else { + break + } + } + this.Goods = newGoods q5.Sort[ShopCartGoods](this.Goods, func (a *ShopCartGoods, b *ShopCartGoods) bool{ return a.SortIdx < b.SortIdx