微信 没登录动态回复会跳到绑定登录界面,私有内容需要是成员才能回复

This commit is contained in:
yuanke 2016-08-11 09:58:45 +08:00
parent b5af6f2c7f
commit 7c5240b386
15 changed files with 181 additions and 94 deletions

View File

@ -14,66 +14,130 @@ module Mobile
requires :token, type: String requires :token, type: String
end end
post ':id' do post ':id' do
authenticate! # authenticate!
status = 0
tip = 0 #0班级1项目
type = params[:type] type = params[:type]
result = 1 result = 1
if params[:content]!="" && current_user if params[:content]!="" && current_user
case type case type
when "HomeworkCommon" when "HomeworkCommon"
homework_common = HomeworkCommon.find(params[:id]) 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) is_public = homework_common.course.is_public
result = 2 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 end
when "News" when "News"
news = News.find(params[:id]) news = News.find(params[:id])
comment = Comment.new
comment.comments = params[:content] if news.project
comment.author = current_user if news.project.is_public == false && !current_user.member_of?(news.project)
if news.comments << comment status = -1
result = 2 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 end
when "Message" when "Message"
message = Message.find(params[:id]) message = Message.find(params[:id])
board = Board.find(message.board_id) board = Board.find(message.board_id)
topic = message.root
reply = Message.new if message.project
reply.author = current_user if message.project.is_public == false && !current_user.member_of?(message.project)
reply.board = board status = -1
reply.content = params[:content] tip = 1
reply.parent_id = params[:id] end
reply.subject = "RE: #{topic.subject}" elsif message.course
if topic.children << reply if message.course.is_public == 0 && !current_user.member_of_course?(message.course)
result = 2 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 end
when "JournalsForMessage" when "JournalsForMessage"
jour = JournalsForMessage.find params[:id] jour = JournalsForMessage.find params[:id]
parent_id = params[:id]
author_id = current_user.id if jour.jour_type == "Project"
reply_user_id = jour.user_id if jour.project.is_public == false && !current_user.member_of?(jour.project)
reply_id = params[:id] status = -1
content = params[:content] tip = 1
options = {:user_id => author_id, end
:status => true, elsif jour.jour_type == "Course"
:m_parent_id => parent_id, if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course)
:m_reply_id => reply_id, status = -1
:reply_id => reply_user_id, tip = 0
:notes => content, end
:is_readed => false} end
jfm = jour.user.add_jour(nil, nil, nil, options)
if jfm.errors.empty? if status == 0
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) parent_id = params[:id]
result = 2 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 end
when 'Issue' when 'Issue'
issue = Issue.find params[:id] issue = Issue.find params[:id]
is_jour = Journal.new
is_jour.user_id = current_user.id if issue.project.is_public == false && !current_user.member_of?(issue.project)
is_jour.notes = params[:content] status = -1
is_jour.journalized = issue tip = 1
if is_jour.save end
result = 2
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 end
when 'BlogComment' when 'BlogComment'
blog = BlogComment.find(params[:id]).root blog = BlogComment.find(params[:id]).root
@ -97,7 +161,8 @@ module Mobile
result = 3 result = 3
end end
present :result, result present :result, result
present :status, 0 present :status, status
present :tip, tip
end end
end end
end end

View File

@ -20,8 +20,8 @@ module Mobile
if news.project if news.project
is_public = news.project.is_public is_public = news.project.is_public
elsif news.project elsif news.course
is_public = news.project.is_public is_public = news.course.is_public
end end
present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page

View File

@ -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 count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count
if count == 0 if count == 0
ws = WechatService.new 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 = "恭喜您加入班级成功。" 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 else
title = "很遗憾您未能成功加入班级。"
role_name = role_id == 7 ? "助教" : "教师" remark = "点击查看申请详情。"
result_name = result == 0 ? "通过" : "被拒绝" uid = user.id
content = "您以"+role_name+"身份加入班级的申请已"+result_name+"" type = "review_class_member"
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
end 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
end end

View File

@ -296,18 +296,18 @@ class WechatService
end end
end end
def join_class_notice(user_id, type, id, first, key1, key2, key3,remark="") # def join_class_notice(user_id, type, id, first, key1, key2, key3,remark="")
uw = UserWechat.where(user_id: user_id).first # uw = UserWechat.where(user_id: user_id).first
unless uw.nil? # unless uw.nil?
data = three_keys_template uw.openid,Wechat.config.join_class_notice, type, id, first, key1, key2, key3, remark # data = three_keys_template uw.openid,Wechat.config.join_class_notice, type, id, first, key1, key2, key3, remark
begin # begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) # req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
rescue Exception => e # rescue Exception => e
Rails.logger.error "[join_class__notice] ===> #{e}" # Rails.logger.error "[join_class__notice] ===> #{e}"
end # end
Rails.logger.info "send over. #{req}" # Rails.logger.info "send over. #{req}"
end # end
end # end
def create_class_notice(user_id, type, id, first, key1, key2, key3, remark="") def create_class_notice(user_id, type, id, first, key1, key2, key3, remark="")
uw = UserWechat.where(user_id: user_id).first uw = UserWechat.where(user_id: user_id).first

View File

@ -23,7 +23,6 @@ default: &default
create_class_notice: "2GtJJGzzNlNy2i0UrsjEDlvfSVIUXQfSo47stpcQAVw" create_class_notice: "2GtJJGzzNlNy2i0UrsjEDlvfSVIUXQfSo47stpcQAVw"
create_project_notice: "jYu0iimbDpgWYZaTLXioZe2lvqoWTdKnUPyphTJ1mxs" create_project_notice: "jYu0iimbDpgWYZaTLXioZe2lvqoWTdKnUPyphTJ1mxs"
project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E" project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E"
join_class_notice: "0V2vhhp5co7drgoyqn3WXUUTQ9xwYrnVcMma7ika6o0"
join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg" join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg"
production: production:
<<: *default <<: *default

View File

@ -23,7 +23,6 @@ default: &default
create_class_notice: "9CDIvHIKiGwPEQWRw_-wieec1o50tMXQPPZIfECKu0I" create_class_notice: "9CDIvHIKiGwPEQWRw_-wieec1o50tMXQPPZIfECKu0I"
create_project_notice: "R2ZaQKJfDJgujPcHWPzadKHIRkIyj2CjX2o_qIuRqig" create_project_notice: "R2ZaQKJfDJgujPcHWPzadKHIRkIyj2CjX2o_qIuRqig"
project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc" project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc"
join_class__notice: "umHZyT8n6KPf3emf4sTJ66I8OB_TJTzjYhxDbJUgUis"
join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M" join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M"
production: production:

View File

@ -73,7 +73,7 @@
<div class="post-reply-row border-bottom-none"> <div class="post-reply-row border-bottom-none">
<div class="post-input-container"> <div class="post-input-container">
<div class="copy-input-container"><textarea class="copy-input"></textarea></div> <div class="copy-input-container"><textarea class="copy-input"></textarea></div>
<textarea input-auto type="text" class="post-reply-input" id="postInput1" ng-model="formData.comment" placeholder="输入回复内容~" /></textarea> <textarea input-auto type="text" class="post-reply-input" id="postInput1" ng-model="formData.comment" placeholder="{{replytip}}" /></textarea>
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr border-radius">提交</button> <button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr border-radius">提交</button>
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr border-radius">提交</button> <button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr border-radius">提交</button>
<div class="cl"></div> <div class="cl"></div>

View File

@ -73,7 +73,7 @@
<div class="post-reply-row border-bottom-none"> <div class="post-reply-row border-bottom-none">
<div class="post-input-container"> <div class="post-input-container">
<div class="copy-input-container"><textarea class="copy-input"></textarea></div> <div class="copy-input-container"><textarea class="copy-input"></textarea></div>
<textarea input-auto type="text" class="post-reply-input" id="postInput1" ng-model="formData.comment" placeholder="输入回复内容~" /></textarea> <textarea input-auto type="text" class="post-reply-input" id="postInput1" ng-model="formData.comment" placeholder="{{replytip}}" /></textarea>
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr border-radius">提交</button> <button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr border-radius">提交</button>
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr border-radius">提交</button> <button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr border-radius">提交</button>
<div class="cl"></div> <div class="cl"></div>

View File

@ -2,13 +2,12 @@
<div loading-spinner></div> <div loading-spinner></div>
<div class="blue-title">友情提示</div> <div class="blue-title">友情提示</div>
<div class="bind-tip-wrap"> <div class="ac-wrap">
<ul class="bind-tip-content f13 c-grey3"> <ul class="ac-content f13 c-grey3">
<li class="mt30 mb15"><span class="project-intro-dot"></span>您还没有绑定,不能直接回复</li> <li class="mt30 mb15"><span class="project-intro-dot"></span>您还没有绑定,不能直接回复</li>
<li class="mb20" style="text-align:center;"><a href="javascript:void(0);" class="btn4 bg-blue" style="width:150px;">绑定</a></li> <li class="mb20" style="text-align:center;"><a ng-click="bindWx()" href="javascript:void(0);" class="btn4 bg-blue" style="width:150px;">绑定</a></li>
<li class="mb15"><span class="project-intro-dot"></span>想要实时接收动态?<br/>长按二维码,关注公众号</li> <li class="mb15"><span class="project-intro-dot"></span>想要实时接收动态?<br/>长按二维码,关注公众号</li>
<li class="mb20" style="text-align:center;"><img src="/images/wechat/trustie_QR.jpg" width="150" class="inline-block" /></li> <li class="mb20" style="text-align:center;"><img src="/images/wechat/trustie_QR.jpg" width="150" class="inline-block" /></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -30,7 +30,7 @@
<input class="input-box" required ng-model="user.username" name="username" placeholder="请输入登录名(英文字母、数字和下划线)" unconfirm/> <input class="input-box" required ng-model="user.username" name="username" placeholder="请输入登录名(英文字母、数字和下划线)" unconfirm/>
<div ng-show="regFrm.$submitted || regFrm.username.$touched"> <div ng-show="regFrm.$submitted || regFrm.username.$touched">
<span class="f12 c-red fl" ng-show="regFrm.username.$error.required">登录名不能为空</span> <span class="f12 c-red fl" ng-show="regFrm.username.$error.required">登录名不能为空</span>
<span class="f12 c-red fl" ng-show="regFrm.username.$error.unconfirm">登录名为1-25个英文字母、数字和下划线</span> <span class="f12 c-red fl" ng-show="regFrm.username.$error.unconfirm">不能以下划线开头不能包括中文长度不超过25个字符</span>
</div> </div>
</div> </div>

View File

@ -1,6 +1,8 @@
app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session','wx', app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session','wx',
function ($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.ready(function(){
wx.hideOptionMenu(); wx.hideOptionMenu();
@ -39,7 +41,13 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams
vm.loginFailed = (response.data.status != 0); vm.loginFailed = (response.data.status != 0);
if (!$scope.loginFailed) { //绑定成功 if (!$scope.loginFailed) { //绑定成功
vm.alertService.showMessage('提示', response.data.message, function(){ vm.alertService.showMessage('提示', response.data.message, function(){
wx.closeWindow(); if(tag){
window.history.back();
tag = null;
}
else{
wx.closeWindow();
}
}); });
} else { } else {
vm.alertService.showMessage('出错了', response.data.message); vm.alertService.showMessage('出错了', response.data.message);

View File

@ -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});
};
}]);

View File

@ -1,5 +1,5 @@
app.controller('RegController', ['$scope', '$http', '$location', 'alertService','$location', app.controller('RegController', ['$scope', '$http', '$location', 'alertService','$location','wx',
function ($scope, $http, $location, alertService, $location) { function ($scope, $http, $location, alertService, $location,wx) {
var vm = $scope; var vm = $scope;
vm.errDialog = alertService.create(); vm.errDialog = alertService.create();
@ -35,7 +35,8 @@ app.controller('RegController', ['$scope', '$http', '$location', 'alertService',
} else { } else {
vm.successDialog.showMessage("提示","注册且绑定微信成功", function(){ vm.successDialog.showMessage("提示","注册且绑定微信成功", function(){
// $location.path("/activities"); // $location.path("/activities");
window.WeixinJSBridge.call('closeWindow'); // window.WeixinJSBridge.call('closeWindow');
wx.closeWindow();
}); });
} }
}, function (response) { }, function (response) {

View File

@ -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){ 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( $http.post(
'/wechat/is_bind', '/wechat/is_bind',
@ -106,8 +106,6 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc
} }
}); });
if(!data.comment || data.comment.length<=0){ if(!data.comment || data.comment.length<=0){
return; return;
} }
@ -129,6 +127,19 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc
}).then(function successCallback(response) { }).then(function successCallback(response) {
//alert("提交成功"); //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; data.disabled = false;
if(typeof cb === 'function'){ if(typeof cb === 'function'){
cb(); cb();
@ -209,6 +220,7 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc
}; };
var init = function(args){ var init = function(args){
args.scope.replytip = "输入回复内容~";
args.scope.formData = {comment: ''}; args.scope.formData = {comment: ''};
var loadData = function(id,replytype,page){ var loadData = function(id,replytype,page){
loadCommonData(id, args.type,replytype,page).then(function successCallback(response) { 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); loadData(args.id,0,0);
args.scope.addReply = function(data){ args.scope.addReply = function(data){
console.log(data.comment); console.log(data.comment);
addCommonReply(args.id, args.replyType, data, function(){ addCommonReply(args.id, args.replyType, data,args, function(){
args.scope.formData = {comment: ''}; args.scope.formData = {comment: ''};
loadData(args.id,0,0); loadData(args.id,0,0);
if(typeof args.replyCallback === 'function'){ if(typeof args.replyCallback === 'function'){

View File

@ -47,6 +47,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func
.when('/project_invite_code', {templateUrl: rootPath + 'project_invite_code.html', controller: 'ProjectInviteCodeController'}) .when('/project_invite_code', {templateUrl: rootPath + 'project_invite_code.html', controller: 'ProjectInviteCodeController'})
.when('/join_project', makeRoute('join_project.html', 'JoinProjectController')) .when('/join_project', makeRoute('join_project.html', 'JoinProjectController'))
.when('/review_project_member', makeRoute('review_project_member.html', 'ReviewProjectMemberController')) .when('/review_project_member', makeRoute('review_project_member.html', 'ReviewProjectMemberController'))
.when('/login_tip', makeRoute('login_tip.html', 'LoginTipController'))
.otherwise({ .otherwise({
redirectTo: '/activites' redirectTo: '/activites'
}); });