金课调整

dev_cs
cxt 5 years ago
parent f74e2cd231
commit aa3063a931

@ -415,6 +415,20 @@ class SubjectsController < ApplicationController
order by ue_count desc limit 10")
end
# 预约报名
def appointment
tip_exception("还存在未结束的课堂") unless @subject.max_course_end_date.nil? || @subject.max_course_end_date < Date.today
tip_exception("无需重复报名") if @subject.subject_appointments.exists?(user_id: current_user.id)
ActiveRecord::Base.transaction do
@subject.subject_appointments << SubjectAppointment.new(user_id: current_user.id)
@subject.increment!(:participant_count)
if @subject.participant_count == @subject.student_count
@subject.start_course_notify
end
normal_status("预约成功")
end
end
private
def subject_params
tip_exception("实训路径名称不能为空") if params[:name].blank?

@ -384,4 +384,8 @@ module TidingDecorator
def public_course_start_content
I18n.t(locale_format) % [belong_container&.name, belong_container&.start_date&.strftime("%Y-%m-%d")]
end
def subject_start_course_content
I18n.t(locale_format) % belong_container&.name
end
end

@ -13,6 +13,8 @@ class Subject < ApplicationRecord
has_many :stage_shixuns, dependent: :destroy
has_many :shixuns, through: :stage_shixuns
has_many :subject_appointments, dependent: :destroy
has_many :subject_members, ->{ order("subject_members.position asc")}, dependent: :destroy
has_many :users, through: :subject_members
has_many :tidings, as: :container, dependent: :destroy
@ -109,4 +111,10 @@ class Subject < ApplicationRecord
def learning? user_id
Myshixun.where(user_id: user_id, shixun_id: shixuns).exists?
end
def start_course_notify
Tiding.create(user_id: user_id, trigger_user_id: 0, container_id: id,
container_type: 'SubjectStartCourse', belong_container_id: id,
belong_container_type: 'Subject', tiding_type: 'System')
end
end

@ -0,0 +1,4 @@
class SubjectAppointment < ApplicationRecord
belongs_to :subject
belongs_to :user
end

@ -24,4 +24,9 @@ if @subject.excellent
json.course_identity @user.course_identity(course)
json.course_status subject_course_status course
end
if @subject.max_course_end_date.nil? || @subject.max_course_end_date < Date.today
json.student_count @subject.student_count
json.participant_count @subject.participant_count
end
end

@ -227,3 +227,4 @@
1_end: "你提交的发布视频申请:%s审核已通过"
2_end: "你提交的发布视频申请:%s审核未通过<br/><span>原因:%{reason}</span>"
PublicCourseStart_end: "你报名参与的开放课程:%s将于%s正式开课"
SubjectStartCourse_end: "您创建的开放课程:%s 已达到开课人数要求。您可以在24小时内自主开设新一期课程。如果超过24小时未开课平台将自动开课并复制您上一期的课程内容。"

@ -284,6 +284,7 @@ Rails.application.routes.draw do
post :up_member_position
post :down_member_position
get :right_banner
post :appointment
end
collection do

@ -0,0 +1,6 @@
class AddCourseMemberToSubjects < ActiveRecord::Migration[5.2]
def change
add_column :subjects, :student_count, :integer, :default => 0
add_column :subjects, :participant_count, :integer, :default => 0
end
end

@ -0,0 +1,10 @@
class CreateSubjectAppointments < ActiveRecord::Migration[5.2]
def change
create_table :subject_appointments do |t|
t.references :subject, index: true
t.references :user, index: true
t.timestamps
end
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe SubjectAppointment, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save