pre_develop
daiao 6 years ago
parent 23d8e023df
commit 3e416f2538

@ -124,19 +124,22 @@ class CnmoocsService
end end
def get_students_data params def get_students_data params
subject = Subject.find_by_id params[:resouceId] shixun = Shixun.find_by_id params[:resouceId]
return {error: -1, messages: "资源id不对请使用一级目录资源查找"} if subject.blank? return {error: -1, messages: "资源id不对请使用资源的id查找"} if shixun.blank?
shixun_ids = StageShixun.where(:stage_id => subject.stages).pluck(:shixun_id) # shixun_ids = StageShixun.where(:stage_id => subject.stages).pluck(:shixun_id)
myshixuns = Myshixun.where(:user_id => params[:userId], shixun_id: shixun_ids).includes(:games) #myshixuns = Myshixun.where(:user_id => params[:userId], shixun_id: shixun_ids).includes(:games)
score = 0 myshixun = shixun.myshixuns.where(:user_id => params[:userId]).includes(:games)
if myshixun
score = myshixun.total_score
time = 0 time = 0
myshixuns.each do |myshixun|
score += myshixun.total_score
myshixun.games.each do |game| myshixun.games.each do |game|
time += game.consumes_time_int time += game.consumes_time_int
end end
end
{error: 0, messages: '成功', data: {time: time, score: score * 10}} {error: 0, messages: '成功', data: {time: time, score: score * 10}}
else
{error: -1, messages: '用户还未开始学习此资源'}
end
end end

Loading…
Cancel
Save