From 03e5b0cf09f826abd9b67896d30d10ef7dde357e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 14:55:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A=E7=9A=84?= =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD=E5=BC=B9=E6=A1=86=E3=80=81?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82=E6=97=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E6=9C=89=E5=90=8C=E5=AD=A6?= =?UTF-8?q?=E5=8F=B7=E7=9A=84=E7=94=A8=E6=88=B7=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 7 +++++++ app/controllers/homework_commons_controller.rb | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 8ea5a7174..7e2c68aab 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -879,6 +879,13 @@ class CoursesController < ApplicationController return normal_status(-1, "同一课堂不允许申请多个教师身份") end + # 验证是否存在同学号的学生 + u_extension = current_user.user_extension + if params[:student].present? && u_extension.student? + same_student_id_users = UserExtension.where.not(user_id: current_user.id).where(student_id: u_extension.student_id, identity: %i[student], school_id: u_extension.school_id).pluck(:user_id) + tip_exception("该课堂已存在同学号的学生,暂时无法加入,请联系老师") if course.students.where(user_id: same_student_id_users).size > 0 + end + # 创建学生身份 if params[:student].present? existing_student = CourseMember.find_by(course_id: course.id, role: %i[STUDENT], user_id: current_user.id) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 83b107ba9..3e12ac474 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -845,12 +845,12 @@ class HomeworkCommonsController < ApplicationController @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct end - @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]).reorder("shixuns.created_at desc") - @shixuns_count = @shixuns.size + @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]) + @total_count = @shixuns.size ## 分页参数 page = params[:page] || 1 - @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(10) + @shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10) # 新版用下面的代码 # ## 我的实训