From 2bc0efc771e24c319cebd0590591a5c5ea95f158 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 14 Jun 2024 13:14:36 +0800 Subject: [PATCH] 1 --- server/marketserver/api/v1/asset/asset.go | 5 + server/marketserver/api/v1/market/market.go | 147 ++++++++++++++++++-- 2 files changed, 139 insertions(+), 13 deletions(-) diff --git a/server/marketserver/api/v1/asset/asset.go b/server/marketserver/api/v1/asset/asset.go index beab3cd7..f2e9d7f9 100644 --- a/server/marketserver/api/v1/asset/asset.go +++ b/server/marketserver/api/v1/asset/asset.go @@ -18,6 +18,11 @@ type AssetApi struct { */ func (this *AssetApi) AccountAsset(c *gin.Context) { pageSize := q5.ToInt32(c.DefaultQuery("page_size", "")) + if pageSize < 0 { + pageSize = 1 + } else if pageSize > 100 { + pageSize = 100 + } cursor := q5.ToInt64(c.DefaultQuery("cursor", "")) netId := q5.ToInt64(c.Param("net_id")) accountAddress := strings.ToLower(c.Param("account_address")) diff --git a/server/marketserver/api/v1/market/market.go b/server/marketserver/api/v1/market/market.go index 5fd81a12..e16d8d29 100644 --- a/server/marketserver/api/v1/market/market.go +++ b/server/marketserver/api/v1/market/market.go @@ -1,8 +1,13 @@ package market import ( + "q5" "f5" "mt" + "main/constant" + "fmt" + //"strings" + "net/http" "github.com/gin-gonic/gin" ) @@ -11,20 +16,136 @@ type MarketApi struct { } func (this *MarketApi) ProductList(c *gin.Context) { - netId := c.Param("netId") - tokenId := c.Param("tokenId") - f5.GetHttpCliMgr().SendGoStyleRequest( - mt.Table.Config.GetGameApiUrl() + "/webapp/index.php", - map[string]string{ - "c": "OutAppNft", - "a": "nftMetaView", - "nft_type": "hero", - "net_id": netId, - "token_id": tokenId, - }, - func (rsp f5.HttpCliResponse) { - c.String(200, rsp.GetRawData()) + 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:"cursor"` + Filter struct { + PriceMin interface{} `json:"price_min"` + PriceMax interface{} `json:"price_max"` + ItemIds []int32 `json:"item_ids"` + HeroRanks []int32 `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.SafeToInt32(reqJson.PageSize) + if pageSize < 0 { + pageSize = 1 + } else if pageSize > 20 { + pageSize = 20 + } + cursor := q5.ToInt64(c.DefaultQuery("cursor", "")) + sql := fmt.Sprintf(` +SELECT * FROM t_order A WHERE idx > %d AND net_id = %d AND status="%s" +`, + cursor, netId, constant.ORDER_STATUS_ACTIVE, pageSize + 1) + + orderBy := "" + { + for _, val := range reqJson.Sort.Fields { + if val.Name == "price" && orderBy == "" { + t := q5.SafeToInt32(val.Type) + if t < 0 { + orderBy = " ORDER BY LENGTH(price) DESC, price DESC" + } else { + orderBy = " ORDER BY LENGTH(price) 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 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()) + } + } + + nfts := []struct{ + idx int64 + netId int32 + tokenType int32 + tokenId string + contractAddress string + }{} + f5.GetGoStyleDb().StreamPageQuery( + constant.BCNFT_DB, + pageSize, + cursor, + sql, + []string{ + }, + f5.GetDbFilter().Comp(subFilters...), + orderBy, + func (err error, pagination *f5.StreamPagination) { + + }, + func (ds *f5.DataSet) { + var p = q5.NewSliceElement(&nfts) + p.idx = q5.ToInt64(ds.GetByName("idx")) + p.netId = q5.ToInt32(ds.GetByName("net_id")) + p.tokenType = q5.ToInt32(ds.GetByName("token_type")) + p.tokenId = ds.GetByName("token_id") + p.contractAddress = ds.GetByName("contract_address") + f5.GetSysLog().Info("idx:%s", p.idx) + }) + f5.GetSysLog().Info("dafdf") } func (this *MarketApi) TransactionHistory(c *gin.Context) {