diff --git a/server/marketserver/api/v1/market/market.go b/server/marketserver/api/v1/market/market.go index 221a3705..2e24fde6 100644 --- a/server/marketserver/api/v1/market/market.go +++ b/server/marketserver/api/v1/market/market.go @@ -15,6 +15,11 @@ import ( "github.com/gin-gonic/gin" ) +type goodsDto struct { + Event interface{} `json:"event"` + Nft interface{} `json:"nft"` +} + type MarketApi struct { } @@ -279,57 +284,127 @@ WHERE net_id = %d AND status="%s" AND item_id <> 0 GROUP BY item_id func (this *MarketApi) QueryPrice(c *gin.Context) { netId := q5.ToInt64(c.DefaultQuery("net_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 { ErrCode int32 `json:"errcode"` ErrMsg string `json:"errmsg"` - LowestPriceGoods *struct{ - Event interface{} `json:"event"` - Nft interface{} `json:"nft"` - } `json:"lowest_price_goods"` - HighestPriceGoods *struct{ - Event interface{} `json:"event"` - Nft interface{} `json:"nft"` - } `json:"highest_price_goods"` + LowestPriceGoods *goodsDto `json:"lowest_price_goods"` + HighestPriceGoods *goodsDto `json:"highest_price_goods"` }{} - sql := fmt.Sprintf(` -SELECT idx, price FROM t_order -WHERE net_id = %d AND status="%s" AND item_id = %d -`, - netId, - jccommon.ORDER_STATUS_ACTIVE, - itemId) - params := []string{} lowestPriceGoodsIdx := int64(0) highestPriceGoodsIdx := int64(0) - lowestPrice := "" - highestPrice := "" - f5.GetGoStyleDb().RawQuery( - constant.BCNFT_DB, - sql, - params, - func (err error, ds *f5.DataSet) { - if err != nil { - rspObj.ErrCode = 500 - rspObj.ErrMsg = "server internal error" - c.JSON(200, rspObj) - return - } - for ds.Next() { - idx := q5.ToInt64(ds.GetByName("idx")) - price := ds.GetByName("price") - if lowestPriceGoodsIdx == 0 || - q5.BigIntStrCmp(lowestPrice, price) < 0 { - lowestPriceGoodsIdx = idx - lowestPrice = price + { + var dbErr error + lowestPrice := "" + highestPrice := "" + sql := fmt.Sprintf(` +SELECT idx, price FROM t_order +WHERE net_id = %d AND contract_address=? AND status="%s" AND item_id = %d AND hero_quality = %d +`, + netId, + jccommon.ORDER_STATUS_ACTIVE, + itemId, + itemQuality) + params := []string{ + contractAddress, + } + f5.GetGoStyleDb().RawQuery( + constant.BCNFT_DB, + sql, + params, + func (err error, ds *f5.DataSet) { + dbErr = err + if err != nil { + return } - if highestPriceGoodsIdx == 0 || - q5.BigIntStrCmp(highestPrice, price) > 0 { - highestPriceGoodsIdx = idx - highestPrice = price + for ds.Next() { + idx := q5.ToInt64(ds.GetByName("idx")) + price := ds.GetByName("price") + if lowestPriceGoodsIdx == 0 || + q5.BigIntStrCmp(lowestPrice, price) < 0 { + lowestPriceGoodsIdx = idx + lowestPrice = price + } + if highestPriceGoodsIdx == 0 || + q5.BigIntStrCmp(highestPrice, price) > 0 { + highestPriceGoodsIdx = idx + highestPrice = price + } } - } + }) + 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) + } } diff --git a/server/marketserver/common/types.go b/server/marketserver/common/types.go index c977c2f4..1021837d 100644 --- a/server/marketserver/common/types.go +++ b/server/marketserver/common/types.go @@ -46,6 +46,7 @@ type NftDto struct { TokenId string NftCache NftCache Payload interface{} + Param1 int64 } type App interface { diff --git a/server/marketserver/mt/Contract.go b/server/marketserver/mt/Contract.go index 33e83251..0d5f4f18 100644 --- a/server/marketserver/mt/Contract.go +++ b/server/marketserver/mt/Contract.go @@ -3,7 +3,6 @@ package mt import ( "f5" "mtb" - "strings" ) type Contract struct { @@ -16,7 +15,3 @@ type ContractTable struct { func (this *Contract) Init1() { } - -func (this *Contract) GetContractAddress() string { - return strings.ToLower(this.GetAddress()) -} diff --git a/server/marketserver/mt/export.go b/server/marketserver/mt/export.go index afb09ca6..dc4f355c 100644 --- a/server/marketserver/mt/export.go +++ b/server/marketserver/mt/export.go @@ -12,7 +12,7 @@ type table struct { Config *ConfigTable Item *ItemTable Language *LanguageTable - Contract *ContractTable + //Contract *ContractTable Web3ServiceCluster *Web3ServiceClusterTable } @@ -52,10 +52,12 @@ var Table = f5.New(func(this *table) { this.PrimKey = "info" }) + /* this.Contract = f5.New(func(this *ContractTable) { this.FileName = "../config/contract.json" this.PrimKey = "name" }) + */ this.Web3ServiceCluster = f5.New(func(this *Web3ServiceClusterTable) { this.FileName = "../config/web3service.cluster.json" diff --git a/server/marketserver/router/market/market.go b/server/marketserver/router/market/market.go index 055b1809..33069dc0 100644 --- a/server/marketserver/router/market/market.go +++ b/server/marketserver/router/market/market.go @@ -16,4 +16,5 @@ func (this *MarketRouter) InitRouter() { 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) + f5.GetApp().GetGinEngine().GET("/api/market/product/query_price", api.MarketApi.QueryPrice) }