75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package asset
|
|
|
|
import (
|
|
"q5"
|
|
"f5"
|
|
"main/constant"
|
|
"main/common"
|
|
"fmt"
|
|
"strings"
|
|
. "main/global"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AssetApi struct {
|
|
|
|
}
|
|
|
|
/*
|
|
filterType: 0:全部 1:已上架 2:未上架
|
|
*/
|
|
func (this *AssetApi) AccountAsset(c *gin.Context) {
|
|
pageSize := q5.AdjustRangeValue(q5.ToInt32(c.DefaultQuery("page_size", "")), 1, 20)
|
|
cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
|
|
netId := q5.ToInt64(c.Param("net_id"))
|
|
accountAddress := strings.ToLower(c.Param("account_address"))
|
|
filterType := q5.ToInt32(c.DefaultQuery("type", ""))
|
|
sql := fmt.Sprintf(`
|
|
SELECT A.idx, A.net_id, A.token_type, A.token_id, A.contract_address, B.status FROM t_nft A LEFT JOIN t_order B
|
|
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=? `,
|
|
cursor, netId)
|
|
params := []string{accountAddress}
|
|
if filterType == 1 {
|
|
sql += "B.status = '" + constant.ORDER_STATUS_ACTIVE + "'"
|
|
} else if filterType == 2 {
|
|
sql += "B.status <> '" + constant.ORDER_STATUS_ACTIVE + "'"
|
|
}
|
|
orderBy := ""
|
|
rspObj := struct {
|
|
ErrCode int32 `json:"errcode"`
|
|
ErrMsg string `json:"errmsg"`
|
|
Page common.StreamPagination `json:"page"`
|
|
Rows []interface{} `json:"rows"`
|
|
}{
|
|
Rows : []interface{}{},
|
|
}
|
|
nfts := []*common.NftDto{}
|
|
f5.GetGoStyleDb().StreamPageQuery(
|
|
constant.BCNFT_DB,
|
|
pageSize,
|
|
cursor,
|
|
sql,
|
|
params,
|
|
f5.GetDbFilter().Comp(
|
|
),
|
|
orderBy,
|
|
func (err error, pagination *f5.StreamPagination) {
|
|
rspObj.Page.FillPage(pagination)
|
|
},
|
|
func (ds *f5.DataSet) {
|
|
p := new(common.NftDto)
|
|
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
|
|
p.ContractAddress = ds.GetByName("contract_address")
|
|
p.TokenId = ds.GetByName("token_id")
|
|
q5.AppendSlice(&nfts, p)
|
|
})
|
|
GetCacheMgr().GetNfts(nfts)
|
|
{
|
|
for _, val := range nfts {
|
|
q5.AppendSlice(&rspObj.Rows, val.NftCache.GetJsonData())
|
|
}
|
|
}
|
|
c.JSON(200, rspObj)
|
|
}
|