From 7c5240b38653fc597eae9525c3b363f97207d4c1 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 11 Aug 2016 09:58:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=20=E6=B2=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=8A=A8=E6=80=81=E5=9B=9E=E5=A4=8D=E4=BC=9A=E8=B7=B3?= =?UTF-8?q?=E5=88=B0=E7=BB=91=E5=AE=9A=E7=99=BB=E5=BD=95=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E7=A7=81=E6=9C=89=E5=86=85=E5=AE=B9=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=98=AF=E6=88=90=E5=91=98=E6=89=8D=E8=83=BD=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 149 +++++++++++++----- app/api/mobile/apis/newss.rb | 4 +- app/services/courses_service.rb | 36 ++--- app/services/wechat_service.rb | 24 +-- config/wechat.yml.template | 1 - config/wechat.yml.test | 1 - public/assets/wechat/blog_detail.html | 2 +- public/assets/wechat/homework_detail.html | 2 +- public/assets/wechat/login_tip.html | 9 +- public/assets/wechat/reg.html | 2 +- .../javascripts/wechat/controllers/login.js | 10 +- .../wechat/controllers/login_tip..js | 7 + public/javascripts/wechat/controllers/reg.js | 7 +- public/javascripts/wechat/others/factory.js | 20 ++- public/javascripts/wechat/others/routes.js | 1 + 15 files changed, 181 insertions(+), 94 deletions(-) create mode 100644 public/javascripts/wechat/controllers/login_tip..js diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 5b7159301..10308774f 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -14,66 +14,130 @@ module Mobile requires :token, type: String end post ':id' do - authenticate! + # authenticate! + status = 0 + tip = 0 #0班级1项目 type = params[:type] result = 1 if params[:content]!="" && current_user case type when "HomeworkCommon" homework_common = HomeworkCommon.find(params[:id]) - feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) - if (feedback.errors.empty?) - homework_common.update_column(:updated_at, Time.now) - result = 2 + + #如果是私有的 并且不是成员则不能回复 + is_public = homework_common.course.is_public + if is_public == 0 && !current_user.member_of_course?(homework_common.course) + status = -1 + tip = 0 + else + feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) + if (feedback.errors.empty?) + homework_common.update_column(:updated_at, Time.now) + result = 2 + end end + when "News" news = News.find(params[:id]) - comment = Comment.new - comment.comments = params[:content] - comment.author = current_user - if news.comments << comment - result = 2 + + if news.project + if news.project.is_public == false && !current_user.member_of?(news.project) + status = -1 + tip = 1 + end + elsif news.course + if news.course.is_public == 0 && !current_user.member_of_course?(news.course) + status = -1 + tip = 0 + end + end + + if status == 0 + comment = Comment.new + comment.comments = params[:content] + comment.author = current_user + if news.comments << comment + result = 2 + end end when "Message" message = Message.find(params[:id]) board = Board.find(message.board_id) - topic = message.root - reply = Message.new - reply.author = current_user - reply.board = board - reply.content = params[:content] - reply.parent_id = params[:id] - reply.subject = "RE: #{topic.subject}" - if topic.children << reply - result = 2 + + if message.project + if message.project.is_public == false && !current_user.member_of?(message.project) + status = -1 + tip = 1 + end + elsif message.course + if message.course.is_public == 0 && !current_user.member_of_course?(message.course) + status = -1 + tip = 0 + end + end + + if status == 0 + topic = message.root + reply = Message.new + reply.author = current_user + reply.board = board + reply.content = params[:content] + reply.parent_id = params[:id] + reply.subject = "RE: #{topic.subject}" + if topic.children << reply + result = 2 + end end when "JournalsForMessage" jour = JournalsForMessage.find params[:id] - parent_id = params[:id] - author_id = current_user.id - reply_user_id = jour.user_id - reply_id = params[:id] - content = params[:content] - options = {:user_id => author_id, - :status => true, - :m_parent_id => parent_id, - :m_reply_id => reply_id, - :reply_id => reply_user_id, - :notes => content, - :is_readed => false} - jfm = jour.user.add_jour(nil, nil, nil, options) - if jfm.errors.empty? - (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) - result = 2 + + if jour.jour_type == "Project" + if jour.project.is_public == false && !current_user.member_of?(jour.project) + status = -1 + tip = 1 + end + elsif jour.jour_type == "Course" + if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course) + status = -1 + tip = 0 + end + end + + if status == 0 + parent_id = params[:id] + author_id = current_user.id + reply_user_id = jour.user_id + reply_id = params[:id] + content = params[:content] + options = {:user_id => author_id, + :status => true, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + jfm = jour.user.add_jour(nil, nil, nil, options) + if jfm.errors.empty? + (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) + result = 2 + end end when 'Issue' issue = Issue.find params[:id] - is_jour = Journal.new - is_jour.user_id = current_user.id - is_jour.notes = params[:content] - is_jour.journalized = issue - if is_jour.save - result = 2 + + if issue.project.is_public == false && !current_user.member_of?(issue.project) + status = -1 + tip = 1 + end + + if status == 0 + is_jour = Journal.new + is_jour.user_id = current_user.id + is_jour.notes = params[:content] + is_jour.journalized = issue + if is_jour.save + result = 2 + end end when 'BlogComment' blog = BlogComment.find(params[:id]).root @@ -97,7 +161,8 @@ module Mobile result = 3 end present :result, result - present :status, 0 + present :status, status + present :tip, tip end end end diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index 907958631..c2e2fcb5c 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -20,8 +20,8 @@ module Mobile if news.project is_public = news.project.is_public - elsif news.project - is_public = news.project.is_public + elsif news.course + is_public = news.course.is_public end present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 81fe9c5f4..7d574bada 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -537,29 +537,25 @@ class CoursesService count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count if count == 0 ws = WechatService.new - if role_id == 10 && result == 0 + + role_name = role_id == 7 ? "助教" : role_id == 9 ? "教师" : "学生" + result_name = result == 0 ? "通过" : "被拒绝" + content = "您以"+role_name+"身份加入班级的申请已"+result_name+"。" + + if result == 0 title = "恭喜您加入班级成功。" - ws.join_class_notice user.id, "class", course.id,title, course.syllabus.name,course.name,course.teacher.show_name, "点击查看班级详情。" + remark = "点击查看班级详情。" + uid = 0 + type = "class" else - - role_name = role_id == 7 ? "助教" : "教师" - result_name = result == 0 ? "通过" : "被拒绝" - content = "您以"+role_name+"身份加入班级的申请已"+result_name+"。" - - if result == 0 - title = "恭喜您加入班级成功。" - remark = "点击查看班级详情。" - uid = 0 - type = "class" - else - title = "很遗憾您未能成功加入班级。" - remark = "点击查看申请详情。" - uid = user.id - type = "review_class_member" - end - ws = WechatService.new - ws.class_notice user.id, type, course.id, title, course.name, user.show_name, format_time(Time.now), content, remark,uid + title = "很遗憾您未能成功加入班级。" + remark = "点击查看申请详情。" + uid = user.id + type = "review_class_member" end + ws = WechatService.new + ws.class_notice user.id, type, course.id, title, course.name, user.show_name, format_time(Time.now), content, remark,uid + end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 4b120eaa0..4506bf3e4 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -296,18 +296,18 @@ class WechatService end end - def join_class_notice(user_id, type, id, first, key1, key2, key3,remark="") - uw = UserWechat.where(user_id: user_id).first - unless uw.nil? - data = three_keys_template uw.openid,Wechat.config.join_class_notice, type, id, first, key1, key2, key3, remark - begin - req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) - rescue Exception => e - Rails.logger.error "[join_class__notice] ===> #{e}" - end - Rails.logger.info "send over. #{req}" - end - end + # def join_class_notice(user_id, type, id, first, key1, key2, key3,remark="") + # uw = UserWechat.where(user_id: user_id).first + # unless uw.nil? + # data = three_keys_template uw.openid,Wechat.config.join_class_notice, type, id, first, key1, key2, key3, remark + # begin + # req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + # rescue Exception => e + # Rails.logger.error "[join_class__notice] ===> #{e}" + # end + # Rails.logger.info "send over. #{req}" + # end + # end def create_class_notice(user_id, type, id, first, key1, key2, key3, remark="") uw = UserWechat.where(user_id: user_id).first diff --git a/config/wechat.yml.template b/config/wechat.yml.template index f55640d97..ce3008729 100644 --- a/config/wechat.yml.template +++ b/config/wechat.yml.template @@ -23,7 +23,6 @@ default: &default create_class_notice: "2GtJJGzzNlNy2i0UrsjEDlvfSVIUXQfSo47stpcQAVw" create_project_notice: "jYu0iimbDpgWYZaTLXioZe2lvqoWTdKnUPyphTJ1mxs" project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E" - join_class_notice: "0V2vhhp5co7drgoyqn3WXUUTQ9xwYrnVcMma7ika6o0" join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg" production: <<: *default diff --git a/config/wechat.yml.test b/config/wechat.yml.test index a49282c1a..a5339d398 100644 --- a/config/wechat.yml.test +++ b/config/wechat.yml.test @@ -23,7 +23,6 @@ default: &default create_class_notice: "9CDIvHIKiGwPEQWRw_-wieec1o50tMXQPPZIfECKu0I" create_project_notice: "R2ZaQKJfDJgujPcHWPzadKHIRkIyj2CjX2o_qIuRqig" project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc" - join_class__notice: "umHZyT8n6KPf3emf4sTJ66I8OB_TJTzjYhxDbJUgUis" join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M" production: diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index a4c24e3d4..c1e2fd2fd 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -73,7 +73,7 @@
- +
diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html index 34e5e83ed..474fc4f03 100644 --- a/public/assets/wechat/homework_detail.html +++ b/public/assets/wechat/homework_detail.html @@ -73,7 +73,7 @@
- +
diff --git a/public/assets/wechat/login_tip.html b/public/assets/wechat/login_tip.html index 7d16f009f..4495e5a0d 100644 --- a/public/assets/wechat/login_tip.html +++ b/public/assets/wechat/login_tip.html @@ -2,13 +2,12 @@
友情提示
-
-
    +
    +
    • 您还没有绑定,不能直接回复
    • -
    • 绑定
    • +
    • 绑定
    • 想要实时接收动态?
      长按二维码,关注公众号
    -
- +
\ No newline at end of file diff --git a/public/assets/wechat/reg.html b/public/assets/wechat/reg.html index 71b05a399..f42108202 100644 --- a/public/assets/wechat/reg.html +++ b/public/assets/wechat/reg.html @@ -30,7 +30,7 @@
登录名不能为空 - 登录名为1-25个英文字母、数字和下划线 + 不能以下划线开头,不能包括中文,长度不超过25个字符
diff --git a/public/javascripts/wechat/controllers/login.js b/public/javascripts/wechat/controllers/login.js index f8e87a93f..ea86a71a2 100644 --- a/public/javascripts/wechat/controllers/login.js +++ b/public/javascripts/wechat/controllers/login.js @@ -1,6 +1,8 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session','wx', function ($scope, $http, $location, $routeParams, alertService, config, auth,session, wx) { + var tag = $routeParams.tag; + // 登录页不用显示菜音 wx.ready(function(){ wx.hideOptionMenu(); @@ -39,7 +41,13 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams vm.loginFailed = (response.data.status != 0); if (!$scope.loginFailed) { //绑定成功 vm.alertService.showMessage('提示', response.data.message, function(){ - wx.closeWindow(); + if(tag){ + window.history.back(); + tag = null; + } + else{ + wx.closeWindow(); + } }); } else { vm.alertService.showMessage('出错了', response.data.message); diff --git a/public/javascripts/wechat/controllers/login_tip..js b/public/javascripts/wechat/controllers/login_tip..js new file mode 100644 index 000000000..a719abf79 --- /dev/null +++ b/public/javascripts/wechat/controllers/login_tip..js @@ -0,0 +1,7 @@ +app.controller('LoginTipController', ['$scope', '$http', '$location', 'alertService','$location', + function ($scope, $http, $location, alertService, $location) { + $scope.bindWx = function(){ + $location.path("/login").search({tag:1}); + }; + + }]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/reg.js b/public/javascripts/wechat/controllers/reg.js index 9600e9dbf..1247cd931 100644 --- a/public/javascripts/wechat/controllers/reg.js +++ b/public/javascripts/wechat/controllers/reg.js @@ -1,5 +1,5 @@ -app.controller('RegController', ['$scope', '$http', '$location', 'alertService','$location', - function ($scope, $http, $location, alertService, $location) { +app.controller('RegController', ['$scope', '$http', '$location', 'alertService','$location','wx', + function ($scope, $http, $location, alertService, $location,wx) { var vm = $scope; vm.errDialog = alertService.create(); @@ -35,7 +35,8 @@ app.controller('RegController', ['$scope', '$http', '$location', 'alertService', } else { vm.successDialog.showMessage("提示","注册且绑定微信成功", function(){ // $location.path("/activities"); - window.WeixinJSBridge.call('closeWindow'); +// window.WeixinJSBridge.call('closeWindow'); + wx.closeWindow(); }); } }, function (response) { diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index 885b38ed3..801ad23ad 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -94,7 +94,7 @@ app.factory('rms', function(){ }); app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$location', function($http, auth, $routeParams,rms,config,wx,$location){ - var addCommonReply = function(id, type, data, cb){ + var addCommonReply = function(id, type, data,args, cb){ //先判断有没有绑定 $http.post( '/wechat/is_bind', @@ -106,8 +106,6 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc } }); - - if(!data.comment || data.comment.length<=0){ return; } @@ -129,6 +127,19 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc }).then(function successCallback(response) { //alert("提交成功"); //数据提交完成,回复按钮启用 + console.log(response); + if(response.data.status == -1){ + console.log("回复失败!"); + data.comment = ""; + if(response.data.tip == 0){ + args.scope.replytip = "您不是该私有班级成员,不能回复"; + } + else{ + args.scope.replytip = "您不是该私有项目成员,不能回复"; + } + return; + } + data.disabled = false; if(typeof cb === 'function'){ cb(); @@ -209,6 +220,7 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc }; var init = function(args){ + args.scope.replytip = "输入回复内容~"; args.scope.formData = {comment: ''}; var loadData = function(id,replytype,page){ loadCommonData(id, args.type,replytype,page).then(function successCallback(response) { @@ -277,7 +289,7 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc loadData(args.id,0,0); args.scope.addReply = function(data){ console.log(data.comment); - addCommonReply(args.id, args.replyType, data, function(){ + addCommonReply(args.id, args.replyType, data,args, function(){ args.scope.formData = {comment: ''}; loadData(args.id,0,0); if(typeof args.replyCallback === 'function'){ diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js index 7b4a0320b..7311c66c1 100644 --- a/public/javascripts/wechat/others/routes.js +++ b/public/javascripts/wechat/others/routes.js @@ -47,6 +47,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func .when('/project_invite_code', {templateUrl: rootPath + 'project_invite_code.html', controller: 'ProjectInviteCodeController'}) .when('/join_project', makeRoute('join_project.html', 'JoinProjectController')) .when('/review_project_member', makeRoute('review_project_member.html', 'ReviewProjectMemberController')) + .when('/login_tip', makeRoute('login_tip.html', 'LoginTipController')) .otherwise({ redirectTo: '/activites' });