问卷的多选提交判断

dev_forum
SylorHuang 5 years ago
parent cf10b2cbc7
commit 6ffa26bc3a

@ -147,17 +147,9 @@ class PollVotesController < ApplicationController
else else
question_max_choices = 0 question_max_choices = 0
end end
if @poll_question.min_choices.present?
question_min_choices = @poll_question.min_choices
else
question_min_choices = 0
end
if question_max_choices > 0 && (user_vote_count > question_max_choices) if question_max_choices > 0 && (user_vote_count > question_max_choices)
normal_status(-1,"多选题答案超过最大限制!") normal_status(-1,"多选题答案超过最大限制!")
end end
if question_min_choices > 0 && (user_vote_count < question_min_choices)
normal_status(-1,"多选题答题不得少于最小限制!")
end
elsif (poll_user.present? && poll_user.commit_status == 1) || poll_user_status == 3 elsif (poll_user.present? && poll_user.commit_status == 1) || poll_user_status == 3
normal_status(-1,"已提交/已结束的问卷不允许修改!") normal_status(-1,"已提交/已结束的问卷不允许修改!")
end end

@ -896,6 +896,23 @@ class PollsController < ApplicationController
def commit_poll def commit_poll
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@poll_multi_questions = @poll.poll_questions.where(question_type:2).select(:id,:max_choices,:min_choices,:question_number)
error_question = []
@poll_multi_questions.each do |q|
poll_user_votes = current_user.poll_votes.where(question_id:q.id)&.size
if q.max_choices.present? && (poll_user_votes > q.max_choices)
error_messages = "#{q.question_number}题:超过最大选项限制"
elsif q.min_choices.present? && (poll_user_votes < q.min_choices)
error_messages = "#{q.question_number}题:不得少于最小选项限制"
else
error_messages = nil
end
error_question.push(error_messages)
end
error_question = error_question.reject(&:blank?)
if error_question.reject(&:blank?).length > 0
normal_status(-1, "#{error_question.join("\n")}")
else
poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first
poll_user_params = { poll_user_params = {
:commit_status => 1, :commit_status => 1,
@ -903,6 +920,7 @@ class PollsController < ApplicationController
} }
poll_user_current.update_attributes(poll_user_params) poll_user_current.update_attributes(poll_user_params)
normal_status(0, "问卷提交成功!") normal_status(0, "问卷提交成功!")
end
## 需添加发送消息的接口,稍后添加 ## 需添加发送消息的接口,稍后添加
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)

Loading…
Cancel
Save