aozhiwei 53ceb4a0cf 1
2024-07-19 13:11:05 +08:00

234 lines
5.1 KiB
Go

package task
import (
"q5"
"f5"
"fmt"
"jccommon"
"main/constant"
"main/service"
"math/rand"
)
type repairNft struct {
}
func (this* repairNft) init() {
go this.processNft()
go this.processOrder()
go this.processSale()
}
func (this* repairNft) unInit() {
}
func (this* repairNft) processNft() {
f5.GetGoStyleDb().LoopLoad(
constant.BCNFT_DB,
"repairNft.nft",
"t_nft",
func () int64 {
return 60 * 1
},
func (lastIdx int64) string {
sql := fmt.Sprintf(`
SELECT * FROM t_nft WHERE idx > %d AND item_id = 0 LIMIT 1000`,
lastIdx,
)
return sql
},
[]string{
},
func () int64 {
return 10
},
func () int64 {
return 60 * 5
},
this.repairNft)
}
func (this* repairNft) processOrder() {
f5.GetGoStyleDb().LoopLoad(
constant.BCNFT_DB,
"repairNft.order",
"t_order",
func () int64 {
return 60 + q5.ToInt64(rand.Intn(2))
},
func (lastIdx int64) string {
sql := fmt.Sprintf(`
SELECT * FROM t_order WHERE idx > %d AND item_id = 0 LIMIT 1000`,
lastIdx,
)
return sql
},
[]string{
},
func () int64 {
return 3
},
func () int64 {
return 60 * 5
},
this.repairOrder)
}
func (this* repairNft) processSale() {
f5.GetGoStyleDb().LoopLoad(
constant.BCNFT_DB,
"repairNft.sale",
"t_sale",
func () int64 {
return 60 + q5.ToInt64(rand.Intn(2))
},
func (lastIdx int64) string {
sql := fmt.Sprintf(`
SELECT * FROM t_sale WHERE idx > %d AND item_id = 0 LIMIT 1000`,
lastIdx,
)
return sql
},
[]string{
},
func () int64 {
return 10
},
func () int64 {
return 60 * 5
},
this.repairSale)
}
func (this* repairNft) repairNft(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.updateNftItemId(netId, contractAddress, tokenId, itemId)
}
}
case jccommon.NFT_TYPE_GOLD_BULLION:
{
var itemId int32
if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) {
this.updateNftItemId(netId, contractAddress, tokenId, itemId)
}
}
}
return true
}
func (this* repairNft) updateNftItemId(netId int32, contractAddress string, tokenId string,
itemId int32) {
f5.GetGoStyleDb().Update(
constant.BCNFT_DB,
"t_nft",
[][]string {
{"net_id", q5.ToString(netId)},
{"contract_address", contractAddress},
{"token_id", tokenId},
{"item_id", q5.ToString(0)},
},
[][]string {
{"item_id", q5.ToString(itemId)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
})
}
func (this* repairNft) repairOrder(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.updateOrder(netId, contractAddress, tokenId, itemId, quality)
}
}
case jccommon.NFT_TYPE_GOLD_BULLION:
{
var itemId int32
if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) {
this.updateOrder(netId, contractAddress, tokenId, itemId, 0)
}
}
}
return true
}
func (this* repairNft) updateOrder(netId int32, contractAddress string, tokenId string,
itemId int32, quality int32) {
f5.GetGoStyleDb().Update(
constant.BCNFT_DB,
"t_order",
[][]string {
{"net_id", q5.ToString(netId)},
{"contract_address", contractAddress},
{"token_id", tokenId},
{"item_id", q5.ToString(0)},
},
[][]string {
{"item_id", q5.ToString(itemId)},
{"hero_quality", q5.ToString(quality)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
})
}
func (this* repairNft) repairSale(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
}
func (this* repairNft) updateSale(netId int32, contractAddress string, tokenId string,
itemId int32, quality int32) {
f5.GetGoStyleDb().Update(
constant.BCNFT_DB,
"t_sale",
[][]string {
{"net_id", q5.ToString(netId)},
{"contract_address", contractAddress},
{"token_id", tokenId},
{"item_id", q5.ToString(0)},
},
[][]string {
{"item_id", q5.ToString(itemId)},
{"hero_quality", q5.ToString(quality)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
})
}