回复留言

This commit is contained in:
lizanle 2015-05-21 15:57:35 +08:00
parent d6fe4082af
commit 8e04b4e565
2 changed files with 19 additions and 8 deletions

View File

@ -111,11 +111,13 @@ module Mobile
requires :token, type: String
requires :user_id, type: Integer,desc: '被留言的用户id'
requires :content,type:String,desc:'留言内容'
optional :refer_user_id,type:Integer,desc:'被回复的用户id'
requires :ref_user_id,type:Integer,desc:'被回复的用户id'
requires :parent_id,type:Integer,desc:'留言父id'
requires :ref_message_id,type:Integer,desc:'引用消息id'
end
post ':user_id/leave_message' do
us = UsersService.new
jours = us.leave_messages params,current_user
jours = us.reply_user_messages params,current_user
present :status,0
end

View File

@ -166,13 +166,22 @@ class UsersService
jours
end
# 给某个用户留言
def leave_messages params,current_user
# 回复用户
def reply_user_messages params,current_user
user = User.find(params[:user_id])
user.add_jour(current_user, params[:content], params[:refer_user_id] ||= 0)
unless params[:refer_user_id].nil? || params[:refer_user_id] == 0 || params[:refer_user_id] == User.current.id
User.find(params[:refer_user_id]).add_jour(current_user, params[:content], params[:refer_user_id])
end
parent_id = params[:parent_id]
author_id = current_user.id
reply_user_id = params[:ref_user_id]
reply_id = params[:ref_message_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}
user.add_jour(nil, nil,nil,options)
end