|
|
|
@ -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,
|
|
|
|
|
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,
|
|
|
|
|
: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 :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
|
|
|
|
|
|
|
|
|
|