新增:token转账列表新增分页参数
This commit is contained in:
parent
8f680fd7c3
commit
841126c0fc
|
@ -416,7 +416,7 @@ class UsersController < ApplicationController
|
|||
is_current_admin_user = true
|
||||
results = Blockchain::BalanceQuery.call(params, is_current_admin_user)
|
||||
if results[:status] == 0
|
||||
@total_count = results[:projects].size
|
||||
@total_count = results[:total_count]
|
||||
@projects = results[:projects]
|
||||
else
|
||||
@total_count = -1
|
||||
|
|
|
@ -8,17 +8,19 @@ class ApplicationQuery
|
|||
end
|
||||
|
||||
# find all the repos that a user has tokens
|
||||
def find_repo_with_token(user_id)
|
||||
def find_repo_with_token(user_id, page=1, limit=10)
|
||||
params = {
|
||||
"request-type": "query user balance of all repos",
|
||||
"username": user_id.to_s
|
||||
"request-type": "query user balance of all repos by page",
|
||||
"username": user_id.to_s,
|
||||
"page": page.to_i,
|
||||
"page_num": limit.to_i
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] != 0
|
||||
raise "区块链接口请求失败."
|
||||
else
|
||||
token_list = resp_body['UserBalanceList'].nil? ? [] : resp_body['UserBalanceList']
|
||||
return token_list
|
||||
return token_list, resp_body['total_count']
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class Blockchain::BalanceQuery < ApplicationQuery
|
|||
|
||||
def call
|
||||
if is_current_admin_user
|
||||
token_list = find_repo_with_token(params["user_id"])
|
||||
token_list, total_count = find_repo_with_token(params["user_id"], (params["page"]), (params["limit"]))
|
||||
result_list = []
|
||||
token_list.each do |t|
|
||||
project = Project.find_by(id: t['token_name'].to_i)
|
||||
|
@ -23,7 +23,7 @@ class Blockchain::BalanceQuery < ApplicationQuery
|
|||
result_list << {project: project, balance: balance}
|
||||
end
|
||||
end
|
||||
results = {"status": 0, "projects": result_list}
|
||||
results = {"status": 0, "projects": result_list, "total_count": total_count}
|
||||
else
|
||||
results = {"status": 1} # query failed
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
# elsif params[:category].to_s == "private"
|
||||
# projects = projects.is_private.joins(:members).where(members: { user_id: user.id })
|
||||
elsif params[:category].to_s == "blockchain_token" # 所有钱包中有token的项目有哪些
|
||||
token_list = find_repo_with_token(user.id)
|
||||
token_list, total_count = find_repo_with_token(user.id)
|
||||
project_names = token_list.map { |x| x['token_name'] }
|
||||
projects = projects.where(name: project_names)
|
||||
tokens = token_list.map { |x| x['balance'] }
|
||||
|
|
Loading…
Reference in New Issue