合并区块确认查询
This commit is contained in:
parent
f213ce23af
commit
75c61bfff5
|
@ -24,6 +24,26 @@ class ApplicationQuery
|
|||
end
|
||||
end
|
||||
|
||||
# find one repo that a user has tokens
|
||||
def find_one_balance_with_token(user_id, project_id)
|
||||
# return 3 statuses: UnknownErr/ResUserNotExisted/Success
|
||||
params = {
|
||||
"request-type": "query user balance of single repo",
|
||||
"username": user_id.to_s,
|
||||
"token_name": project_id.to_s
|
||||
}.to_json
|
||||
Rails.logger.info "query user balance of single repo params======= #{params}"
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
Rails.logger.info "resp_body======= #{resp_body}"
|
||||
if resp_body['status'] == 0
|
||||
return resp_body
|
||||
elsif resp_body['status'] == 100
|
||||
return 0 # 找不到用户返回0
|
||||
else
|
||||
raise "区块链接口请求失败."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# find one repo that a user has tokens
|
||||
def find_one_balance(user_id, project_id)
|
||||
|
|
|
@ -11,9 +11,15 @@ class Blockchain::BalanceQuery < ApplicationQuery
|
|||
if is_current_admin_user
|
||||
result_list = []
|
||||
if params[:project_id].present? or params[:keyword].present?
|
||||
project_ids = params[:project_id].present? ? [params[:project_id]] : Project.where(user_id: params["user_id"]).like(params[:keyword]).ids
|
||||
token_list, total_count = find_repo_with_token(params["user_id"], 1, 10000)
|
||||
p_ids = []
|
||||
token_list.each do |t|
|
||||
p_ids.push(t['token_name'].to_i)
|
||||
end
|
||||
project_ids = params[:project_id].present? ? [params[:project_id]] : Project.where(id: p_ids).like(params[:keyword]).ids
|
||||
project_ids.each do |project_id|
|
||||
project_balance = find_one_balance(params["user_id"], project_id)
|
||||
project_balance = find_one_balance_with_token(params["user_id"], project_id)
|
||||
next if project_balance == 0
|
||||
project = Project.find_by(id: project_balance['token_name'].to_i)
|
||||
if project.present?
|
||||
owner = User.find_by(id: project.user_id)
|
||||
|
|
Loading…
Reference in New Issue