diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index b921eebb0..6a381b258 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -84,7 +84,7 @@ class SubjectsController < ApplicationController @is_manager = @user.manager_of_subject?(@subject) # 合作团队 @shixuns = @subject.shixuns.published.pluck(:id) - @courses = @subject.courses id if @subject.excellent + @courses = @subject.courses if @subject.excellent # 访问数变更 @subject.increment!(:visits) diff --git a/app/helpers/subjects_helper.rb b/app/helpers/subjects_helper.rb index e77af9cbb..8aff41d25 100644 --- a/app/helpers/subjects_helper.rb +++ b/app/helpers/subjects_helper.rb @@ -17,5 +17,18 @@ module SubjectsHelper where(challenge_id: challenge_ids, games: {status: 2, user_id: user_id}).pluck("challenge_tags.name").uniq end - + # 金课的课堂状态 0:未开课,1:进行中,2:已结束 + def subject_course_status course + if course.is_end + {status: 2, time: ""} + elsif course.start_date && course.start_date > Date.today + {status: 0, time: ""} + elsif course.start_date && course.start_date <= Date.today && course.end_date >= Date.today + sum_week = ((course.end_date - course.start_date).to_i / 7.0).ceil + curr_week = ((Date.today - course.start_date).to_i / 7.0).ceil + {status: 1, time: "进行至第#{curr_week}周,共#{sum_week}周"} + else + {status: -1, time: ""} + end + end end diff --git a/app/views/subjects/show.json.jbuilder b/app/views/subjects/show.json.jbuilder index 2511fdadb..bf179b86d 100644 --- a/app/views/subjects/show.json.jbuilder +++ b/app/views/subjects/show.json.jbuilder @@ -1,4 +1,4 @@ -json.(@subject, :id, :name, :description, :learning_notes, :stages_count, :stage_shixuns_count, :shixuns_count) +json.(@subject, :id, :name, :description, :learning_notes, :stages_count, :stage_shixuns_count, :shixuns_count, :excellent) json.challenge_choose_count @subject.subject_challenge_choose_count json.challenges_count @subject.subject_challenge_count @@ -13,11 +13,13 @@ json.allow_visit @subject.status > 1 || @is_manager json.allow_add_member @is_manager if @subject.excellent - @courses.each do |course| - json.start_date course.start_date.beginning_of_day - json.end_date course.end_date.end_of_day + json.courses @courses do |course| + json.course_id course.id + json.first_category_url module_url(course.none_hidden_course_modules.first, course) + json.start_date course.start_date + json.end_date course.end_date json.student_count course.students.count json.course_identity @user.course_identity(course) - json.course_status course + json.course_status subject_course_status course end end \ No newline at end of file