This commit is contained in:
aozhiwei 2024-06-20 15:49:48 +08:00
parent 9ba259d749
commit 998a5ed22e
3 changed files with 25 additions and 1 deletions

View File

@ -139,7 +139,6 @@ func (this *ShopCartApi) Add(c *gin.Context) {
cartDb := common.NewShopCart() cartDb := common.NewShopCart()
dirty := false dirty := false
if q5.DecodeJson(ds.GetByName("data"), cartDb) == nil { if q5.DecodeJson(ds.GetByName("data"), cartDb) == nil {
//newGoods := []*common.ShopCartGoods{}
for _, val := range reqJson.Tokens { for _, val := range reqJson.Tokens {
netId := q5.SafeToInt32(reqJson.NetId) netId := q5.SafeToInt32(reqJson.NetId)
contractAddress := val.ContractAddress contractAddress := val.ContractAddress
@ -165,6 +164,14 @@ func (this *ShopCartApi) Add(c *gin.Context) {
err1 = err err1 = err
if err == nil { if err == nil {
if ds.Next() { if ds.Next() {
cartDb.CurrSortIdx += 1
g := common.NewShopCartGoods()
g.NetId = netId
g.ContractAddress = contractAddress
g.TokenId = tokenId
g.SortIdx = cartDb.CurrSortIdx
g.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds())
q5.AppendSlice(&cartDb.Goods, g)
} else { } else {
} }
} }
@ -180,6 +187,7 @@ func (this *ShopCartApi) Add(c *gin.Context) {
} }
} }
if dirty { if dirty {
cartDb.DeleteExcessData()
this.save(openId, cartDb) this.save(openId, cartDb)
} }
c.JSON(200, rspObj) c.JSON(200, rspObj)

View File

@ -126,8 +126,20 @@ func (this* ShopCart) GetGoods(netId int32, contractAddress string, tokenId stri
return nil return nil
} }
func (this* ShopCart) DeleteExcessData() {
q5.Sort[ShopCartGoods](this.Goods,
func (a *ShopCartGoods, b *ShopCartGoods) bool{
return a.SortIdx < b.SortIdx
})
}
func NewShopCart() *ShopCart { func NewShopCart() *ShopCart {
p := new(ShopCart) p := new(ShopCart)
q5.NewSlice(&p.Goods, 0, 10) q5.NewSlice(&p.Goods, 0, 10)
return p return p
} }
func NewShopCartGoods() *ShopCartGoods {
p := new(ShopCartGoods)
return p
}

View File

@ -33,3 +33,7 @@ const (
CONTRACT_NAME_CFHero = "CFHero" CONTRACT_NAME_CFHero = "CFHero"
CONTRACT_NAME_GoldBrick = "GoldBrick" CONTRACT_NAME_GoldBrick = "GoldBrick"
) )
const (
SHOPCART_MAX_GOODS_NUM = 20
)