1
This commit is contained in:
parent
37b54f1636
commit
ee9b02a362
@ -15,6 +15,11 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type goodsDto struct {
|
||||||
|
Event interface{} `json:"event"`
|
||||||
|
Nft interface{} `json:"nft"`
|
||||||
|
}
|
||||||
|
|
||||||
type MarketApi struct {
|
type MarketApi struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -279,41 +284,45 @@ WHERE net_id = %d AND status="%s" AND item_id <> 0 GROUP BY item_id
|
|||||||
func (this *MarketApi) QueryPrice(c *gin.Context) {
|
func (this *MarketApi) QueryPrice(c *gin.Context) {
|
||||||
netId := q5.ToInt64(c.DefaultQuery("net_id", ""))
|
netId := q5.ToInt64(c.DefaultQuery("net_id", ""))
|
||||||
itemId := q5.ToInt64(c.DefaultQuery("item_id", ""))
|
itemId := q5.ToInt64(c.DefaultQuery("item_id", ""))
|
||||||
|
contractAddress := c.DefaultQuery("contract_address", "")
|
||||||
|
itemQuality := q5.ToInt64(c.DefaultQuery("quality", ""))
|
||||||
|
|
||||||
|
itemMeta := mt.Table.Item.GetById(itemId)
|
||||||
|
if itemMeta != nil && itemMeta.GetType() != jccommon.ITEM_TYPE_HERO {
|
||||||
|
itemQuality = 0
|
||||||
|
}
|
||||||
|
|
||||||
rspObj := &struct {
|
rspObj := &struct {
|
||||||
ErrCode int32 `json:"errcode"`
|
ErrCode int32 `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
ErrMsg string `json:"errmsg"`
|
||||||
LowestPriceGoods *struct{
|
LowestPriceGoods *goodsDto `json:"lowest_price_goods"`
|
||||||
Event interface{} `json:"event"`
|
HighestPriceGoods *goodsDto `json:"highest_price_goods"`
|
||||||
Nft interface{} `json:"nft"`
|
|
||||||
} `json:"lowest_price_goods"`
|
|
||||||
HighestPriceGoods *struct{
|
|
||||||
Event interface{} `json:"event"`
|
|
||||||
Nft interface{} `json:"nft"`
|
|
||||||
} `json:"highest_price_goods"`
|
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
|
lowestPriceGoodsIdx := int64(0)
|
||||||
|
highestPriceGoodsIdx := int64(0)
|
||||||
|
{
|
||||||
|
var dbErr error
|
||||||
|
lowestPrice := ""
|
||||||
|
highestPrice := ""
|
||||||
sql := fmt.Sprintf(`
|
sql := fmt.Sprintf(`
|
||||||
SELECT idx, price FROM t_order
|
SELECT idx, price FROM t_order
|
||||||
WHERE net_id = %d AND status="%s" AND item_id = %d
|
WHERE net_id = %d AND contract_address=? AND status="%s" AND item_id = %d AND hero_quality = %d
|
||||||
`,
|
`,
|
||||||
netId,
|
netId,
|
||||||
jccommon.ORDER_STATUS_ACTIVE,
|
jccommon.ORDER_STATUS_ACTIVE,
|
||||||
itemId)
|
itemId,
|
||||||
params := []string{}
|
itemQuality)
|
||||||
lowestPriceGoodsIdx := int64(0)
|
params := []string{
|
||||||
highestPriceGoodsIdx := int64(0)
|
contractAddress,
|
||||||
lowestPrice := ""
|
}
|
||||||
highestPrice := ""
|
|
||||||
f5.GetGoStyleDb().RawQuery(
|
f5.GetGoStyleDb().RawQuery(
|
||||||
constant.BCNFT_DB,
|
constant.BCNFT_DB,
|
||||||
sql,
|
sql,
|
||||||
params,
|
params,
|
||||||
func (err error, ds *f5.DataSet) {
|
func (err error, ds *f5.DataSet) {
|
||||||
|
dbErr = err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rspObj.ErrCode = 500
|
|
||||||
rspObj.ErrMsg = "server internal error"
|
|
||||||
c.JSON(200, rspObj)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for ds.Next() {
|
for ds.Next() {
|
||||||
@ -330,6 +339,72 @@ WHERE net_id = %d AND status="%s" AND item_id = %d
|
|||||||
highestPrice = price
|
highestPrice = price
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.JSON(200, rspObj)
|
|
||||||
})
|
})
|
||||||
|
if dbErr != nil {
|
||||||
|
rspObj.ErrCode = 500
|
||||||
|
rspObj.ErrMsg = "server internal error"
|
||||||
|
c.JSON(200, rspObj)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
idxs := []string{}
|
||||||
|
if lowestPriceGoodsIdx > 0 {
|
||||||
|
q5.AppendSlice(&idxs, q5.ToString(lowestPriceGoodsIdx))
|
||||||
|
}
|
||||||
|
if highestPriceGoodsIdx > 0 {
|
||||||
|
q5.AppendSlice(&idxs, q5.ToString(highestPriceGoodsIdx))
|
||||||
|
}
|
||||||
|
if len(idxs) <= 0 {
|
||||||
|
c.JSON(200, rspObj)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var dbErr error
|
||||||
|
sql := fmt.Sprintf(`
|
||||||
|
SELECT * FROM t_order
|
||||||
|
WHERE idx in (%s)
|
||||||
|
`,
|
||||||
|
strings.Join(idxs, ","))
|
||||||
|
nfts := []*common.NftDto{}
|
||||||
|
f5.GetGoStyleDb().RawQuery(
|
||||||
|
constant.BCNFT_DB,
|
||||||
|
sql,
|
||||||
|
[]string{},
|
||||||
|
func (err error, ds *f5.DataSet) {
|
||||||
|
dbErr = err
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for ds.Next() {
|
||||||
|
p := new(common.NftDto)
|
||||||
|
p.Param1 = q5.ToInt64(ds.GetByName("idx"))
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if dbErr != nil {
|
||||||
|
c.JSON(200, rspObj)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
GetCacheMgr().GetNfts(nfts)
|
||||||
|
{
|
||||||
|
for _, val := range nfts {
|
||||||
|
var p *goodsDto
|
||||||
|
p = new(goodsDto)
|
||||||
|
p.Event = val.Payload
|
||||||
|
p.Nft = val.NftCache.GetJsonData()
|
||||||
|
if val.Param1 == lowestPriceGoodsIdx {
|
||||||
|
rspObj.LowestPriceGoods = p
|
||||||
|
}
|
||||||
|
if val.Param1 == highestPriceGoodsIdx {
|
||||||
|
rspObj.HighestPriceGoods = p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(200, rspObj)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ type NftDto struct {
|
|||||||
TokenId string
|
TokenId string
|
||||||
NftCache NftCache
|
NftCache NftCache
|
||||||
Payload interface{}
|
Payload interface{}
|
||||||
|
Param1 int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type App interface {
|
type App interface {
|
||||||
|
@ -3,7 +3,6 @@ package mt
|
|||||||
import (
|
import (
|
||||||
"f5"
|
"f5"
|
||||||
"mtb"
|
"mtb"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Contract struct {
|
type Contract struct {
|
||||||
@ -16,7 +15,3 @@ type ContractTable struct {
|
|||||||
|
|
||||||
func (this *Contract) Init1() {
|
func (this *Contract) Init1() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Contract) GetContractAddress() string {
|
|
||||||
return strings.ToLower(this.GetAddress())
|
|
||||||
}
|
|
||||||
|
@ -12,7 +12,7 @@ type table struct {
|
|||||||
Config *ConfigTable
|
Config *ConfigTable
|
||||||
Item *ItemTable
|
Item *ItemTable
|
||||||
Language *LanguageTable
|
Language *LanguageTable
|
||||||
Contract *ContractTable
|
//Contract *ContractTable
|
||||||
Web3ServiceCluster *Web3ServiceClusterTable
|
Web3ServiceCluster *Web3ServiceClusterTable
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,10 +52,12 @@ var Table = f5.New(func(this *table) {
|
|||||||
this.PrimKey = "info"
|
this.PrimKey = "info"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
this.Contract = f5.New(func(this *ContractTable) {
|
this.Contract = f5.New(func(this *ContractTable) {
|
||||||
this.FileName = "../config/contract.json"
|
this.FileName = "../config/contract.json"
|
||||||
this.PrimKey = "name"
|
this.PrimKey = "name"
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
this.Web3ServiceCluster = f5.New(func(this *Web3ServiceClusterTable) {
|
this.Web3ServiceCluster = f5.New(func(this *Web3ServiceClusterTable) {
|
||||||
this.FileName = "../config/web3service.cluster.json"
|
this.FileName = "../config/web3service.cluster.json"
|
||||||
|
@ -16,4 +16,5 @@ func (this *MarketRouter) InitRouter() {
|
|||||||
f5.GetApp().GetGinEngine().GET("/api/market/transaction/history/:net_id/:account_address",
|
f5.GetApp().GetGinEngine().GET("/api/market/transaction/history/:net_id/:account_address",
|
||||||
api.MarketApi.TransactionHistory)
|
api.MarketApi.TransactionHistory)
|
||||||
f5.GetApp().GetGinEngine().GET("/api/market/product/category/:net_id", api.MarketApi.CategoryGoodsNum)
|
f5.GetApp().GetGinEngine().GET("/api/market/product/category/:net_id", api.MarketApi.CategoryGoodsNum)
|
||||||
|
f5.GetApp().GetGinEngine().GET("/api/market/product/query_price", api.MarketApi.QueryPrice)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user