class Weapps::CourseMemberAttendancesController < ApplicationController before_action :require_login before_action :find_course, :user_course_identity, only: [:update] def create tip_exception("签到码不能为空") if params[:code].blank? tip_exception("attendance_mode参数不对") if ["NUMBER", "QRCODE"].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 == "NORMAL" tip_exception("您当前是请假状态,无法签到") if current_attendance.present? && current_attendance.attendance_status == "LEAVE" tip_exception("您当前是旷课状态,无法签到") if current_attendance.present? && current_attendance.attendance_status == "ABSENCE" 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]) end render_ok end def update tip_exception(403, "无权限调整签到状态") if @user_course_identity > Course::ASSISTANT_PROFESSOR attendance = @course.course_attendances.find_by!(id: params[:attendance_id]) current_attendance = attendance.course_member_attendances.find_by(user_id: params[:user_id]) if current_attendance current_attendance.update!(attendance_status) end end end