微信增加回复的回复后台代码

weixin_guange
yuanke 9 years ago
parent 10017d2c69
commit 6f7b40b5ad

@ -78,22 +78,25 @@ module Mobile
subscribe = 0 #默认未关注 subscribe = 0 #默认未关注
#-------------------获取用户是否关注此公众号----------------------------- #-------------------获取用户是否关注此公众号-----------------------------
openid = session[:wechat_openid] # openid = session[:wechat_openid]
raise "无法获取到openid,请在微信中打开本页面" unless openid # raise "无法获取到openid,请在微信中打开本页面" unless openid
user_info = Wechat.api.user(openid) # user_info = Wechat.api.user(openid)
Rails.logger.info "user_info!!!!!!!!!" # Rails.logger.info "user_info!!!!!!!!!"
Rails.logger.info user_info # Rails.logger.info user_info
subscribe = user_info["subscribe"] # subscribe = user_info["subscribe"]
subscribe = "123"
status = 0 status = 0
tip = 0 #0班级1项目 tip = 0 #0班级1项目
type = params[:type] type = params[:type]
result = 1 result = 1
#0回复 1回复的回复
reply_type = params[:reply_type]
if params[:content]!="" && current_user if params[:content]!="" && current_user
case type case type
when "HomeworkCommon" when "HomeworkCommon"
homework_common = HomeworkCommon.find(params[:id])
#如果是私有的 并且不是成员则不能回复 #如果是私有的 并且不是成员则不能回复
# is_public = homework_common.course.is_public # is_public = homework_common.course.is_public
# if is_public == 0 && !current_user.member_of_course?(homework_common.course) # if is_public == 0 && !current_user.member_of_course?(homework_common.course)
@ -106,15 +109,27 @@ module Mobile
# result = 2 # result = 2
# end # end
# end # end
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) if reply_type == nil || reply_type == 0
if (feedback.errors.empty?) homework_common = HomeworkCommon.find(params[:id])
homework_common.update_column(:updated_at, Time.now) feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
result = 2 if (feedback.errors.empty?)
homework_common.update_column(:updated_at, Time.now)
result = 2
end
else
#二级回复
reply = JournalsForMessage.find params[:id].to_i
homework_common = HomeworkCommon.find reply.jour_id
options = {:notes => params[:content], :reply_id => reply.user_id,:user_id => current_user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i}
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], reply.jour_id, options)
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])
# if news.project # if news.project
# if news.project.is_public == false && !current_user.member_of?(news.project) # if news.project.is_public == false && !current_user.member_of?(news.project)
# status = -1 # status = -1
@ -126,19 +141,26 @@ module Mobile
# tip = 0 # tip = 0
# end # end
# end # end
if status == 0 if status == 0
comment = Comment.new if reply_type == nil || reply_type == 0
comment.comments = params[:content] news = News.find(params[:id])
comment.author = current_user comment = Comment.new
if news.comments << comment comment.comments = params[:content]
result = 2 comment.author = current_user
if news.comments << comment
result = 2
end
else
#二级回复
comment = Comment.find(params[:id])
news = News.find comment.commented_id
new_comment = news.comments.build(:author_id => current_user.id, :reply_id => params[:id], :comments => params[:content], :parent_id => comment.id)
if new_comment.save
result = 2
end
end end
end end
when "Message" when "Message"
message = Message.find(params[:id])
board = Board.find(message.board_id)
# if message.project # if message.project
# if message.project.is_public == false && !current_user.member_of?(message.project) # if message.project.is_public == false && !current_user.member_of?(message.project)
# status = -1 # status = -1
@ -152,20 +174,25 @@ module Mobile
# end # end
if status == 0 if status == 0
topic = message.root # if reply_type == nil || reply_type == 0
reply = Message.new message = Message.find(params[:id])
reply.author = current_user board = Board.find(message.board_id)
reply.board = board topic = message.root
reply.content = params[:content] reply = Message.new
reply.parent_id = params[:id] reply.author = current_user
reply.subject = "RE: #{topic.subject}" reply.board = board
if topic.children << reply reply.content = params[:content]
result = 2 reply.parent_id = params[:id]
end reply.subject = "RE: #{topic.subject}"
if topic.children << reply
result = 2
end
# else
#二级回复
# end
end end
when "JournalsForMessage" when "JournalsForMessage"
jour = JournalsForMessage.find params[:id]
# if jour.jour_type == "Project" # if jour.jour_type == "Project"
# if jour.project.is_public == false && !current_user.member_of?(jour.project) # if jour.project.is_public == false && !current_user.member_of?(jour.project)
# status = -1 # status = -1
@ -179,50 +206,80 @@ module Mobile
# end # end
if status == 0 if status == 0
parent_id = params[:id] # if reply_type == nil || reply_type == 0
author_id = current_user.id jour = JournalsForMessage.find params[:id]
reply_user_id = jour.user_id parent_id = params[:id]
reply_id = params[:id] author_id = current_user.id
content = params[:content] reply_user_id = jour.user_id
options = {:user_id => author_id, reply_id = params[:id]
:status => true, content = params[:content]
:m_parent_id => parent_id, options = {:user_id => author_id,
:m_reply_id => reply_id, :status => true,
:reply_id => reply_user_id, :m_parent_id => parent_id,
:notes => content, :m_reply_id => reply_id,
:is_readed => false} :reply_id => reply_user_id,
jfm = jour.user.add_jour(nil, nil, nil, options) :notes => content,
if jfm.errors.empty? :is_readed => false}
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) jfm = jour.user.add_jour(nil, nil, nil, options)
result = 2 if jfm.errors.empty?
end (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
result = 2
end
# else
#二级回复
# end
end end
when 'Issue' when 'Issue'
issue = Issue.find params[:id]
# if issue.project.is_public == false && !current_user.member_of?(issue.project) # if issue.project.is_public == false && !current_user.member_of?(issue.project)
# status = -1 # status = -1
# tip = 1 # tip = 1
# end # end
if status == 0 if status == 0
is_jour = Journal.new if reply_type == nil || reply_type == 0
is_jour.user_id = current_user.id issue = Issue.find params[:id]
is_jour.notes = params[:content] is_jour = Journal.new
is_jour.journalized = issue is_jour.user_id = current_user.id
if is_jour.save is_jour.notes = params[:content]
result = 2 is_jour.journalized = issue
if is_jour.save
result = 2
end
else
#二级回复
end end
end end
when 'BlogComment' when 'BlogComment'
blog = BlogComment.find(params[:id]).root if reply_type == nil || reply_type == 0
blogComment = BlogComment.new blog = BlogComment.find(params[:id]).root
blogComment.author = current_user blogComment = BlogComment.new
blogComment.blog = blog.blog blogComment.author = current_user
blogComment.content = params[:content] blogComment.blog = blog.blog
blogComment.title = "RE: #{blog.title}" blogComment.content = params[:content]
if blog.children << blogComment blogComment.title = "RE: #{blog.title}"
result = 2 if blog.children << blogComment
result = 2
end
else
#二级回复
blog = BlogComment.find(params[:id]).root
blogComment = BlogComment.new
blogComment.author = current_user
blogComment.blog = blog.blog
blogComment.content = params[:content]
blogComment.title = "RE: #{blog.title}"
parent = BlogComment.find params[:id]
blogComment.parent_id = params[:id] #被回复的回复
blogComment.reply_id = parent.author.id #被回复者id
if parent.children << blogComment
result = 2
end
end end
end end
if result == 2 if result == 2

Loading…
Cancel
Save