1
This commit is contained in:
parent
da659a7d03
commit
78e8aed3cd
@ -126,3 +126,52 @@ func GetNoOpenGoldBullionItemIdByTokenId(tokenId string, itemId *int32) bool {
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
func NftExists(netId int32, contractAddress string, tokenId string) bool {
|
||||
result := false
|
||||
f5.GetGoStyleDb().OrmSelectOne(
|
||||
constant.BCNFT_DB,
|
||||
"t_nft",
|
||||
[][]string {
|
||||
{"net_id", q5.ToString(netId)},
|
||||
{"token_id", tokenId},
|
||||
{"contract_address", contractAddress},
|
||||
},
|
||||
func (err error, ds *f5.DataSet) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if ds.Next() {
|
||||
result = true
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
func NftUpdateLock(netId int32, contractAddress string, tokenId string,
|
||||
lockIdx int64, lockAddress string) bool {
|
||||
result := false
|
||||
f5.GetGoStyleDb().UpsertEx(
|
||||
constant.BCNFT_DB,
|
||||
"t_nft",
|
||||
[][]string {
|
||||
{"net_id", q5.ToString(netId)},
|
||||
{"token_id", tokenId},
|
||||
{"contract_address", contractAddress},
|
||||
},
|
||||
[][]string {
|
||||
{"last_lock_idx", q5.ToString(lockIdx)},
|
||||
{"last_lock_address", lockAddress},
|
||||
},
|
||||
[][]string {},
|
||||
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
result = true
|
||||
},
|
||||
func (ds *f5.DataSet) bool {
|
||||
return lockIdx > q5.ToInt64(ds.GetByName("last_lock_idx"))
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
@ -4,11 +4,19 @@ import (
|
||||
"q5"
|
||||
"f5"
|
||||
"fmt"
|
||||
"jccommon"
|
||||
"strings"
|
||||
"main/constant"
|
||||
"main/service"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
type lockReturnValues struct {
|
||||
Nft string `json:"nft"`
|
||||
Sender string `json:"sender"`
|
||||
To string `json:"to"`
|
||||
TokenIds []string `json:"tokenIds"`
|
||||
}
|
||||
|
||||
type nftLock struct {
|
||||
|
||||
}
|
||||
@ -26,17 +34,16 @@ func (this* nftLock) process() {
|
||||
"nftLock",
|
||||
"t_nft_lock_event",
|
||||
func () int64 {
|
||||
return 60 + q5.ToInt64(rand.Intn(3))
|
||||
return 3
|
||||
},
|
||||
func (lastIdx int64) string {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT * FROM t_nft_lock_event idx > %d AND status = ? LIMIT 100`,
|
||||
SELECT * FROM t_nft_lock_event WHERE idx > %d AND nft_sync_status = 0 LIMIT 100`,
|
||||
lastIdx,
|
||||
)
|
||||
return sql
|
||||
},
|
||||
[]string{
|
||||
jccommon.ORDER_STATUS_ACTIVE,
|
||||
},
|
||||
func () int64 {
|
||||
return 3
|
||||
@ -44,9 +51,25 @@ SELECT * FROM t_nft_lock_event idx > %d AND status = ? LIMIT 100`,
|
||||
func () int64 {
|
||||
return 60 + q5.ToInt64(rand.Intn(3))
|
||||
},
|
||||
this.repairPrice)
|
||||
this.repair)
|
||||
}
|
||||
|
||||
func (this* nftLock) repairPrice(ds *f5.DataSet) bool {
|
||||
func (this* nftLock) repair(ds *f5.DataSet) bool {
|
||||
nftSyncStatus := q5.ToInt32(ds.GetByName("nft_sync_status"))
|
||||
netId := q5.ToInt32(ds.GetByName("net_id"))
|
||||
idx := q5.ToInt64(ds.GetByName("idx"))
|
||||
lockTo := ds.GetByName("lock_to")
|
||||
if nftSyncStatus == 0 {
|
||||
p := new(lockReturnValues)
|
||||
if q5.DecodeJson(ds.GetByName("return_values"), p) == nil {
|
||||
for _, val := range p.TokenIds {
|
||||
contractAddress := strings.ToLower(p.Nft)
|
||||
tokenId := val
|
||||
if service.NftExists(netId, contractAddress, tokenId) {
|
||||
service.NftUpdateLock(netId, contractAddress, tokenId, idx, lockTo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ type refreshMeta struct {
|
||||
|
||||
func (this* refreshMeta) init() {
|
||||
this.batchNfts = []*nftInfo{}
|
||||
go this.process()
|
||||
//go this.process()
|
||||
}
|
||||
|
||||
func (this* refreshMeta) unInit() {
|
||||
|
@ -18,12 +18,12 @@ type taskMgr struct {
|
||||
sysMail
|
||||
repairOrder
|
||||
refreshMeta
|
||||
nftLock
|
||||
}
|
||||
|
||||
func (this *taskMgr) Init() {
|
||||
this.refreshMeta.init()
|
||||
return
|
||||
if f5.IsOnlineEnv() {
|
||||
this.nftLock.init()
|
||||
this.refreshMeta.init()
|
||||
return
|
||||
}
|
||||
@ -36,15 +36,16 @@ func (this *taskMgr) Init() {
|
||||
this.sysMail.init()
|
||||
this.repairOrder.init()
|
||||
this.refreshMeta.init()
|
||||
this.nftLock.init()
|
||||
}
|
||||
|
||||
func (this *taskMgr) UnInit() {
|
||||
this.refreshMeta.unInit()
|
||||
return
|
||||
if f5.IsOnlineEnv() {
|
||||
this.nftLock.unInit()
|
||||
this.refreshMeta.unInit()
|
||||
return
|
||||
}
|
||||
this.nftLock.unInit()
|
||||
this.refreshMeta.unInit()
|
||||
this.repairOrder.unInit()
|
||||
this.sysMail.unInit()
|
||||
|
@ -25,7 +25,7 @@ type MarketApi struct {
|
||||
|
||||
}
|
||||
|
||||
func (this *MarketApi) ProductList(c *gin.Context) {
|
||||
func (this *MarketApi) ProductList1(c *gin.Context) {
|
||||
openId := c.MustGet("open_id").(string)
|
||||
cartDb := service.GetShopCartByOpenId(openId)
|
||||
netId := q5.ToInt64(c.Param("net_id"))
|
||||
@ -56,7 +56,7 @@ func (this *MarketApi) ProductList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 20)
|
||||
pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 200)
|
||||
cursor := q5.SafeToInt64(reqJson.Cursor)
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT * FROM t_order A WHERE idx > %d AND net_id = %d AND status="%s"
|
||||
@ -206,6 +206,187 @@ SELECT * FROM t_order A WHERE idx > %d AND net_id = %d
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *MarketApi) ProductList(c *gin.Context) {
|
||||
openId := c.MustGet("open_id").(string)
|
||||
cartDb := service.GetShopCartByOpenId(openId)
|
||||
netId := q5.ToInt64(c.Param("net_id"))
|
||||
reqJson := struct {
|
||||
PageSize interface{} `json:"page_size"`
|
||||
Cursor interface{} `json:"cursor"`
|
||||
Search struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"search"`
|
||||
Filter struct {
|
||||
PriceMin interface{} `json:"price_min"`
|
||||
PriceMax interface{} `json:"price_max"`
|
||||
ItemIds []interface{} `json:"item_ids"`
|
||||
HeroRanks []interface{} `json:"hero_ranks"`
|
||||
} `json:"filter"`
|
||||
Sort struct {
|
||||
Fields [] struct {
|
||||
Name string `json:"name"`
|
||||
Type interface{} `json:"type"`
|
||||
} `json:"fields"`
|
||||
} `json:"sort"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 200)
|
||||
cursor := q5.SafeToInt64(reqJson.Cursor)
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT * FROM t_order A WHERE net_id = %d AND status="%s"
|
||||
`,
|
||||
netId, jccommon.ORDER_STATUS_ACTIVE)
|
||||
/*
|
||||
if f5.IsTestEnv() {
|
||||
sql = fmt.Sprintf(`
|
||||
SELECT * FROM t_order A WHERE idx > %d AND net_id = %d
|
||||
`,
|
||||
cursor, netId)
|
||||
}*/
|
||||
|
||||
orderBy := ""
|
||||
{
|
||||
for _, val := range reqJson.Sort.Fields {
|
||||
if val.Name == "price" && orderBy == "" {
|
||||
t := q5.SafeToInt32(val.Type)
|
||||
if t < 0 {
|
||||
orderBy = " ORDER BY price_len DESC, price DESC"
|
||||
} else {
|
||||
orderBy = " ORDER BY price_len ASC, price ASC"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subFilters := []f5.DbQueryFilter{}
|
||||
{
|
||||
priceMin := q5.SafeToString(reqJson.Filter.PriceMin)
|
||||
priceMax := q5.SafeToString(reqJson.Filter.PriceMax)
|
||||
if !q5.IsPureNumber(priceMin) {
|
||||
priceMin = ""
|
||||
}
|
||||
if !q5.IsPureNumber(priceMax) {
|
||||
priceMax = ""
|
||||
}
|
||||
if priceMin != "" && priceMax != "" {
|
||||
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(
|
||||
fmt.Sprintf(`LENGTH(price) >= LENGTH('%s') AND price >= '%s' AND
|
||||
LENGTH(price) <= LENGTH('%s') AND price <= '%s'`,
|
||||
priceMin,
|
||||
priceMin,
|
||||
priceMax,
|
||||
priceMax)).And())
|
||||
} else if priceMin != "" {
|
||||
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(
|
||||
fmt.Sprintf(`LENGTH(price) >= LENGTH('%s') AND price >= '%s'`,
|
||||
priceMin,
|
||||
priceMin)).And())
|
||||
} else if priceMax != "" {
|
||||
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(
|
||||
fmt.Sprintf(`LENGTH(price) <= LENGTH('%s') AND price <= '%s'`,
|
||||
priceMax,
|
||||
priceMax)).And())
|
||||
}
|
||||
}
|
||||
{
|
||||
itemIds := map[int32]int32{}
|
||||
if reqJson.Search.Name != "" {
|
||||
mt.Table.Item.Search(reqJson.Search.Name, itemIds)
|
||||
}
|
||||
for _, val := range(reqJson.Filter.ItemIds) {
|
||||
itemId := q5.SafeToInt32(val)
|
||||
itemIds[itemId] = 1
|
||||
}
|
||||
if len(itemIds) > 0 {
|
||||
inSub := `item_id IN (`
|
||||
i := 0
|
||||
for key, _ := range(itemIds) {
|
||||
if i == 0 {
|
||||
inSub += q5.ToString(key)
|
||||
} else {
|
||||
inSub += "," + q5.ToString(key)
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
inSub += ")"
|
||||
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
|
||||
}
|
||||
}
|
||||
{
|
||||
heroRanks := map[int32]int32{}
|
||||
for _, val := range(reqJson.Filter.HeroRanks) {
|
||||
rank := q5.SafeToInt32(val)
|
||||
heroRanks[rank] = 1
|
||||
}
|
||||
if len(heroRanks) > 0 {
|
||||
inSub := `hero_quality IN (`
|
||||
i := 0
|
||||
for key, _ := range(heroRanks) {
|
||||
if i == 0 {
|
||||
inSub += q5.ToString(key)
|
||||
} else {
|
||||
inSub += "," + q5.ToString(key)
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
inSub += ")"
|
||||
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
|
||||
}
|
||||
}
|
||||
|
||||
rspObj := struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
Page common.StreamPagination `json:"page"`
|
||||
Rows []struct{
|
||||
Event interface{} `json:"event"`
|
||||
Nft interface{} `json:"nft"`
|
||||
InShopCart int32 `json:"in_shopcart"`
|
||||
} `json:"rows"`
|
||||
}{}
|
||||
q5.NewSlice(&rspObj.Rows, 0, 10)
|
||||
nfts := []*common.NftDto{}
|
||||
f5.GetGoStyleDb().StreamPageQuery1(
|
||||
constant.BCNFT_DB,
|
||||
pageSize,
|
||||
cursor,
|
||||
sql,
|
||||
[]string{
|
||||
},
|
||||
f5.GetDbFilter().Comp(subFilters...),
|
||||
orderBy,
|
||||
func (err error, pagination *f5.StreamPagination) {
|
||||
rspObj.Page.FillPage(pagination)
|
||||
},
|
||||
func (ds *f5.DataSet) {
|
||||
p := new(common.NftDto)
|
||||
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
|
||||
p.ContractAddress = ds.GetByName("contract_address")
|
||||
p.TokenId = ds.GetByName("token_id")
|
||||
p.Payload = map[string]interface{}{}
|
||||
q5.DecodeJson(ds.GetByName("event_data"), &p.Payload)
|
||||
q5.AppendSlice(&nfts, p)
|
||||
})
|
||||
GetCacheMgr().GetNfts(nfts)
|
||||
{
|
||||
for _, val := range nfts {
|
||||
p := q5.NewSliceElement(&rspObj.Rows)
|
||||
p.Event = val.Payload
|
||||
p.Nft = val.NftCache.GetJsonData()
|
||||
if cartDb != nil && cartDb.GetGoods(val.NetId, val.ContractAddress, val.TokenId) != nil{
|
||||
p.InShopCart = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *MarketApi) TransactionHistory(c *gin.Context) {
|
||||
pageSize := q5.AdjustRangeValue(q5.ToInt32(c.DefaultQuery("page_size", "")), 1, 20)
|
||||
cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
|
||||
|
@ -20,6 +20,7 @@ type StreamPagination struct {
|
||||
PreviousCursor string `json:"previous_cursor"`
|
||||
Remaining int32 `json:"remaining"`
|
||||
Count int32 `json:"count"`
|
||||
TotalCount int32 `json:"total_count"`
|
||||
}
|
||||
|
||||
type ShopCartGoods struct {
|
||||
@ -72,6 +73,7 @@ func (this* StreamPagination) FillPage(page *f5.StreamPagination) {
|
||||
this.PreviousCursor = q5.ToString(page.PreviousCursor)
|
||||
}
|
||||
this.Count = page.Count
|
||||
this.TotalCount = page.TotalCount
|
||||
this.Remaining = page.Remaining
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,9 @@ func (this *MarketRouter) InitRouter() {
|
||||
f5.GetApp().GetGinEngine().POST("/api/market/product/list/:net_id",
|
||||
middleware.MaybeJwtAuth,
|
||||
api.MarketApi.ProductList)
|
||||
f5.GetApp().GetGinEngine().POST("/api/market/product1/list/:net_id",
|
||||
middleware.MaybeJwtAuth,
|
||||
api.MarketApi.ProductList1)
|
||||
f5.GetApp().GetGinEngine().GET("/api/market/transaction/history/:net_id/:account_address",
|
||||
api.MarketApi.TransactionHistory)
|
||||
f5.GetApp().GetGinEngine().GET("/api/market/product/category/:net_id", api.MarketApi.CategoryGoodsNum)
|
||||
|
2
third_party/f5
vendored
2
third_party/f5
vendored
@ -1 +1 @@
|
||||
Subproject commit 5c45b36138650071bfbd79b4694d1e5c902f9c37
|
||||
Subproject commit 1d17c0c75ac5ea98a1a57d0b0a04dbc1559d992e
|
Loading…
x
Reference in New Issue
Block a user