加入课程

This commit is contained in:
guange 2016-06-22 16:42:20 +08:00
parent 8129e29d5b
commit 7700445c17
6 changed files with 74 additions and 28 deletions

View File

@ -97,15 +97,13 @@ module Mobile
desc "加入课程"
params do
optional :openid, type: String, desc: '微信ID'
requires :token, type: String
requires :invite_code, type: String, desc: '邀请码'
end
post "join" do
authenticate!
cs = CoursesService.new
status = cs.join_course({openid: params[:openid], invite_code: params[:invite_code]}, current_user)
{
status: status[:state],
messsge:CoursesService::JoinCourseError.message(status[:state])

View File

@ -8,12 +8,14 @@ class WechatsController < ActionController::Base
# default text responder when no other match
on :text do |request, content|
#邀请码
if join_class(content)
uw = user_binded?(request[:FromUserName])
if !uw
sendBind()
elsif (course = join_class(content, uw.user)) && course
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!',
content: "课程名称: 数据结构\n班级名称: 数据结构A班\n任课老师: 尹刚\n进入班级,和小伙伴愉快的学习吧!"} }
content: "课程名称: #{course.name}\n班级名称: #{course.name}\n任课老师: #{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} }
request.reply.news(news) do |article, n, index| # article is return object
url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect"
url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities?id='+course.id}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect"
pic_url = "#{ROOT_URL}/images/wechat/class.jpg"
article.item title: "#{n[:title]}",
description: n[:content],
@ -179,8 +181,11 @@ class WechatsController < ActionController::Base
end
end
def join_class(content)
true
def join_class(content, user)
cs = CoursesService.new
status = cs.join_course({invite_code: content.trim}, current_user)
logger.info status
status[:state] == 0 ? status[:course] : nil
end
### controller method

View File

@ -25,25 +25,26 @@
<script src="https://dn-demotest.qbox.me/angular.all.min.js"></script>
<!--<script src="/javascripts/wechat/build/angular.all.min.js"></script>-->
<script src="/javascripts/wechat/build/app.min.js"></script>
<!--<script src="/javascripts/wechat/app.js"></script>-->
<!--<script src="/javascripts/wechat/others/factory.js"></script>-->
<!--<script src="/javascripts/wechat/others/filter.js"></script>-->
<!--<script src="/javascripts/wechat/directives/alert.js"></script>-->
<!--<script src="/javascripts/wechat/directives/form_validate.js"></script>-->
<!--<script src="/javascripts/wechat/directives/input_auto.js"></script>-->
<!--<script src="/javascripts/wechat/directives/loading_spinner.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/reg.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/login.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/activity.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/add_class.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/blog.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/course_notice.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/discussion.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/homework.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/issue.js"></script>-->
<!--<script src="/javascripts/wechat/controllers/journals.js"></script>-->
<!--<script src="/javascripts/wechat/others/routes.js"></script>-->
<!--<script src="/javascripts/wechat/build/app.min.js"></script>-->
<script src="/javascripts/wechat/app.js"></script>
<script src="/javascripts/wechat/others/factory.js"></script>
<script src="/javascripts/wechat/others/filter.js"></script>
<script src="/javascripts/wechat/directives/alert.js"></script>
<script src="/javascripts/wechat/directives/form_validate.js"></script>
<script src="/javascripts/wechat/directives/input_auto.js"></script>
<script src="/javascripts/wechat/directives/loading_spinner.js"></script>
<script src="/javascripts/wechat/controllers/reg.js"></script>
<script src="/javascripts/wechat/controllers/login.js"></script>
<script src="/javascripts/wechat/controllers/activity.js"></script>
<script src="/javascripts/wechat/controllers/add_class.js"></script>
<script src="/javascripts/wechat/controllers/blog.js"></script>
<script src="/javascripts/wechat/controllers/course_notice.js"></script>
<script src="/javascripts/wechat/controllers/discussion.js"></script>
<script src="/javascripts/wechat/controllers/homework.js"></script>
<script src="/javascripts/wechat/controllers/issue.js"></script>
<script src="/javascripts/wechat/controllers/journals.js"></script>
<script src="/javascripts/wechat/controllers/myclass.js"></script>
<script src="/javascripts/wechat/others/routes.js"></script>
</body>
</html>

View File

@ -0,0 +1,32 @@
<div class="post-container">
<div class="class-detail-name">分布式计算环境A班<span class="f13 blue-title-sub">邀请码</span></div>
<div class="slice3 fl"></div>
<div id="class_tab_1" ng-class="['class-detail-tab3',{'class-tab-active':currentTab==1}]" ng-click="tab(1);"><a herf="javascript:void(0);">课堂资源</a></div>
<div class="slice2 fl">
<div class="slice-line2"></div>
</div>
<div id="class_tab_2" ng-class="['class-detail-tab3',{'class-tab-active':currentTab==2}]" ng-click="tab(2);"><a herf="javascript:void(0);">我的同学</a></div>
<div class="slice3 fl"></div>
<div class="cl"></div>
<div class="class-search-wrap">
<div class="class-search-inner"> <img src="/images/wechat/search.png" width="18" class="class-search-icon" />
<input class="class-detail-search" placeholder="输入关键词进行搜索" />
</div>
</div>
<div ng-class="{'undis': currentTab!=1}">
<div class="class-detail-row border-top f13 c-grey3"><span class="fl ml10">资源名称001</span></div>
<div class="class-detail-row f13 c-grey3"><span class="fl ml10">资源名称002</span></div>
<div class="class-detail-row f13 c-grey3"><span class="fl ml10">资源名称003</span></div>
<div class="class-detail-row f13 c-grey3"><span class="fl ml10">资源名称004</span></div>
<div class="class-detail-row f13 c-grey3"><span class="fl ml10">资源名称005</span></div>
<div class="class-detail-row f13 c-grey3"><span class="fl ml10">资源名称006</span></div>
</div>
<div ng-class="{'undis': currentTab!=2}">
<div class="member-banner f13 c-grey3">授课老师</div>
<div class="class-detail-row f13 c-grey3"><img src="/images/wechat/male.jpg" width="30" class="fl ml10 img-circle mt4" /><span class="fl ml10">jacknudt</span><img src="/images/wechat/male.png" width="15" class="fl ml10 mt10" /></div>
<div class="member-banner f13 mt10 c-grey3">我的同学</div>
<div class="class-detail-row f13 c-grey3"><img src="/images/wechat/male.jpg" width="30" class="fl ml10 img-circle mt4" /><span class="fl ml10">jingquan</span><span class="fr mr10 c-grey2">教辅</span><img src="/images/wechat/male.png" width="15" class="fl ml10 mt10" /></div>
<div class="class-detail-row f13 c-grey3"><img src="/images/wechat/male.jpg" width="30" class="fl ml10 img-circle mt4" /><span class="fl ml10">yuanke</span><img src="/images/wechat/male.png" width="15" class="fl ml10 mt10" /></div>
<div class="class-detail-row f13 c-grey3"><img src="/images/wechat/female.jpg" width="30" class="fl ml10 img-circle mt4" /><span class="fl ml10">sasameimei</span><img src="/images/wechat/female.png" width="15" class="fl ml10 mt10" /></div>
</div>
</div>

View File

@ -1,3 +1,11 @@
app.controller('MyClassController', ['$scope', function($scope){
var vm = $scope;
vm.currentTab = 1;
vm.tab = function(index){
vm.currentTab = index;
console.log(vm.currentTab);
}
}]);

View File

@ -142,6 +142,7 @@ a.underline {text-decoration:underline;}
.slice-line2 {width:1px; height:38px; margin:auto; background:#ccc;}
.class-detail-tab {width:23%; height:38px; line-height:38px; font-size:13px; color:#444; background-color:#fff; float:left; text-align:center; vertical-align:middle; border-bottom:1px solid #ccc;}
.class-detail-tab2 {width:32%; height:38px; line-height:38px; font-size:13px; color:#444; background-color:#fff; float:left; text-align:center; vertical-align:middle; border-bottom:1px solid #ccc;}
.class-detail-tab3 {width:48%; height:38px; line-height:38px; font-size:13px; color:#444; background-color:#fff; float:left; text-align:center; vertical-align:middle; border-bottom:1px solid #ccc;}
.class-tab-active {border-bottom:1px solid #3b94d6;}
.class-search-wrap {padding:8px 12px; position:relative;}
.class-search-inner {padding:0 30px; background-color:#fff;}
@ -151,6 +152,7 @@ a.underline {text-decoration:underline;}
.class-detail-row {width:100%; height:38px; line-height:38px; vertical-align:middle; border-bottom:1px solid #ccc; background-color:#fff;}
.class-test-tip {text-align:center; font-size:13px; color:#444; padding-top:40px;}
.img-circle {border-radius:50%;}
.member-banner {height:24px; line-height:24px; text-align:center; vertical-align:middle; background-color:#dfdfdf;}
/*20160614班级列表*/
.course-list-row {width:100%; height:38px; line-height:38px; vertical-align:middle; border-top:1px solid #ccc; border-bottom:1px solid #ccc; background-color:#fff;}