change chain
This commit is contained in:
parent
d586f526c9
commit
79641e859c
|
@ -104,66 +104,66 @@ class IssuesController < ApplicationController
|
|||
normal_status(-1, "标题不能为空")
|
||||
elsif params[:subject].to_s.size > 255
|
||||
normal_status(-1, "标题不能超过255个字符")
|
||||
elsif (params[:issue_type].to_s == "2")
|
||||
return normal_status(-1, "悬赏的奖金必须大于0") if params[:token].to_i == 0
|
||||
#查看当前用户的积分
|
||||
query_params = {
|
||||
type: "query",
|
||||
chain_params: {
|
||||
reponame: @project.try(:identifer),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
}
|
||||
|
||||
response = Gitea::Chain::ChainGetService.new(query_params).call
|
||||
return normal_status(-1, "获取token失败,请稍后重试") if response.status != 200
|
||||
return normal_status(-1, "您的token值不足") if response.body["balance"].to_i < params[:token].to_i
|
||||
else
|
||||
if params[:issue_type].to_s == "2"
|
||||
return normal_status(-1, "悬赏的奖金必须大于0") if params[:token].to_i == 0
|
||||
query_params = {
|
||||
type: "query",
|
||||
chain_params: {
|
||||
reponame: @project.try(:identifier),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
}
|
||||
response = Gitea::Chain::ChainGetService.new(query_params).call
|
||||
return normal_status(-1, "获取token失败,请稍后重试") if response.status != 200
|
||||
return normal_status(-1, "您的token值不足") if JSON.parse(response.body)["balance"].to_i < params[:token].to_i
|
||||
end
|
||||
|
||||
issue_params = issue_send_params(params)
|
||||
|
||||
@issue = Issue.new(issue_params)
|
||||
if @issue.save!
|
||||
if params[:attachment_ids].present?
|
||||
params[:attachment_ids].each do |id|
|
||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||
unless attachment.blank?
|
||||
attachment.container = @issue
|
||||
attachment.author_id = current_user.id
|
||||
attachment.description = ""
|
||||
attachment.save
|
||||
begin
|
||||
if @issue.save!
|
||||
if params[:attachment_ids].present?
|
||||
params[:attachment_ids].each do |id|
|
||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||
unless attachment.blank?
|
||||
attachment.container = @issue
|
||||
attachment.author_id = current_user.id
|
||||
attachment.description = ""
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if params[:issue_tag_ids].present?
|
||||
params[:issue_tag_ids].each do |tag|
|
||||
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||
if params[:issue_tag_ids].present?
|
||||
params[:issue_tag_ids].each do |tag|
|
||||
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||
end
|
||||
end
|
||||
if params[:assigned_to_id].present?
|
||||
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
||||
container_id: @issue.id, container_type: 'Issue',
|
||||
parent_container_id: @project.id, parent_container_type: "Project",
|
||||
tiding_type: 'issue', status: 0)
|
||||
end
|
||||
|
||||
#为悬赏任务时, 扣除当前用户的积分
|
||||
if params[:issue_type].to_s == "2"
|
||||
post_to_chain("minus", params[:token].to_i, current_user.try(:login))
|
||||
end
|
||||
|
||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
normal_status(0, "创建成功")
|
||||
else
|
||||
normal_status(-1, "创建失败")
|
||||
end
|
||||
if params[:assigned_to_id].present?
|
||||
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
||||
container_id: @issue.id, container_type: 'Issue',
|
||||
parent_container_id: @project.id, parent_container_type: "Project",
|
||||
tiding_type: 'issue', status: 0)
|
||||
end
|
||||
|
||||
#为悬赏任务时, 扣除当前用户的积分
|
||||
if params[:issue_type].to_s == "2"
|
||||
change_params = {
|
||||
type: "minus",
|
||||
chain_params: {
|
||||
amount: params[:token],
|
||||
reponame: @project.try(:identifer),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(change_params)
|
||||
end
|
||||
|
||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
normal_status(0, "创建成功")
|
||||
rescue => e
|
||||
Rails.looger.info("##################________exception_________________######################{e.message}")
|
||||
normal_status(-1, e.message)
|
||||
else
|
||||
normal_status(-1, "创建失败")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -202,42 +202,24 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# if params[:issue_tag_ids].present?
|
||||
# issue_current_tags = @issue&.issue_tags&.select(:id)&.pluck(:id)
|
||||
# new_tag_ids = params[:issue_tag_ids] - issue_current_tags
|
||||
# old_tag_ids = issue_current_tags - params[:issue_tag_ids]
|
||||
# if old_tag_ids.size > 0
|
||||
# @issue.issue_tags_relates.where(issue_tag_id: old_tag_ids).delete_all
|
||||
# end
|
||||
# if new_tag_ids.size > 0
|
||||
# new_tag_ids.each do |tag|
|
||||
# IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
if params[:status_id].to_i == 5
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
@issue.update_closed_issues_count_in_project!
|
||||
if @issue.issue_type.to_s == "2" && @issue.saved_change_to_attribute("status_id")
|
||||
if @issue.status_id_was == 3
|
||||
post_to_chain("add", @issue.token, @issue.get_assign_user.try(:login))
|
||||
else
|
||||
post_to_chain("add", @issue.token, @issue.user.try(:login))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @issue.issue_type.to_s == "2"
|
||||
if @issue.issue_type.to_s == "2" && ![3,5].include?(@issue.status_id) && @issue.saved_change_to_attribute("token")
|
||||
#表示修改token值
|
||||
if @issue.saved_change_to_attribute("token")
|
||||
last_token = @issue.token_was
|
||||
change_token = last_token - @issue.token
|
||||
change_type = change_token > 0 ? "add" : "minus"
|
||||
change_params = {
|
||||
type: change_type,
|
||||
chain_params: {
|
||||
amount: change_token.abs,
|
||||
reponame: @project.try(:identifer),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(change_params)
|
||||
end
|
||||
|
||||
last_token = @issue.token_was
|
||||
change_token = last_token - @issue.token
|
||||
change_type = change_token > 0 ? "add" : "minus"
|
||||
post_to_chain(change_type, change_token.abs, current_user.try(:login))
|
||||
end
|
||||
|
||||
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id)
|
||||
|
@ -266,6 +248,10 @@ class IssuesController < ApplicationController
|
|||
|
||||
def destroy
|
||||
if @issue.destroy
|
||||
if @issue.issue_type == "2" && @issue.status_id != 5
|
||||
post_to_chain("add", @issue.token, current_user.try(:login))
|
||||
end
|
||||
|
||||
normal_status(0, "删除成功")
|
||||
else
|
||||
normal_status(-1, "删除失败")
|
||||
|
@ -273,9 +259,10 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
|
||||
def clean
|
||||
#批量删除,暂时只能删除未悬赏的
|
||||
issue_ids = params[:ids]
|
||||
if issue_ids.present?
|
||||
if Issue.where(id: issue_ids).destroy_all
|
||||
if Issue.where(id: issue_ids, issue_type: "1").destroy_all
|
||||
normal_status(0, "删除成功")
|
||||
else
|
||||
normal_status(-1, "删除失败")
|
||||
|
@ -338,16 +325,7 @@ class IssuesController < ApplicationController
|
|||
@issue&.project_trends&.update_all(action_type: "close")
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
if @issue.issue_type.to_s == "2"
|
||||
tokens = @issue.token
|
||||
change_params = {
|
||||
type: "add",
|
||||
chain_params: {
|
||||
amount: tokens,
|
||||
reponame: @project.try(:identifer),
|
||||
username: @issue.get_assign_user.try(:login)
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(change_params)
|
||||
post_to_chain("add", @issue.token, @issue.get_assign_user.try(:login))
|
||||
end
|
||||
if @issue.issue_classify.to_s == "pull_request"
|
||||
@issue&.pull_request&.update_attribute(:status, 2)
|
||||
|
@ -480,4 +458,16 @@ class IssuesController < ApplicationController
|
|||
project_id: @project.id
|
||||
}
|
||||
end
|
||||
|
||||
def post_to_chain(type, amount,login)
|
||||
change_params = {
|
||||
type: type,
|
||||
chain_params: {
|
||||
amount: amount,
|
||||
reponame: @project.try(:identifier),
|
||||
username: login
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(change_params)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,18 @@
|
|||
module MembersHelper
|
||||
def get_user_token(user_login,reponame)
|
||||
query_params = {
|
||||
type: "query",
|
||||
chain_params: {
|
||||
reponame: reponame,
|
||||
username: user_login
|
||||
}
|
||||
}
|
||||
response = Gitea::Chain::ChainGetService.new(query_params).call
|
||||
|
||||
if response.status == 200
|
||||
return JSON.parse(response.body)["balance"].to_i
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
class PostChainJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
#注 pull_request的 api文档有问题,字段未明确,所以暂时关于pr的参数应该有问题。6-8,hs
|
||||
def perform(chain_params)
|
||||
status = false
|
||||
chain_type = chain_params[:type].to_s
|
||||
|
@ -10,7 +9,7 @@ class PostChainJob < ApplicationJob
|
|||
if status
|
||||
break
|
||||
else
|
||||
response = Gitea::Chain::ChainPostService(chain_params)
|
||||
response = Gitea::Chain::ChainPostService.new(chain_params).call
|
||||
if response.status == 200
|
||||
reponse_body = response&.body
|
||||
messages = reponse_body.present? ? JSON.parse(reponse_body) : "success"
|
||||
|
|
|
@ -13,11 +13,11 @@ class Gitea::Chain::ChainGetService < Gitea::ChainService
|
|||
private
|
||||
|
||||
def request_params
|
||||
Hash.new.merge(data: params["chain_params"])
|
||||
params[:chain_params]
|
||||
end
|
||||
|
||||
def url
|
||||
chain_type = params["type"].to_s
|
||||
chain_type = params[:type].to_s
|
||||
case chain_type
|
||||
when "query"
|
||||
"/repos/amount/query".freeze
|
||||
|
|
|
@ -13,11 +13,11 @@ class Gitea::Chain::ChainPostService < Gitea::ChainService
|
|||
private
|
||||
|
||||
def request_params
|
||||
Hash.new.merge(data: params["chain_params"])
|
||||
Hash.new.merge(data: params[:chain_params])
|
||||
end
|
||||
|
||||
def url
|
||||
chain_type = params["type"].to_s
|
||||
chain_type = params[:type].to_s
|
||||
case chain_type
|
||||
when "create"
|
||||
"/repos/create".freeze
|
||||
|
|
|
@ -18,8 +18,10 @@ class Gitea::ChainService < ApplicationService
|
|||
|
||||
def get(url, params={})
|
||||
conn.get do |req|
|
||||
req.url = "#{request_url}"
|
||||
req.body = params[:data].to_json
|
||||
req.url "#{request_url}"
|
||||
params.each_pair do |key, value|
|
||||
req.params["#{key}"] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class Repositories::CreateService < ApplicationService
|
|||
username: user.try(:login),
|
||||
reponame: @repository.try(:identifier),
|
||||
token_name: @repository.try(:identifier),
|
||||
total_supply: 0
|
||||
total_supply: 1000000
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(chain_params) #创建上链操作
|
||||
|
|
|
@ -3,3 +3,4 @@ json.name user.real_name
|
|||
json.login user.login
|
||||
json.image_url url_to_avatar(user)
|
||||
json.email user.try(:mail)
|
||||
json.token get_user_token(user.try(:login),@project.try(:identifier))
|
||||
|
|
|
@ -4,7 +4,7 @@ Rails.application.routes.draw do
|
|||
require 'admin_constraint'
|
||||
# mount Sidekiq::Web => '/sidekiq'
|
||||
|
||||
mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new
|
||||
mount Sidekiq::Web => '/sidekiq'
|
||||
|
||||
get 'attachments/download/:id', to: 'attachments#show'
|
||||
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeIssueToken < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :issues, :token, :integer, default: 0
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue