This commit is contained in:
aozhiwei 2024-06-16 12:28:43 +08:00
parent 40dc2565db
commit be78cc942e
2 changed files with 15 additions and 29 deletions

View File

@ -19,12 +19,7 @@ type AssetApi struct {
filterType: 0:全部 1:已上架 2:未上架 filterType: 0:全部 1:已上架 2:未上架
*/ */
func (this *AssetApi) AccountAsset(c *gin.Context) { func (this *AssetApi) AccountAsset(c *gin.Context) {
pageSize := q5.ToInt32(c.DefaultQuery("page_size", "")) pageSize := q5.AdjustRangeValue(q5.ToInt32(c.DefaultQuery("page_size", "")), 1, 20)
if pageSize < 0 {
pageSize = 1
} else if pageSize > 100 {
pageSize = 100
}
cursor := q5.ToInt64(c.DefaultQuery("cursor", "")) cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
netId := q5.ToInt64(c.Param("net_id")) netId := q5.ToInt64(c.Param("net_id"))
accountAddress := strings.ToLower(c.Param("account_address")) accountAddress := strings.ToLower(c.Param("account_address"))
@ -34,11 +29,13 @@ SELECT A.idx, A.net_id, A.token_type, A.token_id, A.contract_address, B.status F
ON A.net_id = B.net_id AND A.contract_address = B.contract_address AND A.token_id = B.token_id ON A.net_id = B.net_id AND A.contract_address = B.contract_address AND A.token_id = B.token_id
WHERE A.idx > %d AND A.net_id = %d AND A.owner_address=? `, WHERE A.idx > %d AND A.net_id = %d AND A.owner_address=? `,
cursor, netId) cursor, netId)
params := []string{accountAddress}
if filterType == 1 { if filterType == 1 {
sql += "B.status = '" + constant.ORDER_STATUS_ACTIVE + "'" sql += "B.status = '" + constant.ORDER_STATUS_ACTIVE + "'"
} else if filterType == 2 { } else if filterType == 2 {
sql += "B.status <> '" + constant.ORDER_STATUS_ACTIVE + "'" sql += "B.status <> '" + constant.ORDER_STATUS_ACTIVE + "'"
} }
orderBy := ""
rspObj := struct { rspObj := struct {
ErrCode int32 `json:"errcode"` ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"` ErrMsg string `json:"errmsg"`
@ -53,12 +50,10 @@ WHERE A.idx > %d AND A.net_id = %d AND A.owner_address=? `,
pageSize, pageSize,
cursor, cursor,
sql, sql,
[]string{ params,
accountAddress,
},
f5.GetDbFilter().Comp( f5.GetDbFilter().Comp(
), ),
"", orderBy,
func (err error, pagination *f5.StreamPagination) { func (err error, pagination *f5.StreamPagination) {
rspObj.Page.FillPage(pagination) rspObj.Page.FillPage(pagination)
}, },

View File

@ -46,12 +46,7 @@ func (this *MarketApi) ProductList(c *gin.Context) {
return return
} }
pageSize := q5.SafeToInt32(reqJson.PageSize) pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 20)
if pageSize < 0 {
pageSize = 1
} else if pageSize > 20 {
pageSize = 20
}
cursor := q5.ToInt64(c.DefaultQuery("cursor", "")) cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
sql := fmt.Sprintf(` sql := fmt.Sprintf(`
SELECT * FROM t_order A WHERE idx > %d AND net_id = %d AND status="%s" SELECT * FROM t_order A WHERE idx > %d AND net_id = %d AND status="%s"
@ -170,12 +165,7 @@ SELECT * FROM t_order A WHERE idx > %d AND net_id = %d
} }
func (this *MarketApi) TransactionHistory(c *gin.Context) { func (this *MarketApi) TransactionHistory(c *gin.Context) {
pageSize := q5.ToInt32(c.DefaultQuery("page_size", "")) pageSize := q5.AdjustRangeValue(q5.ToInt32(c.DefaultQuery("page_size", "")), 1, 20)
if pageSize < 0 {
pageSize = 1
} else if pageSize > 20 {
pageSize = 20
}
cursor := q5.ToInt64(c.DefaultQuery("cursor", "")) cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
netId := q5.ToInt64(c.Param("net_id")) netId := q5.ToInt64(c.Param("net_id"))
accountAddress := strings.ToLower(c.Param("account_address")) accountAddress := strings.ToLower(c.Param("account_address"))
@ -183,12 +173,14 @@ func (this *MarketApi) TransactionHistory(c *gin.Context) {
sql := fmt.Sprintf(` sql := fmt.Sprintf(`
SELECT * FROM t_sale WHERE idx > %d AND net_id = %d `, SELECT * FROM t_sale WHERE idx > %d AND net_id = %d `,
cursor, netId) cursor, netId)
params := []string{}
subFilters := []f5.DbQueryFilter{} subFilters := []f5.DbQueryFilter{}
{ {
if filterType == 1 { if filterType == 1 {
q5.AppendSlice(&subFilters, f5.GetDbFilter().EQ("buyer", accountAddress).And()) sql += "AND buyer = ? "
q5.AppendSlice(&params, accountAddress)
} else if filterType == 2 { } else if filterType == 2 {
q5.AppendSlice(&subFilters, f5.GetDbFilter().EQ("seller", accountAddress).And()) sql += "AND seller = ? "
} }
} }
rspObj := struct { rspObj := struct {
@ -199,17 +191,16 @@ SELECT * FROM t_sale WHERE idx > %d AND net_id = %d `,
}{ }{
Rows : []interface{}{}, Rows : []interface{}{},
} }
orderBy := ""
nfts := []*common.NftDto{} nfts := []*common.NftDto{}
f5.GetGoStyleDb().StreamPageQuery( f5.GetGoStyleDb().StreamPageQuery(
constant.BCNFT_DB, constant.BCNFT_DB,
pageSize, pageSize,
cursor, cursor,
sql, sql,
[]string{ params,
//accountAddress,
},
f5.GetDbFilter().Comp(subFilters...), f5.GetDbFilter().Comp(subFilters...),
"", orderBy,
func (err error, pagination *f5.StreamPagination) { func (err error, pagination *f5.StreamPagination) {
rspObj.Page.FillPage(pagination) rspObj.Page.FillPage(pagination)
}, },