From 7700445c178938c23db5f0dbde9b9a8d4d6b780e Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 22 Jun 2016 16:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 4 +- app/controllers/wechats_controller.rb | 17 +++++--- app/views/wechats/user_activities.html.erb | 39 ++++++++++--------- public/assets/wechat/myclass.html | 32 +++++++++++++++ .../javascripts/wechat/controllers/myclass.js | 8 ++++ public/stylesheets/weui/weixin.css | 2 + 6 files changed, 74 insertions(+), 28 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index b585e7dae..de2e48c8e 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -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]) diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index b1bab6c56..f6e73e088 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -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 diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index f920aed4b..b5bd82fc5 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -25,25 +25,26 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/assets/wechat/myclass.html b/public/assets/wechat/myclass.html index e69de29bb..25d29008a 100644 --- a/public/assets/wechat/myclass.html +++ b/public/assets/wechat/myclass.html @@ -0,0 +1,32 @@ +
+
分布式计算环境A班邀请码
+
+
课堂资源
+
+
+
+
我的同学
+
+
+
+
+ +
+
+
+
资源名称001
+
资源名称002
+
资源名称003
+
资源名称004
+
资源名称005
+
资源名称006
+
+
+
授课老师
+
jacknudt
+
我的同学
+
jingquan教辅
+
yuanke
+
sasameimei
+
+
diff --git a/public/javascripts/wechat/controllers/myclass.js b/public/javascripts/wechat/controllers/myclass.js index f6cd77e17..cb5cf9037 100644 --- a/public/javascripts/wechat/controllers/myclass.js +++ b/public/javascripts/wechat/controllers/myclass.js @@ -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); + } + }]); \ No newline at end of file diff --git a/public/stylesheets/weui/weixin.css b/public/stylesheets/weui/weixin.css index ab8081173..12e11b5fa 100644 --- a/public/stylesheets/weui/weixin.css +++ b/public/stylesheets/weui/weixin.css @@ -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;}