修改查询

This commit is contained in:
yangduo 2024-07-04 14:50:53 +08:00
parent b9066d9939
commit 227e1bad17
7 changed files with 53 additions and 31 deletions

View File

@ -30,6 +30,16 @@ exports.RspHead = class RspHead {
};
exports.StreamPagination = class StreamPagination {
constructor() {
this.fields = [
['next_cursor', '', '下一页游标'],
['previous_cursor', '', '上一页游标'],
['remaining', 0, '剩余条数'],
];
}
};
exports.Attachment = class {
constructor() {
@ -155,7 +165,7 @@ exports.BagItem = class {
['today_get_gold', 0, '今日获得金币'],
['last_get_gold_time', 0, '最后获得金币时间'],
['createtime', 0, '创建时间'],
['modifiedtime', 0, '修改时间'],
['modifytime', 0, '修改时间'],
['is_old', 0, '0:展示红点 1:不用展示'],
]
}

View File

@ -14,9 +14,9 @@ module.exports = class {
],
'is_json_params': true,
'params': [
['name', '', '用户名字'],
['account_id', '', '账号id'],
['address', '', '钱包地址'],
['order_id', '', '订单id'],
['contract_address', '', '合约地址'],
['token_id', '', 'token_id'],
],
'uri_params': [
['cursor', '', '游标'],
@ -24,20 +24,23 @@ module.exports = class {
],
'response': [
new common.RspHead(),
['!data', common.Player()]
new common.StreamPagination(),
['!data', common.Order()]
]
},
{
'method': 'POST',
'name': 'bagquery',
'desc': '获取玩家背包信息',
'name': 'salequery',
'desc': '获取售卖信息',
'group': 'nft',
'url': 'api/v1/nft/bagquery',
'url': 'api/v1/nft/salequery',
'header': [
],
'is_json_params': true,
'params': [
['account_id', '', '账号id'],
['order_id', '', '订单id'],
['buyer', '', '买家'],
['seller', '', '卖家'],
],
'uri_params': [
['cursor', '', '游标'],
@ -45,20 +48,23 @@ module.exports = class {
],
'response': [
new common.RspHead(),
['!data', common.BagItem()]
new common.StreamPagination(),
['!data', common.Sale()]
]
},
{
'method': 'POST',
'name': 'heroesquery',
'desc': '获取玩家英雄信息',
'name': 'nftquery',
'desc': '获取NFT信息',
'group': 'nft',
'url': 'api/v1/nft/heroesquery',
'url': 'api/v1/nft/nftquery',
'header': [
],
'is_json_params': true,
'params': [
['account_id', '', '账号id'],
['owner_address', '', '所有者'],
['last_owner_address', '', '上一个所有者'],
['net_id', '', 'net_id'],
],
'uri_params': [
['cursor', '', '游标'],
@ -66,7 +72,8 @@ module.exports = class {
],
'response': [
new common.RspHead(),
['!data', common.he()]
new common.StreamPagination(),
['!data', common.NFT()]
]
}
];

View File

@ -25,6 +25,7 @@ module.exports = class {
],
'response': [
new common.RspHead(),
new common.StreamPagination(),
['!data', common.Player()]
]
},
@ -46,6 +47,7 @@ module.exports = class {
],
'response': [
new common.RspHead(),
new common.StreamPagination(),
['!data', common.BagItem()]
]
},
@ -67,7 +69,8 @@ module.exports = class {
],
'response': [
new common.RspHead(),
['!data', common.he()]
new common.StreamPagination(),
['!data', common.Hero()]
]
}
];

View File

@ -23,12 +23,14 @@ func checkparam(obj any, c *gin.Context) bool {
func query(dbname string, cursor int64, sql string, c *gin.Context, loadcall func(ds *f5.DataSet) interface{}) {
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Code int32 `json:"code"`
Message string `json:"message"`
Page common.StreamPagination `json:"page"`
Rows []interface{} `json:"rows"`
Data []interface{} `json:"data"`
}{
Rows: []interface{}{},
Code: 0,
Message: "success",
Data: []interface{}{},
}
pageSize := q5.AdjustRangeValue(q5.ToInt32(c.DefaultQuery("page_size", "")), 1, 20)
@ -50,7 +52,7 @@ func query(dbname string, cursor int64, sql string, c *gin.Context, loadcall fun
rspObj.Page.FillPage(pagination)
},
func(ds *f5.DataSet) {
rspObj.Rows = append(rspObj.Rows, loadcall(ds))
rspObj.Data = append(rspObj.Data, loadcall(ds))
})
c.JSON(200, rspObj)

View File

@ -46,7 +46,7 @@ func (this *NFTApi) OrderQuery(c *gin.Context) {
sql := fmt.Sprintf(`SELECT * FROM t_order WHERE idx > %d AND %s `, cursor, filterstr)
query(constant.BCNFT_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {
var p system.Order
p := new(system.Order)
p.LoadFromDs(ds)
return p
})
@ -83,20 +83,20 @@ func (this *NFTApi) SaleQuery(c *gin.Context) {
sql := fmt.Sprintf(`SELECT * FROM t_sale WHERE idx > %d AND %s `, cursor, filterstr)
query(constant.BCNFT_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {
var p system.Sale
p := new(system.Sale)
p.LoadFromDs(ds)
return p
})
}
func (this *NFTApi) NFTQuery(c *gin.Context) {
type HeroesQueryForm struct {
type NFTQueryForm struct {
Owner_address string `json:"owner_address"`
Last_owner_address string `json:"last_owner_address"`
Net_id int64 `json:"net_id"`
}
reqJson := HeroesQueryForm{}
reqJson := NFTQueryForm{}
if !checkparam(&reqJson, c) {
return
}
@ -120,7 +120,7 @@ func (this *NFTApi) NFTQuery(c *gin.Context) {
sql := fmt.Sprintf(`SELECT * FROM t_nft WHERE idx > %d AND %s `, cursor, filterstr)
query(constant.BCNFT_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {
var p system.NFT
p := new(system.NFT)
p.LoadFromDs(ds)
return p
})

View File

@ -51,7 +51,7 @@ func (this *PlayerApi) Info(c *gin.Context) {
sql := fmt.Sprintf(`SELECT * FROM t_user WHERE idx > %d AND %s `, cursor, filterstr)
query(constant.GAME_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {
var p system.Player
p := new(system.Player)
p.LoadFromDs(ds)
return p
})
@ -72,7 +72,7 @@ func (this *PlayerApi) BagQuery(c *gin.Context) {
sql := fmt.Sprintf(`SELECT * FROM t_bag WHERE idx > %d AND %s `, cursor, filterstr)
query(constant.GAME_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {
var p system.BagItem
p := new(system.BagItem)
p.LoadFromDs(ds)
return p
})
@ -93,7 +93,7 @@ func (this *PlayerApi) HeroesQuery(c *gin.Context) {
sql := fmt.Sprintf(`SELECT * FROM t_hero WHERE idx > %d AND %s `, cursor, filterstr)
query(constant.GAME_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {
var p system.Hero
p := new(system.Hero)
p.LoadFromDs(ds)
return p
})

View File

@ -16,7 +16,7 @@ type BagItem struct {
Today_get_gold int64 `gorm:"comment:今日获得金币" json:"today_get_gold"`
Last_get_gold_time int `gorm:"comment:最后获得金币时间" json:"last_get_gold_time"`
Createtime int `gorm:"comment:创建时间" json:"createtime"`
Modifiedtime int `gorm:"comment:修改时间" json:"modifiedtime"`
Modifytime int `gorm:"comment:修改时间" json:"modifytime"`
Is_old int `gorm:"comment:0:展示红点 1:不用展示" json:"is_old"`
}
@ -34,6 +34,6 @@ func (this *BagItem) LoadFromDs(ds *f5.DataSet) {
this.Today_get_gold = q5.ToInt64(ds.GetByName("today_get_gold"))
this.Last_get_gold_time = q5.ToInt(ds.GetByName("last_get_gold_time"))
this.Createtime = q5.ToInt(ds.GetByName("createtime"))
this.Modifiedtime = q5.ToInt(ds.GetByName("modifiedtime"))
this.Modifytime = q5.ToInt(ds.GetByName("modifytime"))
this.Is_old = q5.ToInt(ds.GetByName("is_old"))
}