开启挑战时加入课堂

dev_winse
cxt 6 years ago
parent 48e06686eb
commit 3a1490f1c4

@ -562,6 +562,17 @@ class ShixunsController < ApplicationController
commit_id = commit["id"]
end
# 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂
if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1))
subject = Subject.where(excellent: 1, id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id)).take
if subject.courses.exists?("start_date is not null and start_date <= #{Date.today} and end_date is not null and end_date >= #{Date.today}")
course = subject.courses.where("start_date is not null and start_date <= #{Date.today} and end_date is not null and end_date >= #{Date.today}").take
unless CourseMember.exists?(course_id: course.id, user_id: current_user.id)
CourseMember.create!(course_id: course.id, user_id: current_user.id, role: 4)
end
end
end
ActiveRecord::Base.transaction do
begin
cloud_bridge = edu_setting('cloud_bridge')

Loading…
Cancel
Save