verify shopcart
This commit is contained in:
parent
61f3bd7c67
commit
e1ca58b8e8
@ -1,18 +1,18 @@
|
|||||||
package shopcart
|
package shopcart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"q5"
|
|
||||||
"f5"
|
"f5"
|
||||||
"jccommon"
|
"jccommon"
|
||||||
"main/constant"
|
|
||||||
"main/common"
|
"main/common"
|
||||||
|
"main/constant"
|
||||||
. "main/global"
|
. "main/global"
|
||||||
|
"q5"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ShopCartApi struct {
|
type ShopCartApi struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ShopCartApi) List(c *gin.Context) {
|
func (this *ShopCartApi) List(c *gin.Context) {
|
||||||
@ -49,21 +49,42 @@ func (this *ShopCartApi) List(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
dirty := false
|
dirty := false
|
||||||
newGoods := []*common.ShopCartGoods{}
|
newGoods := []*common.ShopCartGoods{}
|
||||||
|
priceType := ""
|
||||||
|
priceContractAddress := ""
|
||||||
for _, val := range cartDb.Goods {
|
for _, val := range cartDb.Goods {
|
||||||
var err1 error
|
var err1 error
|
||||||
f5.GetGoStyleDb().OrmSelectOne(
|
wherekv := [][]string{
|
||||||
constant.BCNFT_DB,
|
|
||||||
"t_order",
|
|
||||||
[][]string{
|
|
||||||
{"net_id", q5.ToString(val.NetId)},
|
{"net_id", q5.ToString(val.NetId)},
|
||||||
{"contract_address", q5.ToString(val.ContractAddress)},
|
{"contract_address", q5.ToString(val.ContractAddress)},
|
||||||
{"token_id", q5.ToString(val.TokenId)},
|
{"token_id", q5.ToString(val.TokenId)},
|
||||||
{"status", jccommon.ORDER_STATUS_ACTIVE},
|
{"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",
|
||||||
|
wherekv,
|
||||||
func(err error, ds *f5.DataSet) {
|
func(err error, ds *f5.DataSet) {
|
||||||
err1 = err
|
err1 = err
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if ds.Next() {
|
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 := new(common.NftDto)
|
||||||
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
|
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
|
||||||
p.ContractAddress = ds.GetByName("contract_address")
|
p.ContractAddress = ds.GetByName("contract_address")
|
||||||
@ -73,9 +94,9 @@ func (this *ShopCartApi) List(c *gin.Context) {
|
|||||||
q5.AppendSlice(&nfts, p)
|
q5.AppendSlice(&nfts, p)
|
||||||
q5.AppendSlice(&newGoods, val)
|
q5.AppendSlice(&newGoods, val)
|
||||||
} else {
|
} else {
|
||||||
dirty = true
|
|
||||||
val.Flag = 1
|
val.Flag = 1
|
||||||
}
|
}
|
||||||
|
dirty = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
@ -151,16 +172,91 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
|||||||
if q5.DecodeJson(ds.GetByName("data"), cartDb) == nil {
|
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 {
|
for _, val := range reqJson.Tokens {
|
||||||
netId := q5.SafeToInt32(reqJson.NetId)
|
netId := q5.SafeToInt32(reqJson.NetId)
|
||||||
contractAddress := val.ContractAddress
|
contractAddress := val.ContractAddress
|
||||||
tokenId := q5.SafeToString(val.TokenId)
|
tokenId := q5.SafeToString(val.TokenId)
|
||||||
p := cartDb.GetGoods(netId, contractAddress, tokenId)
|
p := cartDb.GetGoods(netId, contractAddress, tokenId)
|
||||||
if p != nil {
|
if p != nil {
|
||||||
|
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
|
cartDb.CurrSortIdx += 1
|
||||||
p.SortIdx = cartDb.CurrSortIdx
|
p.SortIdx = cartDb.CurrSortIdx
|
||||||
p.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds())
|
p.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds())
|
||||||
dirty = true;
|
} else {
|
||||||
|
j := 0
|
||||||
|
for _, g := range cartDb.Goods {
|
||||||
|
if g != p {
|
||||||
|
cartDb.Goods[j] = g
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cartDb.Goods = cartDb.Goods[:j]
|
||||||
|
}
|
||||||
|
dirty = true
|
||||||
} else {
|
} else {
|
||||||
var err1 error
|
var err1 error
|
||||||
f5.GetGoStyleDb().OrmSelectOne(
|
f5.GetGoStyleDb().OrmSelectOne(
|
||||||
@ -184,8 +280,22 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
|||||||
g.TokenId = tokenId
|
g.TokenId = tokenId
|
||||||
g.SortIdx = cartDb.CurrSortIdx
|
g.SortIdx = cartDb.CurrSortIdx
|
||||||
g.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds())
|
g.AddTime = q5.ToInt32(f5.GetApp().GetRealSeconds())
|
||||||
|
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)
|
q5.AppendSlice(&cartDb.Goods, g)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +306,7 @@ func (this *ShopCartApi) Add(c *gin.Context) {
|
|||||||
c.JSON(200, rspObj)
|
c.JSON(200, rspObj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if dirty {
|
if dirty {
|
||||||
|
@ -30,6 +30,9 @@ type ShopCartGoods struct {
|
|||||||
SortIdx uint32 `json:"idx"`
|
SortIdx uint32 `json:"idx"`
|
||||||
AddTime int32 `json:"addtime"`
|
AddTime int32 `json:"addtime"`
|
||||||
Flag int32
|
Flag int32
|
||||||
|
PriceType string
|
||||||
|
PriceContractAddress string
|
||||||
|
OrderId string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShopCart struct {
|
type ShopCart struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user