From 3a1490f1c4a4c95c7120af62c44ea425e57e63db Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 14 Aug 2019 15:47:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=90=AF=E6=8C=91=E6=88=98=E6=97=B6?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index fb999b879..343dd4b73 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -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')