From 1eef20bda1c909ee8f5409b12c1a13be1ee29894 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 3 Mar 2020 19:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../course_member_attendances_controller.rb | 22 ++++++++++++++----- app/helpers/weapps/attendances_helper.rb | 2 +- app/models/course_attendance.rb | 2 ++ app/models/course_member_attendance.rb | 2 ++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/weapps/course_member_attendances_controller.rb b/app/controllers/weapps/course_member_attendances_controller.rb index 9eca18d4b..dc8e1a0ca 100644 --- a/app/controllers/weapps/course_member_attendances_controller.rb +++ b/app/controllers/weapps/course_member_attendances_controller.rb @@ -1,9 +1,10 @@ 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 [1, 2].include?(params[:attendance_mode]) + 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? @@ -16,16 +17,27 @@ class Weapps::CourseMemberAttendancesController < ApplicationController 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 + 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] || 2) + 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 \ No newline at end of file diff --git a/app/helpers/weapps/attendances_helper.rb b/app/helpers/weapps/attendances_helper.rb index 087084288..b7c3eafdc 100644 --- a/app/helpers/weapps/attendances_helper.rb +++ b/app/helpers/weapps/attendances_helper.rb @@ -2,6 +2,6 @@ module Weapps::AttendancesHelper def student_attendance_status attendance, user st_attendance = attendance.course_member_attendances.find_by(user_id: user.id) - st_attendance.present? ? st_attendance.attendance_status : 0 + st_attendance.present? ? st_attendance.attendance_status : "ABSENCE" end end \ No newline at end of file diff --git a/app/models/course_attendance.rb b/app/models/course_attendance.rb index f3bcffc56..270b64132 100644 --- a/app/models/course_attendance.rb +++ b/app/models/course_attendance.rb @@ -1,5 +1,7 @@ class CourseAttendance < ApplicationRecord # mode: 0 两种签到,1 二维码签到,2 数字签到 + enum mode: { ALL: 0, QRCODE: 1, NUMBER: 2 } + belongs_to :course belongs_to :user diff --git a/app/models/course_member_attendance.rb b/app/models/course_member_attendance.rb index 3b8aafda0..03a81e7e7 100644 --- a/app/models/course_member_attendance.rb +++ b/app/models/course_member_attendance.rb @@ -1,6 +1,8 @@ class CourseMemberAttendance < ApplicationRecord # attendance_mode :1 二维码签到,2 数字签到,3 老师签到 + enum attendance_mode: { QRCODE: 1, NUMBER: 2, TEACHER: 3 } # attendance_status :1 正常签到,2 请假,0 旷课 + enum attendance_status: { NORMAL: 1, LEAVE: 2, ABSENCE: 3 } belongs_to :course_member belongs_to :user belongs_to :course