From 6c71994e3309406e58da0e9fcbfcb82001aedabd Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 18:11:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=82=AC=E8=B5=8F?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E5=8F=98=E6=9B=B4=E9=9C=80=E8=A6=81=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E8=87=B3=E9=93=BE=E4=B8=8A=E4=BB=A5=E5=8F=8A=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=96=91=E4=BF=AE=E6=96=B0=E5=A2=9E=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 2 ++ app/models/pull_attached_issue.rb | 1 + app/services/api/v1/issues/concerns/checkable.rb | 4 ++-- app/services/api/v1/issues/update_service.rb | 10 +++++++++- ...20230309095515_add_fixed_to_pull_attached_issues.rb | 5 +++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index e9db3a487..47e55af15 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -227,11 +227,13 @@ class PullRequestsController < ApplicationController # 查看是否fix了相关issue,如果fix就转账 @pull_request.attached_issues.each do |issue| + next if PullAttachedIssue.exist?(issue_id: issue.id, fixed: true) token_num = issue.blockchain_token_num token_num = token_num.nil? ? 0 : token_num author_id = @pull_request.user_id if token_num > 0 Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: @project.id.to_s, token_num: token_num}) if Site.has_blockchain? && @project.use_blockchain + PullAttachedIssue.find_by(issue_id: issue.id, pull_request_id: @pull_request.id).update(fixed: true) end # update issue to state 5 issue.update(status_id: 5) diff --git a/app/models/pull_attached_issue.rb b/app/models/pull_attached_issue.rb index c93a95d65..abc6c3448 100644 --- a/app/models/pull_attached_issue.rb +++ b/app/models/pull_attached_issue.rb @@ -7,6 +7,7 @@ # issue_id :integer # created_at :datetime not null # updated_at :datetime not null +# fixed :boolean default("0") # # Indexes # diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index 411b1b7ff..cda01ba25 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -46,8 +46,8 @@ module Api::V1::Issues::Concerns::Checkable raise ApplicationService::Error, "ParentJournal不存在!" unless Journal.find_by_id(parent_id).present? end - def check_blockchain_token_num(user_id, project_id, blockchain_token_num) + def check_blockchain_token_num(user_id, project_id, blockchain_token_num, now_blockchain_token_num=0) left_blockchain_token_num = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id}) rescue 0 - raise ApplicationService::Error, "项目Token不足。" if blockchain_token_num > left_blockchain_token_num + raise ApplicationService::Error, "项目Token不足。" if blockchain_token_num.to_i > (left_blockchain_token_num+now_blockchain_token_num).to_i end end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 3c2600bf3..85190fe95 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -42,7 +42,7 @@ class Api::V1::Issues::UpdateService < ApplicationService check_assigners(assigner_ids) unless assigner_ids.nil? check_attachments(attachment_ids) unless attachment_ids.nil? check_atme_receivers(receivers_login) unless receivers_login.nil? - check_blockchain_token_num(project.user_id, project.id, blockchain_token_num) if blockchain_token_num.present? + check_blockchain_token_num(project.user_id, project.id, blockchain_token_num, @issue.blockchain_token_num) if blockchain_token_num.present? load_assigners(assigner_ids) load_attachments(attachment_ids) load_issue_tags(issue_tag_ids) @@ -71,6 +71,7 @@ class Api::V1::Issues::UpdateService < ApplicationService build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 build_previous_issue_changes + build_cirle_blockchain_token if blockchain_token_num.present? # @信息发送 AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? @@ -134,6 +135,13 @@ class Api::V1::Issues::UpdateService < ApplicationService end end + def build_cirle_blockchain_token + if @updated_issue.previous_changes["blockchain_token_num"].present? + unlock_balance_on_blockchain(@updated_issue.project&.user_id, @updated_issue.project_id, @updated_issue.previous_changes["blockchain_token_num"][0]) + lock_balance_on_blockchain(@updated_issue.project&.user_id, @updated_issue.project_id, @updated_issue.previous_changes["blockchain_token_num"][1]) + end + end + def build_issue_project_trends if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][1] == 5 @updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) diff --git a/db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb b/db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb new file mode 100644 index 000000000..9f9952121 --- /dev/null +++ b/db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb @@ -0,0 +1,5 @@ +class AddFixedToPullAttachedIssues < ActiveRecord::Migration[5.2] + def change + add_column :pull_attached_issues, :fixed, :boolean, default: false + end +end