From 30cd2cc5d436beeb1bf5097ed2c7dd597114b363 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 20 Jun 2024 15:31:38 +0800 Subject: [PATCH] 1 --- .../marketserver/api/v1/shopcart/shopcart.go | 43 ++++++++++++++++++- server/marketserver/common/types.go | 8 ++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/server/marketserver/api/v1/shopcart/shopcart.go b/server/marketserver/api/v1/shopcart/shopcart.go index 20623699..c86211b8 100644 --- a/server/marketserver/api/v1/shopcart/shopcart.go +++ b/server/marketserver/api/v1/shopcart/shopcart.go @@ -101,7 +101,7 @@ func (this *ShopCartApi) List(c *gin.Context) { } func (this *ShopCartApi) Add(c *gin.Context) { - //openId := c.MustGet("open_id").(string) + openId := c.MustGet("open_id").(string) rspObj := &struct { ErrCode int32 `json:"errcode"` @@ -122,6 +122,47 @@ func (this *ShopCartApi) Add(c *gin.Context) { return } + f5.GetGoStyleDb().OrmSelectOne( + constant.BCNFT_DB, + "t_shopcart", + [][]string{ + {"open_id", openId}, + }, + func (err error, ds* f5.DataSet) { + if err != nil { + rspObj.ErrCode = 500 + rspObj.ErrMsg = "server internal error" + c.JSON(200, rspObj) + return + } + if ds.Next() { + cartDb := common.NewShopCart() + dirty := false + if q5.DecodeJson(ds.GetByName("data"), cartDb) == nil { + //newGoods := []*common.ShopCartGoods{} + for _, val := range reqJson.Tokens { + netId := q5.SafeToInt32(reqJson.NetId) + contractAddress := val.ContractAddress + tokenId := q5.SafeToString(val.TokenId) + p := cartDb.GetGoods(netId, contractAddress, tokenId) + if p != nil { + cartDb.CurrSortIdx += 1 + p.SortIdx = cartDb.CurrSortIdx + p.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds()) + dirty = true; + } else { + dirty = true; + } + } + } + if dirty { + this.save(openId, cartDb) + } + c.JSON(200, rspObj) + } else { + c.JSON(200, rspObj) + } + }) } func (this *ShopCartApi) Del(c *gin.Context) { diff --git a/server/marketserver/common/types.go b/server/marketserver/common/types.go index 812c4b21..4463d6f8 100644 --- a/server/marketserver/common/types.go +++ b/server/marketserver/common/types.go @@ -66,7 +66,7 @@ type ShopCartGoods struct { ContractAddress string `json:"address"` TokenId string `json:"token_id"` SortIdx uint32 `json:"idx"` - CreateTime int32 `json:"addtime"` + AddTime int32 `json:"addtime"` Flag int32 } @@ -117,13 +117,13 @@ func (this* NftDto) GetKey() string { return key } -func (this* ShopCart) Exists(netId int32, contractAddress string, tokenId string) bool { +func (this* ShopCart) GetGoods(netId int32, contractAddress string, tokenId string) *ShopCartGoods { for _, val := range this.Goods { if val.NetId == netId && val.ContractAddress == contractAddress && val.TokenId == tokenId { - return true + return val } } - return false + return nil } func NewShopCart() *ShopCart {