From 3e416f2538c1b56a8082958b0d4345e3458a2a81 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 28 May 2019 21:12:06 +0800 Subject: [PATCH] 1 --- app/services/cnmoocs_service.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/services/cnmoocs_service.rb b/app/services/cnmoocs_service.rb index 34d97d6c..e1bae88d 100644 --- a/app/services/cnmoocs_service.rb +++ b/app/services/cnmoocs_service.rb @@ -124,19 +124,22 @@ class CnmoocsService end def get_students_data params - subject = Subject.find_by_id params[:resouceId] - return {error: -1, messages: "资源id不对,请使用一级目录资源查找"} if subject.blank? - shixun_ids = StageShixun.where(:stage_id => subject.stages).pluck(:shixun_id) - myshixuns = Myshixun.where(:user_id => params[:userId], shixun_id: shixun_ids).includes(:games) - score = 0 - time = 0 - myshixuns.each do |myshixun| - score += myshixun.total_score + shixun = Shixun.find_by_id params[:resouceId] + return {error: -1, messages: "资源id不对,请使用资源的id查找"} if shixun.blank? + # shixun_ids = StageShixun.where(:stage_id => subject.stages).pluck(:shixun_id) + #myshixuns = Myshixun.where(:user_id => params[:userId], shixun_id: shixun_ids).includes(:games) + myshixun = shixun.myshixuns.where(:user_id => params[:userId]).includes(:games) + if myshixun + score = myshixun.total_score + time = 0 myshixun.games.each do |game| time += game.consumes_time_int end + {error: 0, messages: '成功', data: {time: time, score: score * 10}} + else + {error: -1, messages: '用户还未开始学习此资源'} end - {error: 0, messages: '成功', data: {time: time, score: score * 10}} + end