This commit is contained in:
aozhiwei 2024-07-24 11:34:21 +08:00
parent a2fb17a9fa
commit 66e5392b13
3 changed files with 93 additions and 2 deletions

View File

@ -45,6 +45,45 @@ func GetItemIdHeroQuality(netId int32, contractAddress string, tokenId string,
})
}
func GetNftItemIdQuality(netId int32, contractAddress string, tokenId string,
itemId *int32, quality *int32) {
f5.GetGoStyleDb().OrmSelectOne(
constant.BCNFT_DB,
"t_nft",
[][]string {
{"net_id", q5.ToString(netId)},
{"contract_address", contractAddress},
{"token_id", tokenId},
},
func (err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
*itemId = q5.ToInt32(ds.GetByName("item_id"))
*quality = q5.ToInt32(ds.GetByName("quality"))
tokenType := q5.ToInt32(ds.GetByName("token_type"))
if tokenType == jccommon.NFT_TYPE_CFHERO ||
tokenType == jccommon.NFT_TYPE_CFHERO_NORMAL {
f5.GetGoStyleDb().OrmSelectOne(
constant.GAME_DB,
"t_hero",
[][]string {
{"token_id", tokenId},
},
func (err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
*quality = q5.ToInt32(ds.GetByName("quality"))
}
})
}
}
})
}
func GetHeroByTokenId(tokenId string, itemId *int32, heroQuality *int32) bool {
result := false
f5.GetGoStyleDb().OrmSelectOne(

View File

@ -98,10 +98,10 @@ func (this* chainActivity) saveToDb(ds *f5.DataSet) bool {
{"token_id", tokenId},
}
}
genInsertKv := func (nftAddress ,tokenId ,sender, to string, isMint int32) [][]string {
genInsertKv := func (nftAddress, tokenId, sender, to string, isMint int32) [][]string {
var itemId int32
var quality int32
service.GetItemIdHeroQuality(q5.ToInt32(netId), contractAddress, tokenId, &itemId, &quality)
service.GetNftItemIdQuality(q5.ToInt32(netId), contractAddress, tokenId, &itemId, &quality)
return [][]string{
{"txhash", txhash},
{"log_index", logIndex},

View File

@ -18,6 +18,7 @@ func (this* repairNft) init() {
go this.processNft()
go this.processOrder()
go this.processSale()
go this.processChainActivity()
}
func (this* repairNft) unInit() {
@ -102,6 +103,32 @@ SELECT * FROM t_sale WHERE idx > %d AND item_id = 0 LIMIT 1000`,
this.repairSale)
}
func (this* repairNft) processChainActivity() {
f5.GetGoStyleDb().LoopLoad(
constant.BCEVENT_DB,
"repairNft.chainActivity",
"t_chain_activity",
func () int64 {
return 60 + q5.ToInt64(rand.Intn(2))
},
func (lastIdx int64) string {
sql := fmt.Sprintf(`
SELECT * FROM t_chain_activity WHERE idx > %d AND item_id = 0 AND quality = 0 LIMIT 100`,
lastIdx,
)
return sql
},
[]string{
},
func () int64 {
return 10
},
func () int64 {
return 60 * 5
},
this.repairChainActivity)
}
func (this* repairNft) repairNft(ds *f5.DataSet) bool {
netId := q5.ToInt32(ds.GetByName("net_id"))
contractAddress := ds.GetByName("contract_address")
@ -233,3 +260,28 @@ func (this* repairNft) updateSale(netId int32, contractAddress string, tokenId s
func (err error, lastInsertId int64, rowsAffected int64) {
})
}
func (this* repairNft) repairChainActivity(ds *f5.DataSet) bool {
netId := q5.ToInt32(ds.GetByName("net_id"))
contractAddress := ds.GetByName("contract_address")
tokenId := ds.GetByName("token_id")
switch q5.ToInt32(ds.GetByName("token_type")) {
case jccommon.NFT_TYPE_CFHERO:
case jccommon.NFT_TYPE_CFHERO_NORMAL:
{
var itemId int32
var quality int32
if service.GetHeroByTokenId(tokenId, &itemId, &quality) {
this.updateSale(netId, contractAddress, tokenId, itemId, quality)
}
}
case jccommon.NFT_TYPE_GOLD_BULLION:
{
var itemId int32
if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) {
this.updateSale(netId, contractAddress, tokenId, itemId, 0)
}
}
}
return true
}