verify shopcart
This commit is contained in:
parent
61f3bd7c67
commit
e1ca58b8e8
@ -1,28 +1,28 @@
|
||||
package shopcart
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"jccommon"
|
||||
"main/constant"
|
||||
"main/common"
|
||||
"main/constant"
|
||||
. "main/global"
|
||||
"q5"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ShopCartApi struct {
|
||||
|
||||
}
|
||||
|
||||
func (this *ShopCartApi) List(c *gin.Context) {
|
||||
openId := c.MustGet("open_id").(string)
|
||||
rspObj := &struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
Data []struct{
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
Data []struct {
|
||||
Event interface{} `json:"event"`
|
||||
Nft interface{} `json:"nft"`
|
||||
Nft interface{} `json:"nft"`
|
||||
} `json:"data"`
|
||||
}{}
|
||||
q5.NewSlice(&rspObj.Data, 0, 10)
|
||||
@ -32,7 +32,7 @@ func (this *ShopCartApi) List(c *gin.Context) {
|
||||
[][]string{
|
||||
{"open_id", openId},
|
||||
},
|
||||
func (err error, ds* f5.DataSet) {
|
||||
func(err error, ds *f5.DataSet) {
|
||||
if err != nil {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "server internal error"
|
||||
@ -44,26 +44,47 @@ func (this *ShopCartApi) List(c *gin.Context) {
|
||||
cartDb := common.NewShopCart()
|
||||
if q5.DecodeJson(ds.GetByName("data"), cartDb) == nil {
|
||||
q5.Sort[common.ShopCartGoods](cartDb.Goods,
|
||||
func (a *common.ShopCartGoods, b *common.ShopCartGoods) bool{
|
||||
func(a *common.ShopCartGoods, b *common.ShopCartGoods) bool {
|
||||
return a.SortIdx < b.SortIdx
|
||||
})
|
||||
dirty := false
|
||||
newGoods := []*common.ShopCartGoods{}
|
||||
priceType := ""
|
||||
priceContractAddress := ""
|
||||
for _, val := range cartDb.Goods {
|
||||
var err1 error
|
||||
wherekv := [][]string{
|
||||
{"net_id", q5.ToString(val.NetId)},
|
||||
{"contract_address", q5.ToString(val.ContractAddress)},
|
||||
{"token_id", q5.ToString(val.TokenId)},
|
||||
{"status", jccommon.ORDER_STATUS_ACTIVE},
|
||||
}
|
||||
|
||||
if priceType != "" {
|
||||
wherekv = append(wherekv, []string{"src_price_item_type", priceType})
|
||||
}
|
||||
|
||||
if priceContractAddress != "" {
|
||||
wherekv = append(wherekv, []string{"src_price_contract_address", priceContractAddress})
|
||||
}
|
||||
|
||||
f5.GetGoStyleDb().OrmSelectOne(
|
||||
constant.BCNFT_DB,
|
||||
"t_order",
|
||||
[][]string{
|
||||
{"net_id", q5.ToString(val.NetId)},
|
||||
{"contract_address", q5.ToString(val.ContractAddress)},
|
||||
{"token_id", q5.ToString(val.TokenId)},
|
||||
{"status", jccommon.ORDER_STATUS_ACTIVE},
|
||||
},
|
||||
func (err error, ds* f5.DataSet) {
|
||||
wherekv,
|
||||
func(err error, ds *f5.DataSet) {
|
||||
err1 = err
|
||||
if err == nil {
|
||||
if ds.Next() {
|
||||
val.PriceType = ds.GetByName("src_price_item_type")
|
||||
val.PriceContractAddress = ds.GetByName("src_price_contract_address")
|
||||
val.OrderId = ds.GetByName("order_id")
|
||||
|
||||
if priceType == "" && priceContractAddress == "" {
|
||||
priceType = val.PriceType
|
||||
priceContractAddress = val.PriceContractAddress
|
||||
}
|
||||
|
||||
p := new(common.NftDto)
|
||||
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
|
||||
p.ContractAddress = ds.GetByName("contract_address")
|
||||
@ -73,9 +94,9 @@ func (this *ShopCartApi) List(c *gin.Context) {
|
||||
q5.AppendSlice(&nfts, p)
|
||||
q5.AppendSlice(&newGoods, val)
|
||||
} else {
|
||||
dirty = true
|
||||
val.Flag = 1
|
||||
}
|
||||
dirty = true
|
||||
}
|
||||
})
|
||||
if err1 != nil {
|
||||
@ -84,7 +105,7 @@ func (this *ShopCartApi) List(c *gin.Context) {
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
}//end for goods
|
||||
} //end for goods
|
||||
if dirty {
|
||||
cartDb.Goods = newGoods
|
||||
this.save(openId, cartDb)
|
||||
@ -108,15 +129,15 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
||||
accountAddress := c.MustGet("account_address").(string)
|
||||
|
||||
rspObj := &struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
}{}
|
||||
|
||||
reqJson := struct {
|
||||
NetId interface{} `json:"net_id"`
|
||||
NetId interface{} `json:"net_id"`
|
||||
Tokens []struct {
|
||||
TokenId interface{} `json:"token_id"`
|
||||
ContractAddress string `json:"contract_address"`
|
||||
TokenId interface{} `json:"token_id"`
|
||||
ContractAddress string `json:"contract_address"`
|
||||
} `json:"tokens"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
||||
@ -138,7 +159,7 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
||||
[][]string{
|
||||
{"open_id", openId},
|
||||
},
|
||||
func (err error, ds* f5.DataSet) {
|
||||
func(err error, ds *f5.DataSet) {
|
||||
if err != nil {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "server internal error"
|
||||
@ -151,16 +172,91 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
||||
if q5.DecodeJson(ds.GetByName("data"), cartDb) == nil {
|
||||
}
|
||||
}
|
||||
|
||||
priceType := ""
|
||||
priceContractAddress := ""
|
||||
for _, g := range cartDb.Goods {
|
||||
inreq := false
|
||||
for _, req := range reqJson.Tokens {
|
||||
netId := q5.SafeToInt32(reqJson.NetId)
|
||||
contractAddress := req.ContractAddress
|
||||
tokenId := q5.SafeToString(req.TokenId)
|
||||
if g.NetId == netId && g.ContractAddress == contractAddress && g.TokenId == tokenId {
|
||||
inreq = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !inreq {
|
||||
priceType = g.PriceType
|
||||
priceContractAddress = g.PriceContractAddress
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
var err1 error
|
||||
orderok := false
|
||||
f5.GetGoStyleDb().OrmSelectOne(
|
||||
constant.BCNFT_DB,
|
||||
"t_order",
|
||||
[][]string{
|
||||
{"net_id", q5.ToString(netId)},
|
||||
{"contract_address", contractAddress},
|
||||
{"token_id", tokenId},
|
||||
{"status", jccommon.ORDER_STATUS_ACTIVE},
|
||||
},
|
||||
func(err error, ds *f5.DataSet) {
|
||||
err1 = err
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !ds.Next() {
|
||||
return
|
||||
}
|
||||
if ds.GetByName("seller_address") == accountAddress {
|
||||
return
|
||||
}
|
||||
|
||||
p.OrderId = ds.GetByName("order_id")
|
||||
p.PriceType = ds.GetByName("src_price_item_type")
|
||||
p.PriceContractAddress = ds.GetByName("src_price_contract_address")
|
||||
if priceType == "" && priceContractAddress == "" {
|
||||
priceType = p.PriceType
|
||||
priceContractAddress = p.PriceContractAddress
|
||||
orderok = true
|
||||
} else if priceType != "" && priceContractAddress != "" &&
|
||||
priceType == p.PriceType && priceContractAddress == p.PriceContractAddress {
|
||||
orderok = true
|
||||
}
|
||||
})
|
||||
if err1 != nil {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "server internal error"
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
|
||||
if orderok {
|
||||
cartDb.CurrSortIdx += 1
|
||||
p.SortIdx = cartDb.CurrSortIdx
|
||||
p.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds())
|
||||
} else {
|
||||
j := 0
|
||||
for _, g := range cartDb.Goods {
|
||||
if g != p {
|
||||
cartDb.Goods[j] = g
|
||||
j++
|
||||
}
|
||||
}
|
||||
cartDb.Goods = cartDb.Goods[:j]
|
||||
}
|
||||
dirty = true
|
||||
} else {
|
||||
var err1 error
|
||||
f5.GetGoStyleDb().OrmSelectOne(
|
||||
@ -172,7 +268,7 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
||||
{"token_id", tokenId},
|
||||
{"status", jccommon.ORDER_STATUS_ACTIVE},
|
||||
},
|
||||
func (err error, ds* f5.DataSet) {
|
||||
func(err error, ds *f5.DataSet) {
|
||||
err1 = err
|
||||
if err == nil {
|
||||
if ds.Next() {
|
||||
@ -184,7 +280,21 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
||||
g.TokenId = tokenId
|
||||
g.SortIdx = cartDb.CurrSortIdx
|
||||
g.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds())
|
||||
q5.AppendSlice(&cartDb.Goods, g)
|
||||
g.OrderId = ds.GetByName("order_id")
|
||||
g.PriceType = ds.GetByName("src_price_item_type")
|
||||
g.PriceContractAddress = ds.GetByName("src_price_contract_address")
|
||||
orderok := false
|
||||
if priceType == "" && priceContractAddress == "" {
|
||||
orderok = true
|
||||
priceType = g.PriceType
|
||||
priceContractAddress = g.PriceContractAddress
|
||||
} else if priceType != "" && priceContractAddress != "" && priceType == g.PriceType && priceContractAddress == g.PriceContractAddress {
|
||||
orderok = true
|
||||
}
|
||||
|
||||
if orderok {
|
||||
q5.AppendSlice(&cartDb.Goods, g)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
@ -196,7 +306,7 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
||||
c.JSON(200, rspObj)
|
||||
return
|
||||
}
|
||||
dirty = true;
|
||||
dirty = true
|
||||
}
|
||||
}
|
||||
if dirty {
|
||||
@ -211,15 +321,15 @@ func (this *ShopCartApi) Del(c *gin.Context) {
|
||||
openId := c.MustGet("open_id").(string)
|
||||
|
||||
rspObj := &struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
}{}
|
||||
|
||||
reqJson := struct {
|
||||
NetId interface{} `json:"net_id"`
|
||||
NetId interface{} `json:"net_id"`
|
||||
Tokens []struct {
|
||||
TokenId interface{} `json:"token_id"`
|
||||
ContractAddress string `json:"contract_address"`
|
||||
TokenId interface{} `json:"token_id"`
|
||||
ContractAddress string `json:"contract_address"`
|
||||
} `json:"tokens"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
||||
@ -235,7 +345,7 @@ func (this *ShopCartApi) Del(c *gin.Context) {
|
||||
[][]string{
|
||||
{"open_id", openId},
|
||||
},
|
||||
func (err error, ds* f5.DataSet) {
|
||||
func(err error, ds *f5.DataSet) {
|
||||
if err != nil {
|
||||
rspObj.ErrCode = 500
|
||||
rspObj.ErrMsg = "server internal error"
|
||||
@ -276,8 +386,8 @@ func (this *ShopCartApi) Clear(c *gin.Context) {
|
||||
openId := c.MustGet("open_id").(string)
|
||||
|
||||
rspObj := &struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
}{}
|
||||
|
||||
cartDb := common.NewShopCart()
|
||||
@ -303,7 +413,7 @@ func (this *ShopCartApi) save(openId string, cartDb *common.ShopCart) {
|
||||
{"createtime", q5.ToString(nowTime)},
|
||||
{"modifytime", q5.ToString(nowTime)},
|
||||
},
|
||||
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||
func(err error, lastInsertId int64, rowsAffected int64) {
|
||||
|
||||
})
|
||||
}
|
||||
|
@ -8,33 +8,36 @@ import (
|
||||
)
|
||||
|
||||
type NftHomeMeta struct {
|
||||
Name string `json:"name"`
|
||||
Symbol string `json:"symbol"`
|
||||
Description string `json:"description"`
|
||||
Image string `json:"image"`
|
||||
Name string `json:"name"`
|
||||
Symbol string `json:"symbol"`
|
||||
Description string `json:"description"`
|
||||
Image string `json:"image"`
|
||||
ExternalLink string `json:"external_link"`
|
||||
}
|
||||
|
||||
type StreamPagination struct {
|
||||
NextCursor string `json:"next_cursor"`
|
||||
NextCursor string `json:"next_cursor"`
|
||||
PreviousCursor string `json:"previous_cursor"`
|
||||
Remaining int32 `json:"remaining"`
|
||||
Count int32 `json:"count"`
|
||||
TotalCount int32 `json:"total_count"`
|
||||
Remaining int32 `json:"remaining"`
|
||||
Count int32 `json:"count"`
|
||||
TotalCount int32 `json:"total_count"`
|
||||
}
|
||||
|
||||
type ShopCartGoods struct {
|
||||
NetId int32 `json:"net_id"`
|
||||
ContractAddress string `json:"address"`
|
||||
TokenId string `json:"token_id"`
|
||||
SortIdx uint32 `json:"idx"`
|
||||
AddTime int32 `json:"addtime"`
|
||||
Flag int32
|
||||
NetId int32 `json:"net_id"`
|
||||
ContractAddress string `json:"address"`
|
||||
TokenId string `json:"token_id"`
|
||||
SortIdx uint32 `json:"idx"`
|
||||
AddTime int32 `json:"addtime"`
|
||||
Flag int32
|
||||
PriceType string
|
||||
PriceContractAddress string
|
||||
OrderId string
|
||||
}
|
||||
|
||||
type ShopCart struct {
|
||||
CurrSortIdx uint32 `json:"curr_sort_idx"`
|
||||
Goods []*ShopCartGoods `json:"goods"`
|
||||
CurrSortIdx uint32 `json:"curr_sort_idx"`
|
||||
Goods []*ShopCartGoods `json:"goods"`
|
||||
}
|
||||
|
||||
type NftCache interface {
|
||||
@ -43,32 +46,32 @@ type NftCache interface {
|
||||
}
|
||||
|
||||
type NftDto struct {
|
||||
NetId int32
|
||||
NetId int32
|
||||
ContractAddress string
|
||||
TokenId string
|
||||
NftCache NftCache
|
||||
Price string
|
||||
Payload interface{}
|
||||
Param1 int64
|
||||
LockTime int32
|
||||
TokenId string
|
||||
NftCache NftCache
|
||||
Price string
|
||||
Payload interface{}
|
||||
Param1 int64
|
||||
LockTime int32
|
||||
}
|
||||
|
||||
type App interface {
|
||||
Run(func(), func())
|
||||
}
|
||||
|
||||
type RouterMgr interface{
|
||||
type RouterMgr interface {
|
||||
}
|
||||
|
||||
type TaskMgr interface{
|
||||
type TaskMgr interface {
|
||||
}
|
||||
|
||||
type CacheMgr interface{
|
||||
type CacheMgr interface {
|
||||
GetNfts([]*NftDto)
|
||||
GetIngameHero(string) (error, []interface{})
|
||||
}
|
||||
|
||||
func (this* StreamPagination) FillPage(page *f5.StreamPagination) {
|
||||
func (this *StreamPagination) FillPage(page *f5.StreamPagination) {
|
||||
if page.NextCursor != 0 {
|
||||
this.NextCursor = q5.ToString(page.NextCursor)
|
||||
}
|
||||
@ -80,12 +83,12 @@ func (this* StreamPagination) FillPage(page *f5.StreamPagination) {
|
||||
this.Remaining = page.Remaining
|
||||
}
|
||||
|
||||
func (this* NftDto) GetKey() string {
|
||||
func (this *NftDto) GetKey() string {
|
||||
key := fmt.Sprintf("%d_%s_%s", this.NetId, this.ContractAddress, this.TokenId)
|
||||
return key
|
||||
}
|
||||
|
||||
func (this* ShopCart) GetGoods(netId int32, contractAddress string, tokenId string) *ShopCartGoods {
|
||||
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 val
|
||||
@ -94,9 +97,9 @@ func (this* ShopCart) GetGoods(netId int32, contractAddress string, tokenId stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this* ShopCart) DeleteExcessData() {
|
||||
func (this *ShopCart) DeleteExcessData() {
|
||||
q5.Sort[ShopCartGoods](this.Goods,
|
||||
func (a *ShopCartGoods, b *ShopCartGoods) bool{
|
||||
func(a *ShopCartGoods, b *ShopCartGoods) bool {
|
||||
return a.SortIdx > b.SortIdx
|
||||
})
|
||||
newGoods := []*ShopCartGoods{}
|
||||
@ -109,7 +112,7 @@ func (this* ShopCart) DeleteExcessData() {
|
||||
}
|
||||
this.Goods = newGoods
|
||||
q5.Sort[ShopCartGoods](this.Goods,
|
||||
func (a *ShopCartGoods, b *ShopCartGoods) bool{
|
||||
func(a *ShopCartGoods, b *ShopCartGoods) bool {
|
||||
return a.SortIdx < b.SortIdx
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user