fix first reply error

This commit is contained in:
thomaschen 2013-09-27 17:03:09 +08:00
parent 696134aa18
commit 660960f316
1 changed files with 30 additions and 0 deletions

View File

@ -17,6 +17,36 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
if @ask_question.ask_reply.send_email?
Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id)
end
status_stack = []
new_status = ""
params[:school][:depts].each do |dns|
begin
status_stack << send_request(dns, @ask_question, @ask_reply)
rescue
status_stack << "fail"
end
end unless params[:school].nil?
success_count = status_stack.count("success")
failed_count = status_stack.count("fail")
if failed_count == 0 && success_count > 0
new_status = "轉介其他單位"
elsif failed_count > 0 && success_count > 0
new_status = "部份轉介失敗"
elsif failed_count > 0 && success_count == 0
new_status = "轉介失敗"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "待處理"
new_status = "待處理"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "已處理"
new_status = "已處理"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "轉介其他單位"
new_status = "轉介失敗"
end
@ask_reply.update_attributes(status: new_status)
redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success')
end