dev_trainings
cxt 6 years ago
parent 1fe13e8f4a
commit 15e50f3ee3

@ -8,6 +8,9 @@ class TrainingsController < ApplicationController
# ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}" # ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}"
# #
# before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback] # before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback]
#
before_filter :find_tag_id
before_filter :find_training, only: [:show, :test] before_filter :find_training, only: [:show, :test]
before_filter :valid_training, only: [:pay, :result, :pay_js] before_filter :valid_training, only: [:pay, :result, :pay_js]
@ -15,18 +18,18 @@ class TrainingsController < ApplicationController
layout 'base_trainings' layout 'base_trainings'
TAG_ID = 'bigdata_hnjcxy_2019' # TAG_ID = 'bigdata_hnjcxy_2019'
def show def show
@training = current_training @training = current_training
url = nil url = nil
if @training && !@training.pay? if @training && !@training.pay?
url = enroll_training_path(id: TAG_ID) url = enroll_training_path(id: @tag_id)
elsif @training && @training.pay? elsif @training && @training.pay?
url = result_training_path(id: TAG_ID) url = result_training_path(id: @tag_id)
else else
url = enroll_training_path(id: TAG_ID) url = enroll_training_path(id: @tag_id)
end end
redirect_to url redirect_to url
@ -45,7 +48,7 @@ class TrainingsController < ApplicationController
# 防止重复支付,对于已支付过的,不应该再到这个页来 # 防止重复支付,对于已支付过的,不应该再到这个页来
if @training.payed? if @training.payed?
redirect_to result_training_path(id: TAG_ID) redirect_to result_training_path(id: @tag_id)
return return
end end
@ -100,11 +103,15 @@ class TrainingsController < ApplicationController
def create def create
@training = current_training || Training.new(params) @training = current_training || Training.new(params)
@training.training_type = Training::Training_Type @training.training_type = @training_type
if @training_type == 3
@training.research_field = params[:research_field].reject(&:blank?).uniq.join(",")
end
@training.openid = session[:wechat_open_id] @training.openid = session[:wechat_open_id]
@training.save! @training.save!
redirect_to pay_training_path(id: TAG_ID) redirect_to enroll_training_path(id: @tag_id)
# redirect_to pay_training_path(id: @tag_id)
end end
@ -116,7 +123,7 @@ class TrainingsController < ApplicationController
end end
@training.update_attributes(params) @training.update_attributes(params)
redirect_to pay_training_path(id: TAG_ID) redirect_to pay_training_path(id: @tag_id)
end end
@ -168,7 +175,7 @@ class TrainingsController < ApplicationController
if params[:js] == 'true' if params[:js] == 'true'
_pay_js(training_info.fee) _pay_js(training_info.fee)
else else
redirect_to url = result_training_path(id: TAG_ID) redirect_to url = result_training_path(id: @tag_id)
end end
end end
@ -232,11 +239,11 @@ class TrainingsController < ApplicationController
url = '' url = ''
if !@training if !@training
url = training_path(id: TAG_ID) url = training_path(id: @tag_id)
elsif !@training.pay? elsif !@training.pay?
url = enroll_training_path(id: TAG_ID) url = enroll_training_path(id: @tag_id)
else else
url = result_training_path(id: TAG_ID) url = result_training_path(id: @tag_id)
end end
redirect_to url redirect_to url
@ -262,8 +269,14 @@ class TrainingsController < ApplicationController
end end
end end
def find_tag_id
@tag_id = params[:id]
@training_type = @tag_id == "aeee0601_2019" ? 3 : @tag_id == "ceeaa06_2019" ? 4 : 0
render_404 if @training_type == 0
end
def find_training def find_training
if params[:id] == TAG_ID if params[:id] == @tag_id
@training = current_training @training = current_training
else else
render_404 render_404
@ -271,12 +284,12 @@ class TrainingsController < ApplicationController
end end
def current_training def current_training
Training.where(openid: session[:wechat_open_id], training_type: Training::Training_Type).first Training.where(openid: session[:wechat_open_id], training_type: @training_type).first
end end
def valid_training def valid_training
unless current_training unless current_training
redirect_to training_path(id: TAG_ID) redirect_to training_path(id: @tag_id)
end end
end end

@ -3,7 +3,7 @@ class Training < ActiveRecord::Base
attr_accessible :address, :email, :name, :phone, :position, :school, :sex, :openid, :training_type, attr_accessible :address, :email, :name, :phone, :position, :school, :sex, :openid, :training_type,
:major, :student_id :major, :student_id
# training_type 1 2018-培训会 2 警察学院大数据培训会 # training_type 1 2018-培训会 2 警察学院大数据培训会 3 大数据和人工智能 4 工程教育认证
has_one :training_payinfo has_one :training_payinfo

@ -1,19 +1,19 @@
<% if false %> <% if false %>
<div> <div>
<p class="collegeInfo">湖南警察学院大数据培训缴费</p> <p class="collegeInfo">湖南警察学院大数据培训缴费</p>
<%= form_for @training do |f| %> <%= form_for @training do |f| %>
<p class="subtitle">基本信息</p> <p class="subtitle">基本信息</p>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">姓名</span> <span class="left_tag fl">姓名</span>
<input type="text" class="right_input" id="username" name="name" <input type="text" class="right_input" id="username" name="name"
placeholder="请输入真实姓名" value="<%= @training.name %>"/> placeholder="请输入真实姓名" value="<%= @training.name %>"/>
</li> </li>
<li class="clearfix infoBar" id="userSex" NavShow> <li class="clearfix infoBar" id="userSex" NavShow>
<span class="left_tag fl">性别</span> <span class="left_tag fl">性别</span>
<label class="fr" id="sexl" style="margin-right: 24px;"><%= @training.sex == 1 ? '男' : '女' %></label> <label class="fr" id="sexl" style="margin-right: 24px;"><%= @training.sex == 1 ? '男' : '女' %></label>
<i class="iconfont icon-youjiantou rightArrow"></i> <i class="iconfont icon-youjiantou rightArrow"></i>
<input type="hidden" id="sex" name="sex" value="<%= @training.sex ==1 ?1 : 2 %>"> <input type="hidden" id="sex" name="sex" value="<%= @training.sex == 1 ? 1 : 2 %>">
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">专业</span> <span class="left_tag fl">专业</span>
<input type="text" class="right_input" id="userMajor" placeholder="请输入专业" <input type="text" class="right_input" id="userMajor" placeholder="请输入专业"
@ -26,19 +26,19 @@
name="student_id" name="student_id"
value="<%= @training.student_id %>"/> value="<%= @training.student_id %>"/>
</li> </li>
<!--<li class="clearfix infoBar"> <!--<li class="clearfix infoBar">
<span class="left_tag fl">单位</span> <span class="left_tag fl">单位</span>
<input type="text" class="right_input" id="userunit" placeholder="请输入单位名称或学校" <input type="text" class="right_input" id="userunit" placeholder="请输入单位名称或学校"
name="school" name="school"
value="<%#= @training.school %>"/> value="<%#= @training.school %>"/>
</li>--> </li>-->
<!--<li class="clearfix infoBar"> <!--<li class="clearfix infoBar">
<span class="left_tag fl">职称</span> <span class="left_tag fl">职称</span>
<input type="text" class="right_input" id="usertitle" placeholder="请输入职称" <input type="text" class="right_input" id="usertitle" placeholder="请输入职称"
name="position" name="position"
value="<%#= @training.position %>"/> value="<%#= @training.position %>"/>
</li>--> </li>-->
<!--<p class="subtitle">通讯地址</p> <!--<p class="subtitle">通讯地址</p>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
&lt;!&ndash; <div class="clearfix" id="userArea" NavShow>&ndash;&gt; &lt;!&ndash; <div class="clearfix" id="userArea" NavShow>&ndash;&gt;
&lt;!&ndash; <span class="left_tag fl">地区</span>&ndash;&gt; &lt;!&ndash; <span class="left_tag fl">地区</span>&ndash;&gt;
@ -49,178 +49,182 @@
id="DetailAdd"><%#= @training.address %></textarea> id="DetailAdd"><%#= @training.address %></textarea>
</li>--> </li>-->
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">手机号码</span> <span class="left_tag fl">手机号码</span>
<input type="text" class="right_input" placeholder="请输入手机号" id="userphone" <input type="text" class="right_input" placeholder="请输入手机号" id="userphone"
name="phone" name="phone"
value="<%= @training.phone %>"/> value="<%= @training.phone %>"/>
</li> </li>
<!--<li class="clearfix infoBar"> <!--<li class="clearfix infoBar">
<span class="left_tag fl">Email</span> <span class="left_tag fl">Email</span>
<input type="text" class="right_input" placeholder="请输入Email" id="userEmail" <input type="text" class="right_input" placeholder="请输入Email" id="userEmail"
name="email" name="email"
value="<%#= @training.email %>"/> value="<%#= @training.email %>"/>
</li>--> </li>-->
<p style="height: 50px;"></p> <p style="height: 50px;"></p>
<a href="javascript:void(0)" class="EnrollNext" onclick="NextStep();">下一步</a> <a href="javascript:void(0)" class="EnrollNext" onclick="NextStep();">下一步</a>
<% end %> <% end %>
</div> </div>
<div class="sexDownNav downNav"> <div class="sexDownNav downNav">
<li>男</li> <li>男</li>
<li>女</li> <li>女</li>
</div> </div>
<script> <script>
$(function () { $(function () {
var down = $('#userSex'); var down = $('#userSex');
var downNav = $(".sexDownNav"); var downNav = $(".sexDownNav");
showNav(down, downNav, "down"); showNav(down, downNav, "down");
$(".sexDownNav li").on("click", function () { $(".sexDownNav li").on("click", function () {
$(down).find("#sexl").html($(this).html()); $(down).find("#sexl").html($(this).html());
hideNav(downNav); hideNav(downNav);
if ($(this).html()=='男'){ if ($(this).html() == '男') {
$('#sex').val("1"); $('#sex').val("1");
} else { } else {
$('#sex').val("2"); $('#sex').val("2");
} }
}) })
}) })
//下一步 //下一步
function NextStep() { function NextStep() {
var username = $("#username").val(); var username = $("#username").val();
var userMajor = $("#userMajor").val(); var userMajor = $("#userMajor").val();
var userphone = $("#userphone").val(); var userphone = $("#userphone").val();
var userID = $("#userID").val(); var userID = $("#userID").val();
if (username == '') { if (username == '') {
alert("请输入真实姓名"); alert("请输入真实姓名");
return; return;
} }
if (userMajor == '') { if (userMajor == '') {
alert("请输入专业"); alert("请输入专业");
return; return;
} }
if (userID == '') { if (userID == '') {
alert("请输入学号"); alert("请输入学号");
return; return;
} }
if (userphone == '') { if (userphone == '') {
alert("请输入手机号码"); alert("请输入手机号码");
return; return;
} else if (!/^1\d{10}$/.test(userphone) && !/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(userphone)) { } else if (!/^1\d{10}$/.test(userphone) && !/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(userphone)) {
alert("请输入正确的手机号码"); alert("请输入正确的手机号码");
return; return;
} }
$('form').submit(); $('form').submit();
} }
</script> </script>
<% end %> <% end %>
<div> <div>
<p class="collegeInfo">信息技术新工科产学研联盟师资培训班</p> <p class="collegeInfo">信息技术新工科产学研联盟师资培训班</p>
<%= form_for @training do |f| %> <%= form_for @training do |f| %>
<p class="subtitle">基本信息</p> <p class="subtitle">基本信息</p>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">姓名</span> <span class="left_tag fl">姓名</span>
<input type="text" class="right_input" id="username" name="name" <input type="text" class="right_input" id="username" name="name"
placeholder="请输入真实姓名" value="<%= @training.name %>"/> placeholder="请输入真实姓名" value="<%= @training.name %>"/>
</li> </li>
<li class="clearfix infoBar" id="userSex" NavShow> <li class="clearfix infoBar" id="userSex" NavShow>
<span class="left_tag fl">性别</span> <span class="left_tag fl">性别</span>
<label class="fr" id="sexl" style="margin-right: 24px;"><%= @training.sex == 1 ? '男' : '女' %></label> <label class="fr" id="sexl" style="margin-right: 24px;"><%= @training.sex == 1 ? '男' : '女' %></label>
<i class="iconfont icon-youjiantou rightArrow"></i> <i class="iconfont icon-youjiantou rightArrow"></i>
<input type="hidden" id="sex" name="sex" value="<%= @training.sex ==1 ?1 : 2 %>"> <input type="hidden" id="sex" name="sex" value="<%= @training.sex == 1 ? 1 : 2 %>">
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">单位</span> <span class="left_tag fl">单位</span>
<input type="text" class="right_input" id="userUnit" placeholder="请输入单位名称或者学校" <input type="text" class="right_input" id="userUnit" placeholder="请输入单位名称或者学校"
name="major" name="major"
value="<%= @training.major %>"/> value="<%= @training.major %>"/>
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">职称</span> <span class="left_tag fl">职称</span>
<input type="text" class="right_input" id="userPositional" placeholder="请输入职称" <input type="text" class="right_input" id="userPositional" placeholder="请输入职称"
name="student_id" name="student_id"
value="<%= @training.student_id %>"/> value="<%= @training.student_id %>"/>
</li> </li>
<% if @training_type == 3 %>
<p class="subtitle">您的授课/研究领域最少选1项</p> <p class="subtitle">您的授课/研究领域最少选1项</p>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">机器学习/深度学习</span> <span class="left_tag fl">机器学习/深度学习</span>
<span class="fr"> <span class="fr">
<input type="checkbox" name="study" value="1" id="check_1" class="magic-checkbox"> <input type="checkbox" name="research_field[]" value="机器学习/深度学习" id="check_1" class="magic-checkbox">
<label for="check_1" style="top:8px">&nbsp;</label> <label for="check_1" style="top:8px">&nbsp;</label>
</span> </span>
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">计算机结构与组成</span> <span class="left_tag fl">计算机结构与组成</span>
<span class="fr"> <span class="fr">
<input type="checkbox" name="study" value="2" id="check_2" class="magic-checkbox"> <input type="checkbox" name="research_field[]" value="计算机结构与组成" id="check_2" class="magic-checkbox">
<label for="check_2" style="top:8px">&nbsp;</label> <label for="check_2" style="top:8px">&nbsp;</label>
</span> </span>
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">计算机系统</span> <span class="left_tag fl">计算机系统</span>
<span class="fr"> <span class="fr">
<input type="checkbox" name="study" value="3" id="check_3" class="magic-checkbox"> <input type="checkbox" name="research_field[]" value="计算机系统" id="check_3" class="magic-checkbox">
<label for="check_3" style="top:8px">&nbsp;</label> <label for="check_3" style="top:8px">&nbsp;</label>
</span> </span>
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">计算机软件技术和应用</span> <span class="left_tag fl">计算机软件技术和应用</span>
<span class="fr"> <span class="fr">
<input type="checkbox" name="study" value="4" id="check_4" class="magic-checkbox"> <input type="checkbox" name="research_field[]" value="计算机软件技术和应用" id="check_4" class="magic-checkbox">
<label for="check_4" style="top:8px">&nbsp;</label> <label for="check_4" style="top:8px">&nbsp;</label>
</span> </span>
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">计算机理论</span> <span class="left_tag fl">计算机理论</span>
<span class="fr"> <span class="fr">
<input type="checkbox" name="study" value="5" id="check_5" class="magic-checkbox"> <input type="checkbox" name="research_field[]" value="计算机理论" id="check_5" class="magic-checkbox">
<label for="check_5" style="top:8px">&nbsp;</label> <label for="check_5" style="top:8px">&nbsp;</label>
</span> </span>
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">计算机应用与学科交叉</span> <span class="left_tag fl">计算机应用与学科交叉</span>
<span class="fr"> <span class="fr">
<input type="checkbox" name="study" value="6" id="check_6" class="magic-checkbox"> <input type="checkbox" name="research_field[]" value="计算机应用与学科交叉" id="check_6" class="magic-checkbox">
<label for="check_6" style="top:8px">&nbsp;</label> <label for="check_6" style="top:8px">&nbsp;</label>
</span> </span>
</li> </li>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
<span class="left_tag fl">其他</span> <span class="left_tag fl">其他</span>
<span class="fr"> <span class="fr">
<input type="checkbox" name="study" value="7" id="check_7" class="magic-checkbox"> <input type="checkbox" name="research_field[]" value="其他" id="check_7" class="magic-checkbox">
<label for="check_7" style="top:8px">&nbsp;</label> <label for="check_7" style="top:8px">&nbsp;</label>
</span> </span>
</li> </li>
<p class="subtitle">通讯地址</p> <% end %>
<li class="clearfix infoBar">
<!--<div class="clearfix" id="userArea" NavShow>--> <p class="subtitle">通讯地址</p>
<!--<span class="left_tag fl">地区</span>--> <li class="clearfix infoBar">
<!--<input type="text" class="right_input" id="usertitle" placeholder="填写区域"/>--> <!--<div class="clearfix" id="userArea" NavShow>-->
<!--<i class="iconfont icon-youjiantou rightArrow"></i>--> <!--<span class="left_tag fl">地区</span>-->
<!--</div>--> <!--<input type="text" class="right_input" id="usertitle" placeholder="填写区域"/>-->
<textarea class="DetailAddress" placeholder="请输入详细地址" name="address" id="DetailAdd" style="margin-top: 15px;"><%#= @training.address %></textarea> <!--<i class="iconfont icon-youjiantou rightArrow"></i>-->
</li> <!--</div>-->
<li class="clearfix infoBar"> <textarea class="DetailAddress" placeholder="请输入详细地址" name="address" id="DetailAdd" style="margin-top: 15px;"><%= @training.address %></textarea>
<span class="left_tag fl">手机号码</span> </li>
<input type="text" class="right_input" placeholder="请输入手机号" id="userphone" <li class="clearfix infoBar">
name="phone" <span class="left_tag fl">手机号码</span>
value="<%= @training.phone %>"/> <input type="text" class="right_input" placeholder="请输入手机号" id="userphone"
</li> name="phone"
<li class="clearfix infoBar"> value="<%= @training.phone %>"/>
<span class="left_tag fl">Email</span> </li>
<input type="text" class="right_input" placeholder="请输入Email" id="userEmail" name="email" value="<%#= @training.email %>"/> <li class="clearfix infoBar">
</li> <span class="left_tag fl">Email</span>
<p style="height: 50px;"></p> <input type="text" class="right_input" placeholder="请输入Email" id="userEmail" name="email" value="<%= @training.email %>"/>
<a href="javascript:void(0)" class="EnrollNext" onclick="NextStep();">完成</a> </li>
<p style="height: 50px;"></p>
<a href="javascript:void(0)" class="EnrollNext" onclick="NextStep();">完成</a>
<% end %> <% end %>
</div> </div>
@ -238,9 +242,9 @@
$(down).find("#sexl").html($(this).html()); $(down).find("#sexl").html($(this).html());
hideNav(downNav); hideNav(downNav);
if ($(this).html()=='男'){ if ($(this).html() == '男') {
$('#sex').val("1"); $('#sex').val("1");
} else { } else {
$('#sex').val("2"); $('#sex').val("2");
} }
}) })

@ -0,0 +1,5 @@
class AddReseachFieldToTrainings < ActiveRecord::Migration
def change
add_column :trainings, :research_field, :string
end
end
Loading…
Cancel
Save