forgeplus/app/controllers/notices_controller.rb

34 lines
1.2 KiB
Ruby
Raw Normal View History

2022-02-17 18:28:32 +08:00
class NoticesController < ApplicationController
def create
2022-05-31 16:34:08 +08:00
return tip_exception("参数有误") if params["source"].blank?
2022-02-17 18:28:32 +08:00
user_id = params[:user_id]
if params["source"] == "CompetitionBegin"
competition_id = params[:competition_id]
SendTemplateMessageJob.perform_later('CompetitionBegin', user_id, competition_id)
elsif params["source"] == "CompetitionResult"
competition_id = params[:competition_id]
SendTemplateMessageJob.perform_later('CompetitionResult', user_id, competition_id)
2022-02-21 16:46:40 +08:00
elsif params["source"] == "CompetitionReview"
2022-02-17 18:28:32 +08:00
competition_id = params[:competition_id]
2022-02-21 16:46:40 +08:00
SendTemplateMessageJob.perform_later('CompetitionReview', user_id, competition_id)
2022-05-31 16:34:08 +08:00
elsif params["source"] == "CustomTip"
users_id = params[:users_id]
props = params[:props].to_unsafe_hash
return tip_exception("参数有误") unless props.is_a?(Hash) && users_id.is_a?(Array)
template_id = params[:template_id]
SendTemplateMessageJob.perform_later('CustomTip', users_id, template_id, props)
2022-02-17 18:28:32 +08:00
else
tip_exception("#{params["source"]}未配置")
end
render_ok
end
2022-05-31 16:34:08 +08:00
private
def params_props
params.require(:notice).permit(:props)
end
2022-02-17 18:28:32 +08:00
end