实践课程公开流程

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_account, except: [:index, :show, :right_banner]
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,
:search_members, :add_subject_members, :statistics, :shixun_report, :school_report,
:up_member_position, :down_member_position, :update_team_title, :statistics_info]
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,
: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 :shixun_marker, only: [:add_shixun_to_stage]
@ -33,16 +34,16 @@ class SubjectsController < ApplicationController
laboratory_join = " AND subjects.id in #{subject_ids} "
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
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")
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
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")
end
else
@ -59,7 +60,7 @@ class SubjectsController < ApplicationController
elsif reorder == "publish_time"
@subjects = @subjects.unhidden
else
@subjects = @subjects.visible.unhidden
@subjects = @subjects.publiced.unhidden
end
# 类型
@ -72,7 +73,7 @@ class SubjectsController < ApplicationController
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)
end
@ -273,14 +274,44 @@ class SubjectsController < ApplicationController
end
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
if apply && apply.status == 0
@status = 0
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)
begin
status = Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员')
Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员')
rescue => e
uid_logger_error("发送验证码出错: #{e}")
end
@ -288,28 +319,28 @@ class SubjectsController < ApplicationController
end
end
def cancel_publish
def cancel_public
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)
@subject.update_attributes(public: 0)
render_ok
rescue => e
uid_logger_error(e.message)
tip_exception("撤销申请失败")
raise ActiveRecord::Rollback
end
end
def cancel_has_publish
def cancel_has_public
begin
@subject.update_attributes(:status => 0)
@subject.update_attributes(:public => 0)
render_ok
rescue => e
uid_logger_error(e.message)
tip_exception("撤销发布失败")
raise ActiveRecord::Rollback
tip_exception("撤销公开失败")
end
end

@ -6,6 +6,6 @@ module Admins::SubjectsHelper
when 1 then 'text-warning'
when 2 then 'text-success'
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

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

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

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

@ -10,7 +10,7 @@ class Admins::SubjectAuths::AgreeApplyService < ApplicationService
def call
ActiveRecord::Base.transaction do
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!
end

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

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

@ -1,6 +1,10 @@
'zh-CN':
subject:
status:
'0': 编辑中
'1': 审核中
'2': 已发布
public:
'0': 编辑中
'1': 审核中
'2': 已发布

@ -406,9 +406,12 @@ Rails.application.routes.draw do
resources :subjects, path: :paths do
member do
get 'choose_subject_shixun'
get 'publish'
get 'cancel_publish'
get 'cancel_has_publish'
post 'publish'
post :apply_public
post :cancel_public
post 'cancel_publish'
post 'cancel_has_publish'
post :cancel_has_public
get 'statistics'
get 'statistics_info'
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