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

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
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

View File

@ -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

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
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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -73,7 +73,7 @@
<div class="post-reply-row border-bottom-none">
<div class="post-input-container">
<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-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr border-radius">提交</button>
<div class="cl"></div>

View File

@ -73,7 +73,7 @@
<div class="post-reply-row border-bottom-none">
<div class="post-input-container">
<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-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr border-radius">提交</button>
<div class="cl"></div>

View File

@ -2,13 +2,12 @@
<div loading-spinner></div>
<div class="blue-title">友情提示</div>
<div class="bind-tip-wrap">
<ul class="bind-tip-content f13 c-grey3">
<div class="ac-wrap">
<ul class="ac-content f13 c-grey3">
<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="mb20" style="text-align:center;"><img src="/images/wechat/trustie_QR.jpg" width="150" class="inline-block" /></li>
</ul>
</div>
</div>
</div>

View File

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

View File

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

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',
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) {

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){
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'){

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('/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'
});