|
|
@ -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)
|
|
|
|