学生签到

video_log
cxt 5 years ago
parent f99a375967
commit 6632e728db

@ -321,7 +321,7 @@ class ApplicationController < ActionController::Base
end
if !User.current.logged? && Rails.env.development?
User.current = User.find 1
User.current = User.find 3117
end

@ -0,0 +1,31 @@
class Weapps::CourseMemberAttendancesController < ApplicationController
before_action :require_login
def create
tip_exception("签到码不能为空") if params[:code].blank?
tip_exception("attendance_mode参数不对") if [1, 2].include?(params[:attendance_mode])
attendance = CourseAttendance.find_by(attendance_code: params[:code])
tip_exception("签到码输入有误") if attendance.blank? || attendance.course.blank?
member = attendance.course.students.find_by(user_id: current_user.id)
tip_exception("签到码输入有误") if member.blank?
start_time = "#{attendance.attendance_date} #{attendance.start_time}".to_time
end_time = "#{attendance.attendance_date} #{attendance.end_time}".to_time
Rails.logger.info("##############{start_time} #{end_time}")
tip_exception("不在签到时间内") unless start_time < Time.current && Time.current < end_time
current_attendance = attendance.course_member_attendances.find_by(user_id: current_user.id)
tip_exception("请勿重复签到") if current_attendance.present? && current_attendance.attendance_status == 1
tip_exception("您当前是请假状态,无法签到") if current_attendance.present? && current_attendance.attendance_status == 2
tip_exception("您当前是旷课状态,无法签到") if current_attendance.present? && current_attendance.attendance_status == 0
unless current_attendance.present?
attendance.course_member_attendances.create!(course_member_id: member.id, user_id: current_user.id, course_id: attendance.course_id,
course_group_id: member.course_group_id, attendance_status: 1, attendance_mode: params[:attendance_mode] || 2)
end
render_ok
end
end

@ -8,6 +8,7 @@ class CourseMember < ApplicationRecord
belongs_to :course_group, counter_cache: true, optional: true
belongs_to :graduation_group, optional: true
has_many :teacher_course_groups, dependent: :destroy
has_many :course_member_attendances, dependent: :destroy
scope :teachers_and_admin, -> { where(role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) }
scope :students, ->(course) { where(course_id: course.id, role: %i[STUDENT])}

@ -1065,6 +1065,8 @@ Rails.application.routes.draw do
end
end
resources :course_member_attendances, only: [:create]
resources :homework_commons do
post :update_settings, on: :member
end

Loading…
Cancel
Save