实践课程公开流程

sso
daiao 5 years ago
parent 1f1ff6c7a9
commit 8ac2f9d6f7

@ -3,9 +3,10 @@ class SubjectsController < ApplicationController
# before_action :check_auth, except: [:index] # before_action :check_auth, except: [:index]
before_action :check_account, except: [:index, :show, :right_banner] before_action :check_account, except: [:index, :show, :right_banner]
before_action :find_subject, except: [:index, :create, :new, :append_to_stage, :add_shixun_to_stage] before_action :find_subject, except: [:index, :create, :new, :append_to_stage, :add_shixun_to_stage]
before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, :apply_public,
:search_members, :add_subject_members, :statistics, :shixun_report, :school_report, :search_members, :add_subject_members, :statistics, :shixun_report, :school_report,
:up_member_position, :down_member_position, :update_team_title, :statistics_info] :cancel_has_public, :up_member_position, :down_member_position, :update_team_title,
:statistics_info, :cancel_public]
before_action :require_admin, only: [:copy_subject] before_action :require_admin, only: [:copy_subject]
before_action :shixun_marker, only: [:add_shixun_to_stage] before_action :shixun_marker, only: [:add_shixun_to_stage]
@ -33,16 +34,16 @@ class SubjectsController < ApplicationController
laboratory_join = " AND subjects.id in #{subject_ids} " laboratory_join = " AND subjects.id in #{subject_ids} "
if select if select
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public,
subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' #{laboratory_join} subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join}
AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
else else
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public,
subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' #{laboratory_join} subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join}
GROUP BY subjects.id ORDER BY myshixun_member_count DESC") GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
end end
else else
@ -59,7 +60,7 @@ class SubjectsController < ApplicationController
elsif reorder == "publish_time" elsif reorder == "publish_time"
@subjects = @subjects.unhidden @subjects = @subjects.unhidden
else else
@subjects = @subjects.visible.unhidden @subjects = @subjects.publiced.unhidden
end end
# 类型 # 类型
@ -72,7 +73,7 @@ class SubjectsController < ApplicationController
end end
# 排序 # 排序
order_str = (reorder == "publish_time" ? "homepage_show desc, excellent desc, status = 2 desc, publish_time asc" : "homepage_show desc, excellent desc, updated_at desc") order_str = (reorder == "publish_time" ? "homepage_show desc, excellent desc, public = 2 desc, publish_time asc" : "homepage_show desc, excellent desc, updated_at desc")
@subjects = @subjects.reorder(order_str) @subjects = @subjects.reorder(order_str)
end end
@ -273,14 +274,44 @@ class SubjectsController < ApplicationController
end end
def publish def publish
@subject.update_attributes(status: 2)
end
def cancel_publish
begin
apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first
if apply && apply.status == 0
apply.update_attributes(status: 3)
apply.tidings.destroy_all
end
@subject.update_attributes(status: 0)
rescue => e
uid_logger_error(e.message)
tip_exception("撤销申请失败")
end
end
def cancel_has_publish
begin
@subject.update_attributes(:status => 0)
rescue => e
uid_logger_error(e.message)
tip_exception("撤销发布失败")
raise ActiveRecord::Rollback
end
end
# 申请公开
def apply_public
tip_exception(-1, "请先发布课程再申请公开") if @subject.status != 2
apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first
if apply && apply.status == 0 if apply && apply.status == 0
@status = 0 @status = 0
else else
@subject.update_attributes(status: 1) @subject.update_attributes(public: 1)
ApplyAction.create(container_type: "ApplySubject", container_id: @subject.id, user_id: current_user.id, status: 0) ApplyAction.create(container_type: "ApplySubject", container_id: @subject.id, user_id: current_user.id, status: 0)
begin begin
status = Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员') Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员')
rescue => e rescue => e
uid_logger_error("发送验证码出错: #{e}") uid_logger_error("发送验证码出错: #{e}")
end end
@ -288,28 +319,28 @@ class SubjectsController < ApplicationController
end end
end end
def cancel_publish def cancel_public
begin begin
apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first
if apply && apply.status == 0 if apply && apply.status == 0
apply.update_attributes(status: 3) apply.update_attributes(status: 3)
apply.tidings.destroy_all apply.tidings.destroy_all
end end
@subject.update_attributes(status: 0) @subject.update_attributes(public: 0)
render_ok
rescue => e rescue => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("撤销申请失败") tip_exception("撤销申请失败")
raise ActiveRecord::Rollback
end end
end end
def cancel_has_publish def cancel_has_public
begin begin
@subject.update_attributes(:status => 0) @subject.update_attributes(:public => 0)
render_ok
rescue => e rescue => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("撤销发布失败") tip_exception("撤销公开失败")
raise ActiveRecord::Rollback
end end
end end

@ -6,6 +6,6 @@ module Admins::SubjectsHelper
when 1 then 'text-warning' when 1 then 'text-warning'
when 2 then 'text-success' when 2 then 'text-success'
end end
raw content_tag(:span, t("subject.status.#{subject.status}"), class: style) raw content_tag(:span, t("subject.public.#{subject.public}"), class: style)
end end
end end

@ -40,6 +40,7 @@ class Subject < ApplicationRecord
scope :visible, lambda{where(status: 2)} scope :visible, lambda{where(status: 2)}
scope :published, lambda{where(status: 1)} scope :published, lambda{where(status: 1)}
scope :unhidden, lambda{where(hidden: 0)} scope :unhidden, lambda{where(hidden: 0)}
scope :publiced, lambda{ where(public: 2) }
after_create :send_tiding after_create :send_tiding
def send_tiding def send_tiding

@ -21,7 +21,7 @@ class Admins::SubjectQuery < ApplicationQuery
when 'applying' then 1 when 'applying' then 1
when 'published' then 2 when 'published' then 2
end end
subjects = subjects.where(status: status) if status subjects = subjects.where(public: status) if status
# 创建者单位 # 创建者单位
if params[:school_id].present? if params[:school_id].present?

@ -8,7 +8,7 @@ class Weapps::SubjectQuery < ApplicationQuery
end end
def call def call
subjects = @current_laboratory.subjects.unhidden.visible subjects = @current_laboratory.subjects.unhidden.publiced
# 课程体系的过滤 # 课程体系的过滤
if params[:sub_discipline_id].present? if params[:sub_discipline_id].present?

@ -10,7 +10,7 @@ class Admins::SubjectAuths::AgreeApplyService < ApplicationService
def call def call
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
apply.update!(status: 1, dealer_id: user.id) apply.update!(status: 1, dealer_id: user.id)
subject.update!(status: 2, publish_time: Time.now) subject.update!(public: 2, publish_time: Time.now)
deal_tiding! deal_tiding!
end end

@ -10,7 +10,7 @@ class Admins::SubjectAuths::RefuseApplyService < ApplicationService
def call def call
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
subject.update!(status: 0) subject.update!(public: 0)
apply.update!(status: 2, reason: reason, dealer_id: user.id) apply.update!(status: 2, reason: reason, dealer_id: user.id)
deal_tiding! deal_tiding!

@ -0,0 +1,2 @@
json.status @status
json.message @status == 0 ? "已公开过申请,请等待管理员审核" : "公开申请已提交,请等待管理员的审核"

@ -1,2 +1,2 @@
json.status 1 json.status 0
json.subject_id @subject.id json.subject_id @subject.id

@ -1,2 +1,2 @@
json.status @status json.status 0
json.message @status == 0 ? "已发布过申请,请等待管理员审核" : "发布申请已提交,请等待管理员的审核" json.message "申请成功"

@ -4,3 +4,7 @@
'0': 编辑中 '0': 编辑中
'1': 审核中 '1': 审核中
'2': 已发布 '2': 已发布
public:
'0': 编辑中
'1': 审核中
'2': 已发布

@ -406,9 +406,12 @@ Rails.application.routes.draw do
resources :subjects, path: :paths do resources :subjects, path: :paths do
member do member do
get 'choose_subject_shixun' get 'choose_subject_shixun'
get 'publish' post 'publish'
get 'cancel_publish' post :apply_public
get 'cancel_has_publish' post :cancel_public
post 'cancel_publish'
post 'cancel_has_publish'
post :cancel_has_public
get 'statistics' get 'statistics'
get 'statistics_info' get 'statistics_info'
get 'shixun_report' get 'shixun_report'

@ -0,0 +1,5 @@
class AddPublicForSubjects < ActiveRecord::Migration[5.2]
def change
add_column :subjects, :public, :integer, :default => 0
end
end

@ -0,0 +1,7 @@
class MigrateSubjectStatus < ActiveRecord::Migration[5.2]
def change
Subject.unhidden.visible.update_all(public: 2)
Subject.where(status: 1, id: ApplyAction.where(container_type: 'ApplySubject', status: 0)
.pluck(:container_id)).update_all(status: 2, public: 1)
end
end
Loading…
Cancel
Save