1
This commit is contained in:
parent
4b2cd6d1d8
commit
30cd2cc5d4
@ -101,7 +101,7 @@ func (this *ShopCartApi) List(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *ShopCartApi) Add(c *gin.Context) {
|
func (this *ShopCartApi) Add(c *gin.Context) {
|
||||||
//openId := c.MustGet("open_id").(string)
|
openId := c.MustGet("open_id").(string)
|
||||||
|
|
||||||
rspObj := &struct {
|
rspObj := &struct {
|
||||||
ErrCode int32 `json:"errcode"`
|
ErrCode int32 `json:"errcode"`
|
||||||
@ -122,6 +122,47 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
|||||||
return
|
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) {
|
func (this *ShopCartApi) Del(c *gin.Context) {
|
||||||
|
@ -66,7 +66,7 @@ type ShopCartGoods struct {
|
|||||||
ContractAddress string `json:"address"`
|
ContractAddress string `json:"address"`
|
||||||
TokenId string `json:"token_id"`
|
TokenId string `json:"token_id"`
|
||||||
SortIdx uint32 `json:"idx"`
|
SortIdx uint32 `json:"idx"`
|
||||||
CreateTime int32 `json:"addtime"`
|
AddTime int32 `json:"addtime"`
|
||||||
Flag int32
|
Flag int32
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,13 +117,13 @@ func (this* NftDto) GetKey() string {
|
|||||||
return key
|
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 {
|
for _, val := range this.Goods {
|
||||||
if val.NetId == netId && val.ContractAddress == contractAddress && val.TokenId == tokenId {
|
if val.NetId == netId && val.ContractAddress == contractAddress && val.TokenId == tokenId {
|
||||||
return true
|
return val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewShopCart() *ShopCart {
|
func NewShopCart() *ShopCart {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user