Merge branch 'szzh' of http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git into redis_cache
This commit is contained in:
commit
2545a5a7e0
|
@ -99,6 +99,19 @@ module Mobile
|
|||
present :status, 0
|
||||
end
|
||||
|
||||
desc '留言详情'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :comment_parent_id,type:Integer,desc:'留言id'
|
||||
optional :course_id,type:Integer,desc:'课程id'
|
||||
end
|
||||
get ':comment_parent_id/comment_details' do
|
||||
cs = CommentService.new
|
||||
jour = cs.comment_detail params,current_user
|
||||
present :data, jour, with: Mobile::Entities::Jours
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,6 +115,8 @@ module Mobile
|
|||
requires :ref_user_id,type:Integer,desc:'被回复的用户id'
|
||||
requires :parent_id,type:Integer,desc:'留言父id'
|
||||
requires :ref_message_id,type:Integer,desc:'引用消息id'
|
||||
optional :type,type:Integer,desc:'回复类型'
|
||||
optional :course_id,type:Integer,desc:'课程id'
|
||||
end
|
||||
post ':user_id/reply_message' do
|
||||
us = UsersService.new
|
||||
|
@ -133,6 +135,18 @@ module Mobile
|
|||
us.leave_message params,current_user
|
||||
present :data,0
|
||||
end
|
||||
|
||||
desc "与我相关"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page,type:Integer,desc:'页码'
|
||||
end
|
||||
get ':user_id/all_my_dynamic' do
|
||||
us = UsersService.new
|
||||
my_jours = us.reply_my_messages params,current_user
|
||||
present :data,my_jours,with:Mobile::Entities::Jours
|
||||
present :status,0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,11 @@ module Mobile
|
|||
else
|
||||
f.send(field)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :course_name
|
||||
f[:jour_type] == "Course" ? f.course.name : ""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -27,6 +32,11 @@ module Mobile
|
|||
jours_expose :notes
|
||||
jours_expose :m_reply_id
|
||||
jours_expose :m_parent_id
|
||||
expose :course,using:Mobile::Entities::Course do |f,opt|
|
||||
if f.is_a?(::JournalsForMessage) && f[:jour_type] == "Course"
|
||||
f.course
|
||||
end
|
||||
end
|
||||
expose :reply_user,using: Mobile::Entities::User do |f, opt|
|
||||
f.at_user
|
||||
end
|
||||
|
|
|
@ -101,4 +101,17 @@ class CommentService
|
|||
@jours
|
||||
end
|
||||
|
||||
def comment_detail params,current_user
|
||||
if !params[:course_id].nil? && params[:course_id] != 0
|
||||
course = Course.find(params[:course_id])
|
||||
jour = course.journals_for_messages.where("id = ? ",params[:comment_parent_id])
|
||||
jour
|
||||
else
|
||||
jour1 = JournalsForMessage.where("id = ? ",params[:comment_parent_id])
|
||||
jour1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -169,19 +169,26 @@ class UsersService
|
|||
# 回复用户
|
||||
def reply_user_messages params,current_user
|
||||
user = User.find(params[:user_id])
|
||||
parent_id = params[:parent_id]
|
||||
|
||||
m_parent_id = params[:parent_id]
|
||||
author_id = current_user.id
|
||||
reply_user_id = params[:ref_user_id]
|
||||
reply_id = params[:ref_message_id]
|
||||
reply_id = params[:ref_user_id]
|
||||
ref_message_id = params[:ref_message_id]
|
||||
content = params[:content]
|
||||
options = {:user_id => author_id,
|
||||
options = {:user_id => author_id, # 作者id
|
||||
:status => true,
|
||||
:m_parent_id => parent_id,
|
||||
:m_reply_id => reply_id,
|
||||
:reply_id => reply_user_id,
|
||||
:m_parent_id => m_parent_id,# 父留言id
|
||||
:m_reply_id => ref_message_id, # 子留言 id
|
||||
:reply_id => reply_id, # 被留言用户id
|
||||
:notes => content,
|
||||
:is_readed => false}
|
||||
user.add_jour(nil, nil,nil,options)
|
||||
if(params[:type] == 1)
|
||||
user.add_jour(nil, nil,nil,options)
|
||||
elsif(params[:type] == 2)
|
||||
Course.find(params[:course_id]).journals_for_messages.build(options).save! unless params[:course_id].nil?
|
||||
else
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# 给用户留言
|
||||
|
@ -258,4 +265,41 @@ class UsersService
|
|||
scope
|
||||
end
|
||||
|
||||
# 课程留言中与我相关的回复
|
||||
def my_course_messages params,current_user
|
||||
#找到我所有的课程
|
||||
@user = current_user
|
||||
if !current_user.admin? && !@user.active?
|
||||
raise '404'
|
||||
return
|
||||
end
|
||||
if current_user == @user || current_user.admin?
|
||||
membership = @user.coursememberships.all
|
||||
end
|
||||
# membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||
message_list = []
|
||||
membership.each do |mp|
|
||||
#课程轮询找到与我相关的回复
|
||||
message_list << mp.course.journals_for_messages.where("reply_id = ?",current_user.id)
|
||||
end
|
||||
message_list
|
||||
end
|
||||
|
||||
# 获取与我相关的留言:我的留言,回复我的留言
|
||||
def my_personal_messages params,current_user
|
||||
jours = current_user.journals_for_messages.where('m_parent_id is null or reply_id = ?',current_user.id)
|
||||
jours.update_all(:is_readed => true, :status => false)
|
||||
jours
|
||||
end
|
||||
|
||||
def reply_my_messages params,current_user
|
||||
jours = my_personal_messages params,current_user
|
||||
jours1 = my_course_messages params,current_user
|
||||
my_jours = []
|
||||
my_jours << jours << jours1
|
||||
my_jours.flatten!.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||
my_jours_arr = Kaminari.paginate_array(my_jours, total_count: my_jours.count).page(params[:page] || 1).per(10)
|
||||
my_jours_arr
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue