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