| @@ -105,44 +105,55 @@ class IssuesController < ApplicationController | |||
| elsif params[:subject].to_s.size > 255 | |||
| normal_status(-1, "标题不能超过255个字符") | |||
| else | |||
| 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 | |||
| ActiveRecord::Base.transaction do | |||
| 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 | |||
| 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 | |||
| 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 | |||
| #为悬赏任务时, 扣除当前用户的积分 | |||
| 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") | |||
| render json: {status: 0, message: "创建成", id: @issue.id} | |||
| else | |||
| normal_status(-1, "创建失败") | |||
| end | |||
| @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create") | |||
| # author: zxh | |||
| # 调用上链API | |||
| success_blockchain = push_activity_2_blockchain("issue_create", @issue) | |||
| if success_blockchain == false | |||
| normal_status(-1, "创建失败") | |||
| raise ActiveRecord::Rollback | |||
| else | |||
| render json: {status: 0, message: "创建成", id: @issue.id} | |||
| end | |||
| else | |||
| normal_status(-1, "创建失败") | |||
| raise ActiveRecord::Rollback | |||
| end | |||
| end | |||
| end | |||
| end | |||