添加作品评分接口
This commit is contained in:
parent
6261d95eba
commit
9708c50899
|
@ -70,6 +70,32 @@ module Mobile
|
||||||
present :status, 0
|
present :status, 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "作品打分"
|
||||||
|
params do
|
||||||
|
requires :token, type: String
|
||||||
|
requires :is_teacher, type: String,desc: '是否为教师(匿评作品详情返回的结果中可获取此参数的值)'
|
||||||
|
requires :is_anonymous_comments, type: String, desc: '是否为匿评(匿评作品详情返回的结果中可获取此参数的值)'
|
||||||
|
optional :stars_value, type: Integer,desc: '用户给出的评分'
|
||||||
|
optional :cur_page,type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||||||
|
optional :cur_type, type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||||||
|
optional :user_message, type: String, desc: '用户评论'
|
||||||
|
end
|
||||||
|
|
||||||
|
post ':homework_id/scoring' do
|
||||||
|
cs_params = {
|
||||||
|
new_form: params.reject{|k,v| [:token,:is_teacher,:is_anonymous_comments,:stars_value,:cur_page,:cur_type,:homework_id].include?(k)},
|
||||||
|
token: params[:token],
|
||||||
|
is_teacher: params[:is_teacher],
|
||||||
|
is_anonymous_comments: params[:is_anonymous_comments],
|
||||||
|
stars_value: params[:stars_value],
|
||||||
|
cur_page: params[:cur_page],
|
||||||
|
cur_type: params[:cur_type],
|
||||||
|
homework_id: params[:homework_id]
|
||||||
|
}
|
||||||
|
Homeworks.get_service.add_score_and_jour cs_params,current_user
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -141,16 +141,56 @@ class HomeworkService
|
||||||
end
|
end
|
||||||
|
|
||||||
#作品打分/留言
|
#作品打分/留言
|
||||||
def add_score_and_jour params
|
def add_score_and_jour params,current_user
|
||||||
@is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value]
|
@is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value]
|
||||||
@cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5
|
@cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5
|
||||||
@homework = HomeworkAttach.find(params[:homework_id])
|
@homework = HomeworkAttach.find(params[:homework_id])
|
||||||
|
comment_status = @homework.bid.comment_status
|
||||||
|
if @is_anonymous_comments && comment_status != 1
|
||||||
|
case comment_status
|
||||||
|
when 0
|
||||||
|
raise '尚未开启匿评!'
|
||||||
|
when 2
|
||||||
|
raise '匿评已结束!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if @is_anonymous_comments && ((@m_score.nil? || @m_score.blank?) || !(params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""))
|
||||||
|
raise '您尚未打分或评论!'
|
||||||
|
end
|
||||||
#保存评分
|
#保存评分
|
||||||
@homework.rate(@m_score.to_i,User.current.id,:quality) if @m_score
|
homework = @homework
|
||||||
|
is_teacher = @is_teacher ? 1 : 0
|
||||||
|
#保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0))
|
||||||
|
if @m_score
|
||||||
|
rate = @homework.rates(:quality).where(:rater_id => current_user.id, :is_teacher_score => is_teacher).first
|
||||||
|
if rate
|
||||||
|
rate.stars = @m_score
|
||||||
|
rate.save!
|
||||||
|
else
|
||||||
|
@homework.rates(:quality).new(:stars => @m_score, :rater_id => current_user.id, :is_teacher_score => is_teacher).save!
|
||||||
|
end
|
||||||
|
|
||||||
|
if homework.is_teacher_score == 0
|
||||||
|
if is_teacher == 1
|
||||||
|
homework.score = @m_score
|
||||||
|
homework.is_teacher_score = 1
|
||||||
|
else
|
||||||
|
sql = "SELECT AVG(stars) as stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{homework.id}"
|
||||||
|
score= HomeworkAttach.find_by_sql(sql).first.stars
|
||||||
|
homework.score = score
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if is_teacher == 1
|
||||||
|
homework.score = @m_score
|
||||||
|
homework.is_teacher_score = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
homework.save!
|
||||||
|
end
|
||||||
#保存评论
|
#保存评论
|
||||||
@is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言
|
@is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言
|
||||||
if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言
|
if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言
|
||||||
@homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation
|
@homework.addjours current_user.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue