788 lines
31 KiB
Ruby
788 lines
31 KiB
Ruby
# encoding: utf-8
|
||
class ManagementsController < ApplicationController
|
||
before_filter :require_admin
|
||
layout 'base_management'
|
||
include ManagementsHelper
|
||
include SortHelper
|
||
include UsersHelper
|
||
include ApplicationHelper
|
||
# 专业列表
|
||
def profession
|
||
@syllabus=Syllabus.where("0=0")
|
||
@menu_type=11
|
||
@sub_type=1
|
||
major_level_option=params[:major_level_option]
|
||
discipline_category_option=params[:discipline_category_option]
|
||
first_level_discipline_option=params[:first_level_discipline_option]
|
||
if major_level_option!='0'
|
||
@syllabus=@syllabus.where(:major_level=>major_level_option)
|
||
else
|
||
@syllabus=@syllabus
|
||
end
|
||
|
||
if discipline_category_option !=nil
|
||
@syllabus=@syllabus.where(:discipline_category_id=>discipline_category_option)
|
||
end
|
||
|
||
if first_level_discipline_option!=nil
|
||
@syllabus=@syllabus.where(:first_level_discipline_id=>first_level_discipline_option)
|
||
end
|
||
@syllabus_count = @syllabus.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@syllabus_pages = Paginator.new @syllabus_count, limit, params['page'] || 1
|
||
@offset ||= @syllabus_pages.offset
|
||
@syllabus = paginateHelper @syllabus, limit
|
||
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
|
||
end
|
||
|
||
# 实训适用课程
|
||
def applicable_course
|
||
@majorcourse=MajorCourse.where("0=0")
|
||
|
||
end
|
||
# 单位部门列表
|
||
def departments
|
||
@menu_type = 6
|
||
@sub_type = 2
|
||
@department =Department.where("0=0")
|
||
search=params[:search]
|
||
if search.blank?
|
||
@department = @department
|
||
else
|
||
@department = @department.where("name like '%#{search}%'")
|
||
end
|
||
@department_count =@department.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@department_pages = Paginator.new @department_count, limit, params['page'] || 1
|
||
@offset ||=@department_pages.offset
|
||
@department = paginateHelper @department, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
|
||
end
|
||
# 单位列表
|
||
def departments_part
|
||
@menu_type = 6
|
||
@sub_type = 1
|
||
@schools = School.where("0=0")
|
||
search=params[:search]
|
||
if search.blank?
|
||
@schools = @schools
|
||
else
|
||
@schools = @schools.where("name like '%#{search}%'")
|
||
end
|
||
@schools_count = @schools.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@schools_pages = Paginator.new @schools_count, limit, params['page'] || 1
|
||
@offset ||= @schools_pages.offset
|
||
@schools= paginateHelper @schools, limit
|
||
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 部门审核
|
||
def depart
|
||
@menu_type = 10
|
||
@sub_type = 3
|
||
search = params[:search]
|
||
@apply_status = ApplyAddDepartment.where("0=0")
|
||
if search.blank?
|
||
@apply_status = @apply_status.where("0=0")
|
||
else
|
||
@apply_status= @apply_status.where("name like '%#{search}%'")
|
||
end
|
||
@apply_status_count = @apply_status.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@apply_status_pages = Paginator.new @apply_status_count, limit, params['page'] || 1
|
||
@offset ||=@apply_status_pages.offset
|
||
@apply_status = paginateHelper @apply_status, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 单位审批
|
||
def unit
|
||
@menu_type = 10
|
||
@sub_type = 4
|
||
search = params[:search]
|
||
@apply_status = ApplyAddSchools.where("0=0")
|
||
if search.blank?
|
||
@apply_status = @apply_status.where("0=0")
|
||
else
|
||
@apply_status= @apply_status.where("name like '%#{search}%'")
|
||
end
|
||
@apply_status_count = @apply_status.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@apply_status_pages = Paginator.new @apply_status_count, limit, params['page'] || 1
|
||
@offset ||= @apply_status_pages.offset
|
||
@apply_status = paginateHelper @apply_status, limit
|
||
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 课堂列表
|
||
def classroom
|
||
@menu_type = 2
|
||
@sub_type = 1
|
||
@syllabus = Syllabus.where("0=0")
|
||
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
unless params[:school_id] || params[:search] || params[:keyword] || params[:status]
|
||
user_exs=UserExtensions.where(:user_id=> @syllabus.map(&:user_id))
|
||
@schools = School.where(:id =>user_exs.map(&:school_id))
|
||
end
|
||
|
||
major_level_option=params[:major_level_option]
|
||
discipline_category_option=params[:discipline_category_option]
|
||
first_level_discipline_option=params[:first_level_discipline_option]
|
||
syllabus_major_option=params[:syllabus_major_option]
|
||
keyword=params[:keyword]
|
||
search=params[:search]
|
||
if major_level_option!='0'
|
||
@syllabus=@syllabus.where(:major_level=>major_level_option)
|
||
else
|
||
@syllabus=@syllabus
|
||
end
|
||
|
||
if discipline_category_option !=nil
|
||
@syllabus=@syllabus.where(:discipline_category_id=>discipline_category_option)
|
||
end
|
||
|
||
if first_level_discipline_option!=nil
|
||
@syllabus=@syllabus.where(:first_level_discipline_id=>first_level_discipline_option)
|
||
end
|
||
|
||
if syllabus_major_option!=nil
|
||
@syllabus=@syllabus.where(:major_id=>syllabus_major_option)
|
||
end
|
||
|
||
if params[:school_id] && params[:school_id] != '0'
|
||
@syllabus = Syllabus.includes(:user => {:user_extensions => []}).where("user_extensions.school_id = #{params[:school_id]}")
|
||
else
|
||
@syllabus = @syllabus.where("0=0")
|
||
end
|
||
|
||
if search.blank?
|
||
@syllabus = @syllabus
|
||
else
|
||
if "u_name" == keyword
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@syllabus = @syllabus.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'")
|
||
else
|
||
@syllabus= @syllabus.where("user_id like '%#{search}%'")
|
||
end
|
||
end
|
||
@syllabus_count = @syllabus.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@syllabus_pages = Paginator.new @syllabus_count, limit, params['page'] || 1
|
||
@offset ||= @syllabus_pages.offset
|
||
@syllabus = paginateHelper @syllabus, limit
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 班级列表
|
||
def classroom_classment
|
||
@menu_type = 2
|
||
@sub_type = 2
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order]
|
||
@courses = Course.where("0=0")
|
||
# @courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc")
|
||
@timing=Course.where(:is_end=>false).count
|
||
@end=Course.where(:is_end=>true).count
|
||
unless params[:school_id] || params[:search] || params[:keyword] || params[:status]
|
||
user_exs=UserExtensions.where(:school_id=> @courses.map(&:school_id))
|
||
@schools = School.where(:id =>user_exs.map(&:school_id))
|
||
end
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索
|
||
status = params[:status].to_i
|
||
if params[:school_id] && params[:school_id] != '0'
|
||
@courses =Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("ue.school_id = #{params[:school_id]}").order("created_at #{@sx_order}")
|
||
else
|
||
@courses = Course.where("0=0").order("created_at #{@sx_order}")
|
||
end
|
||
if params[:status] && params[:status]!=''
|
||
@courses =@courses.where(:is_end =>status).order("created_at #{@sx_order}")
|
||
end
|
||
if "u_name" == keyword
|
||
if search.blank?
|
||
@courses = @courses.order("created_at #{@sx_order}")
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@courses = @courses.joins("join users u on courses.tea_id = u.id").where("concat(u.lastname, u.firstname) like '%#{search}%'").order("created_at #{@sx_order}")
|
||
end
|
||
else
|
||
@courses= @courses.where("name like '%#{search}%'").order("created_at #{@sx_order}")
|
||
end
|
||
@courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").reorder("updatetime desc")
|
||
@courses_count = @courses.count
|
||
limit = 20
|
||
@is_remote = true
|
||
@courses_pages = Paginator.new @courses_count, limit, params['page'] || 1
|
||
@offset ||= @courses_pages.offset
|
||
@courses = paginateHelper @courses, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 课程实训
|
||
def class_shixuns
|
||
@menu_type = 4
|
||
@sub_type = 1
|
||
@edit_class_sx_num=Subject.where(:status => 0).count
|
||
@audit_class_sx_num=Subject.where(:status => 1).count
|
||
@publish_class_sx_num=Subject.where(:status => 2).count
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索
|
||
status = params[:status].to_i
|
||
if params[:school_id] && params[:school_id] != '0'
|
||
@c_shixuns = Subject.includes(:user => {:user_extensions => []}).where("user_extensions.school_id = #{params[:school_id]}")
|
||
else
|
||
@c_shixuns = Subject.where("0=0")
|
||
end
|
||
if params[:status] && params[:status]!=''
|
||
@c_shixuns= @c_shixuns.where(:status =>status)
|
||
end
|
||
if search.blank?
|
||
@c_shixuns = @c_shixuns
|
||
else
|
||
if "u_name" == keyword
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@c_shixuns = @c_shixuns.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'")
|
||
else
|
||
@c_shixuns= @c_shixuns.where("name like '%#{search}%'")
|
||
end
|
||
end
|
||
@c_shixuns = @c_shixuns.reorder("created_at desc")
|
||
unless params[:school_id] || params[:search] || params[:keyword] || params[:status]
|
||
user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id))
|
||
@schools = School.where(:id => user_exs.map(&:school_id))
|
||
end
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 已发布课程实训
|
||
def class_publish_shixuns
|
||
@menu_type = 4
|
||
@sub_type = 2
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索
|
||
if params[:school_id] && params[:school_id] != '0'
|
||
@c_shixuns = Subject.includes(:user => {:user_extensions => []}).where("subjects.status = 2 and user_extensions.school_id = #{params[:school_id]}")
|
||
else
|
||
@c_shixuns = Subject.where(:status => 2)
|
||
end
|
||
if search.blank?
|
||
@c_shixuns = @c_shixuns
|
||
else
|
||
if "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@c_shixuns = @c_shixuns.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'")
|
||
else
|
||
@c_shixuns= @c_shixuns.where("name like '%#{search}%'")
|
||
end
|
||
end
|
||
unless params[:school_id] || params[:search] || params[:keyword]
|
||
user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id))
|
||
@schools = School.where(:id => user_exs.map(&:school_id))
|
||
end
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 0 全部;1 活动的; 2 已注册; 3 锁定
|
||
def users
|
||
@menu_type =7
|
||
@sub_type = 1
|
||
status = params[:user_status].nil? ? 0 : params[:user_status].to_i
|
||
@us_order = params[:us_order].blank? ? "desc" : params[:us_order] # 排序
|
||
@order_key = params[:order_key].blank? ? "created_on" : params[:order_key] # 排序关键字
|
||
condition = (params[:research_condition].nil? || params[:research_condition] == "name") ? "concat(lastname, firstname)" : params[:research_condition]
|
||
if 0 == status
|
||
if params[:research_condition] == "phone" && params[:research_contents].blank?
|
||
@users = User.order("#{@order_key} #{@us_order}").all
|
||
else
|
||
@users = User.where("#{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all
|
||
end
|
||
else
|
||
if params[:research_condition] == "phone" && params[:research_contents].blank?
|
||
@users = User.where(:status => status).order("#{@order_key} #{@us_order}").all
|
||
else
|
||
@users = User.where("status = #{status} and #{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all
|
||
end
|
||
end
|
||
@users_count = @users.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@users_pages = Paginator.new @users_count, @limit, params['page'] || 1
|
||
@offset ||= @users_pages.offset
|
||
@users = paginateHelper @users, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def shixuns
|
||
@menu_type = 3
|
||
@sub_type = 1
|
||
sx_status = params[:status].blank? ? [0, 1, 2, 3] : params[:status].to_i # 搜索实训的状态
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
|
||
search = params[:search] # 搜索的字
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
|
||
if "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
if search.blank?
|
||
@shixuns = Shixun.where(:status => sx_status).order("created_at #{@sx_order}")
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@shixuns = Shixun.where(:user_id => user_id, :status => sx_status).order("created_at #{@sx_order}")
|
||
end
|
||
else
|
||
@shixuns = Shixun.where("name like '%#{search}%'").where(:status => sx_status).order("created_at #{@sx_order}")
|
||
end
|
||
@edit_sx_num = Shixun.where(:status => 0).count
|
||
@audit_sx_num = Shixun.where(:status => 1).count
|
||
@publish_sx_num =Shixun.where(:status => 2).count
|
||
@close_sx_num = Shixun.where(:status => 3).count
|
||
@shixuns_count = @shixuns.count
|
||
limit = 20
|
||
@shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @shixuns_pages.offset
|
||
@shixuns = paginateHelper @shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 已发布的实训
|
||
def publish_shixuns
|
||
@menu_type = 3
|
||
@sub_type = 2
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
|
||
close = params[:close] # 关闭实训,参数是实训的Id
|
||
unless close.blank?
|
||
Shixun.find(close).update_attribute(:status, 3)
|
||
end
|
||
if "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
if search.blank?
|
||
@shixuns = Shixun.where(:status => 2).order("created_at #{@sx_order}")
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@shixuns = Shixun.where(:user_id => user_id, :status => 2).order("created_at #{@sx_order}")
|
||
end
|
||
else
|
||
@shixuns = Shixun.where("name like '%#{search}%'").where(:status => 2).order("created_at #{@sx_order}")
|
||
end
|
||
@shixuns_count = @shixuns.count
|
||
limit = 20
|
||
@shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @shixuns_pages.offset
|
||
@shixuns = paginateHelper @shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
# 已关闭的实训
|
||
def close_shixuns
|
||
@menu_type = 3
|
||
@sub_type = 3
|
||
@sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
|
||
search = params[:search] # 搜索字
|
||
keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
|
||
reopen = params[:reopen] # 从新开启实训,参数是实训的Id
|
||
unless reopen.blank?
|
||
Shixun.find(reopen).update_attribute(:status, 2)
|
||
end
|
||
if "u_name" == keyword
|
||
# 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
|
||
if search.blank?
|
||
@shixuns = Shixun.where(:status => 3).order("updated_at #{@sx_order}")
|
||
else
|
||
user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
|
||
@shixuns = Shixun.where(:user_id => user_id, :status => 3).order("updated_at #{@sx_order}")
|
||
end
|
||
else
|
||
@shixuns = Shixun.where("name like '%#{search}%'").where(:status => 3).order("updated_at #{@sx_order}")
|
||
end
|
||
@shixuns_count = @shixuns.count
|
||
limit = 20
|
||
@shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1
|
||
@offset ||= @shixuns_pages.offset
|
||
@shixuns = paginateHelper @shixuns, limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def users_trial
|
||
@menu_type = 7
|
||
@sub_type = 2
|
||
@users = User.where(:status => 1).order("created_on desc").all
|
||
@users_count = @users.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@users_pages = Paginator.new @users_count, @limit, params['page'] || 1
|
||
@offset ||= @users_pages.offset
|
||
@users = paginateHelper @users, @limit
|
||
end
|
||
|
||
def search_user
|
||
|
||
=begin
|
||
auth = ApplyUserAuthentication.where(:status => params[:authentication])
|
||
auth_id = auth.blank? ? User.where(:status => 1).id : "(" + auth.map{|a| a.user_id }.join(",") + ")"
|
||
=end
|
||
|
||
if params[:member_ids] && params[:trial_whether] == "trial_agree"
|
||
params[:member_ids].each do |member|
|
||
aUser = ApplyAction.where(:user_id => member, :container_type => "TrialAuthorization")
|
||
if aUser.blank?
|
||
ApplyAction.create(:user_id => member, :container_type => "TrialAuthorization", :status => 1)
|
||
else
|
||
aUser.update_all(:status => 1)
|
||
end
|
||
end
|
||
elsif params[:member_ids] && params[:trial_whether] == "trial_cancel"
|
||
ApplyAction.where(:user_id => params[:member_ids], :container_type => "TrialAuthorization").update_all(:status => 2)
|
||
end
|
||
|
||
if params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_agree")
|
||
User.where(:id => params[:member_ids]).update_all(:authentication => true)
|
||
elsif params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_cancel")
|
||
User.where(:id => params[:member_ids]).update_all(:authentication => false)
|
||
end
|
||
|
||
if params[:trial] == "-1"
|
||
apply = ApplyAction.where(:container_type => "TrialAuthorization")
|
||
apply_id = apply.blank? ? -1 : "(" + apply.map{|a| a.user_id}.join(",") + ")"
|
||
apply_user_id = User.where("id not in #{apply_id} and status = 1").all
|
||
apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
|
||
elsif params[:trial] == "-2"
|
||
apply_user_id = User.where(:status => 1).all
|
||
apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
|
||
else
|
||
apply = ApplyAction.where(:status => params[:trial])
|
||
apply_user_id = apply.blank? ? [-1] : apply.map{|a| a.user_id}.split(",")[0]
|
||
end
|
||
|
||
if params[:school] == ""
|
||
s_user_id = User.where(:status => 1).all
|
||
s_user_id = s_user_id.blank? ? [-1] : s_user_id.map{|s| s.id}.split(",")[0]
|
||
else
|
||
school = School.where("name like '%#{params[:school]}%'")
|
||
school_id = school.blank? ? -1 : school.map{|s| s.id }.split(",")[0]
|
||
usr = UserExtensions.where(:school_id => school_id)
|
||
s_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
|
||
end
|
||
|
||
if params[:department] == ""
|
||
d_user_id = User.where(:status => 1).all
|
||
d_user_id = d_user_id.blank? ? [-1] : d_user_id.map{|d| d.id}.split(",")[0]
|
||
else
|
||
department = Department.where("name like '%#{params[:department]}%'").all
|
||
dep_id = department.blank? ? -1 : department.map{|d| d.id}.split(",")
|
||
usr = UserExtensions.where(:department_id => dep_id)
|
||
d_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
|
||
end
|
||
|
||
user_id = s_user_id & d_user_id & apply_user_id
|
||
|
||
if params[:research_condition] == "name"
|
||
@users = User.where(:id => user_id).where("concat(lastname, firstname) like '%#{params[:research_contents]}%'").order("created_on desc")
|
||
elsif params[:research_condition] == "email"
|
||
@users = User.where(:id => user_id).where("mail like '%#{params[:research_contents]}%'").order("created_on desc")
|
||
elsif params[:research_condition] == "phone"
|
||
if params[:research_contents].blank?
|
||
@users = User.where(:id => user_id).order("created_on desc")
|
||
else
|
||
@users = User.where(:id => user_id).where("phone like '%#{params[:research_contents]}%'").order("created_on desc")
|
||
end
|
||
|
||
end
|
||
|
||
@users_count = @users.count
|
||
@limit = 20
|
||
@is_remote = true
|
||
@users_pages = Paginator.new @users_count, @limit, params['page'] || 1
|
||
@offset ||= @users_pages.offset
|
||
@users = paginateHelper @users, @limit
|
||
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def update_webssh
|
||
webssh = params[:status] == "true" ? true : false
|
||
@shixuns = Shixun.find(params[:shixun_id])
|
||
@shixuns.update_column(:webssh, webssh)
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def affirm_cancel_auth
|
||
user_id = params[:users]
|
||
end
|
||
|
||
|
||
def trial_authorization
|
||
@menu_type =10
|
||
@sub_type = 2
|
||
search = params[:search]
|
||
@status = trial_authorization_status(params[:status])
|
||
# @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2]
|
||
if search.blank?
|
||
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status).includes(:user)
|
||
else
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
|
||
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status, :user_id => user_id).includes(:user)
|
||
end
|
||
|
||
@autu_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
|
||
@offset ||= @autu_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
|
||
end
|
||
|
||
# 批量授权
|
||
def batch_authorization
|
||
|
||
end
|
||
|
||
# params[:type] 1:拒绝 0:同意
|
||
# authentication 会有一个初始值,不同的值代表不同的权限
|
||
# REDO: 后面权限改了后,一并要改
|
||
def trial_authorization_operation
|
||
apply_action = ApplyAction.find(params[:apply_id])
|
||
type = params[:type]
|
||
search = params[:search]
|
||
if type == "0"
|
||
authentication_user = AuthenticationsUsers.where(:user_id => apply_action.user_id).first
|
||
if authentication_user.blank?
|
||
AuthenticationsUsers.create(:user_id => apply_action.user_id, :authentication_id => 1)
|
||
end
|
||
end
|
||
apply_action.update_attributes(:status => (params[:type] == "1" ? 2 : 1), :reason => params[:reject_reason], :dealer_id => User.current.id)
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
|
||
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => 0, :user_id => user_id).includes(:user)
|
||
@autu_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
|
||
@offset ||= @autu_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def index
|
||
|
||
end
|
||
|
||
# copy from admin
|
||
def identity_authentication
|
||
@menu_type = 10
|
||
@sub_type = 1
|
||
@type = trial_authorization_status(params[:type])
|
||
type = params[:type] || 0 # 存在type 就用type 没有就为 0
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'")
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id, :auth_type => 1).order("updated_at desc")
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def professional_authentication
|
||
@menu_type = 10
|
||
@sub_type = 7
|
||
@type = trial_authorization_status(params[:type])
|
||
type = params[:type] || 0 # 存在type 就用type 没有就为 0
|
||
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'")
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id, :auth_type => 2).order("updated_at desc")
|
||
respond_to do |format|
|
||
format.html
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 拒绝身份认证
|
||
# copy from admin
|
||
def reject_authentication
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 1).first
|
||
reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason])
|
||
render :json => {success: reason}
|
||
end
|
||
|
||
# 同意身份认证
|
||
# copy from admin
|
||
def agree_authentication
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 1).first
|
||
user = User.find(apply_user.user_id)
|
||
apply_user.update_attribute(:status, 1)
|
||
user.update_attribute(:authentication, true)
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => 0, :auth_type => 1).order("updated_at desc")
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
# 拒绝职业认证
|
||
def reject_authentication_pro
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 2).first
|
||
reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason])
|
||
render :json => {success: reason}
|
||
end
|
||
|
||
# 同意职业认证
|
||
def agree_authentication_pro
|
||
apply_user = ApplyUserAuthentication.where(:id => params[:apply_id], :auth_type => 2).first
|
||
user = User.find(apply_user.user_id)
|
||
apply_user.update_attribute(:status, 1)
|
||
user.update_attribute(:professional_certification, true)
|
||
@unapproved_user = ApplyUserAuthentication.where(:status => 0, :auth_type => 2).order("updated_at desc")
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
|
||
def subject_authorization
|
||
@menu_type = 10
|
||
@sub_type == 6
|
||
@type = trial_authorization_status params[:type]
|
||
@authorizations = ApplyAction.where(:container_type => "ApplySubject", :status => @type).order("created_at desc")
|
||
# @subject=Subject.all
|
||
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
|
||
def shixun_authorization
|
||
@menu_type = 10
|
||
@sub_type == 5
|
||
@type = trial_authorization_status params[:type]
|
||
@authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => @type).order("created_at desc")
|
||
search = params[:search]
|
||
unless search.blank?
|
||
@authorizations = @authorizations.where(:container_id => Shixun.where(:id => @authorizations.map(&:container_id)).where("name like '%#{search}%'").map(&:id)).order("created_at desc")
|
||
end
|
||
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
format.html
|
||
end
|
||
end
|
||
# 课程实训发布审批
|
||
def deal_subject_authorization
|
||
apply_action = ApplyAction.find(params[:apply_id])
|
||
type = params[:type].to_i
|
||
subject = Subject.find apply_action.container_id
|
||
if type == 0 #拒绝
|
||
subject.update_column('status', 0)
|
||
apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id)
|
||
notes = "您所在团队提交的课程实训发布申请:<a href='#{subject_path(subject)}'>#{subject.name}</a>,审核未通过。<br/>原因:#{params[:reject_reason]}"
|
||
JournalsForMessage.create(:jour_id => subject.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
|
||
else #同意
|
||
subject.update_column('status', 2)
|
||
apply_action.update_attributes(:status => 1, :dealer_id => User.current.id)
|
||
end
|
||
@authorizations = ApplyAction.where(:container_type => "ApplySubject", :status => 0)
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
# 项目实训发布审批
|
||
def deal_shixun_authorization
|
||
apply_action = ApplyAction.find(params[:apply_id])
|
||
type = params[:type].to_i
|
||
shixun = Shixun.find apply_action.container_id
|
||
if type == 0 #拒绝
|
||
shixun.update_column('status', 0)
|
||
apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id)
|
||
notes = "您所在团队提交的项目实训发布申请:<a href='#{shixun_path(shixun)}'>#{shixun.name}</a>,审核未通过。<br/>原因:#{params[:reject_reason]}"
|
||
shixun.shixun_members.each do |member|
|
||
JournalsForMessage.create(:jour_id => member.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
|
||
end
|
||
else #同意
|
||
shixun.update_column('status', 2)
|
||
apply_action.update_attributes(:status => 1, :dealer_id => User.current.id)
|
||
shixun_modify_status_without_publish shixun, 1
|
||
end
|
||
@authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => 0)
|
||
@authorizations_count = @authorizations.count
|
||
@limit = 15
|
||
@is_remote = true
|
||
@authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1
|
||
@offset ||= @authorizations_pages.offset
|
||
@authorizations = paginateHelper @authorizations, @limit
|
||
respond_to do |format|
|
||
format.js
|
||
end
|
||
end
|
||
end
|