2017-06-30 10:17:44 +08:00
# encoding: utf-8
2017-06-07 17:39:24 +08:00
class ManagementsController < ApplicationController
before_filter :require_admin
layout 'base_management'
include ManagementsHelper
2017-06-08 16:15:24 +08:00
include SortHelper
include UsersHelper
2017-06-23 13:57:25 +08:00
include ApplicationHelper
2017-07-04 09:51:51 +08:00
# 0 全部; 1 活动的; 2 已注册; 3 锁定
2017-06-08 11:17:29 +08:00
def users
2017-07-21 11:16:10 +08:00
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 ] # 排序关键字
2017-07-04 09:51:51 +08:00
condition = ( params [ :research_condition ] . nil? || params [ :research_condition ] == " name " ) ? " concat(lastname, firstname) " : params [ :research_condition ]
if 0 == status
2017-07-04 10:40:17 +08:00
if params [ :research_condition ] == " phone " && params [ :research_contents ] . blank?
2017-07-21 11:16:10 +08:00
@users = User . order ( " #{ @order_key } #{ @us_order } " ) . all
2017-07-04 10:40:17 +08:00
else
2017-07-21 11:16:10 +08:00
@users = User . where ( " #{ condition } like '% #{ params [ :research_contents ] } %' " ) . order ( " #{ @order_key } #{ @us_order } " ) . all
2017-07-04 10:40:17 +08:00
end
2017-07-04 09:51:51 +08:00
else
2017-07-04 10:40:17 +08:00
if params [ :research_condition ] == " phone " && params [ :research_contents ] . blank?
2017-07-21 11:16:10 +08:00
@users = User . where ( :status = > status ) . order ( " #{ @order_key } #{ @us_order } " ) . all
2017-06-08 16:15:24 +08:00
else
2017-07-21 11:16:10 +08:00
@users = User . where ( " status = #{ status } and #{ condition } like '% #{ params [ :research_contents ] } %' " ) . order ( " #{ @order_key } #{ @us_order } " ) . all
2017-07-04 10:40:17 +08:00
end
2017-06-08 16:15:24 +08:00
end
2017-07-04 09:51:51 +08:00
@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
2017-06-08 16:15:24 +08:00
respond_to do | format |
2017-07-04 09:51:51 +08:00
format . js
2017-07-21 11:16:10 +08:00
format . html
2017-06-08 16:15:24 +08:00
end
end
2017-07-07 15:41:02 +08:00
def shixuns
2017-07-12 16:23:57 +08:00
@menu_type = 3
2017-07-10 15:13:11 +08:00
sx_status = params [ :status ] . blank? ? [ 0 , 1 , 2 , 3 ] : params [ :status ] . to_i # 搜索实训的状态
keyword = params [ :keyword ] . blank? ? " u_name " : params [ :keyword ] # 根据姓名/实训名搜索
search = params [ :search ] # 搜索的字
2017-07-10 16:41:15 +08:00
@sx_order = params [ :sx_order ] . blank? ? " desc " : params [ :sx_order ] # 排序
2017-07-10 15:13:11 +08:00
if " u_name " == keyword
# 如果用户搜索为空, 不用遍历user表, 直接查找所有实训, 有搜索时才查找user
if search . blank?
2017-07-10 16:41:15 +08:00
@shixuns = Shixun . where ( :status = > sx_status ) . order ( " created_at #{ @sx_order } " )
2017-07-10 15:13:11 +08:00
else
user_id = User . where ( " concat(lastname, firstname) like '% #{ search } %' " )
2017-07-10 16:41:15 +08:00
@shixuns = Shixun . where ( :user_id = > user_id , :status = > sx_status ) . order ( " created_at #{ @sx_order } " )
2017-07-10 15:13:11 +08:00
end
else
2017-07-10 16:41:15 +08:00
@shixuns = Shixun . where ( " name like '% #{ search } %' " ) . where ( :status = > sx_status ) . order ( " created_at #{ @sx_order } " )
2017-07-10 15:13:11 +08:00
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
2017-07-07 16:02:55 +08:00
@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
2017-07-10 16:41:15 +08:00
format . html
2017-07-07 16:02:55 +08:00
end
2017-07-07 15:41:02 +08:00
end
2017-07-12 16:23:57 +08:00
# 已发布的实训
def publish_shixuns
@menu_type = 3
@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
2017-07-13 09:48:17 +08:00
# 已关闭的实训
def close_shixuns
@menu_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
2017-06-08 16:15:24 +08:00
def users_trial
@menu_type = 6
2017-06-22 17:03:00 +08:00
@users = User . where ( :status = > 1 ) . order ( " created_on desc " ) . all
2017-06-19 17:04:55 +08:00
@users_count = @users . count
2017-06-22 17:03:00 +08:00
@limit = 20
2017-06-19 17:04:55 +08:00
@is_remote = true
@users_pages = Paginator . new @users_count , @limit , params [ 'page' ] || 1
@offset || = @users_pages . offset
@users = paginateHelper @users , @limit
2017-06-08 11:17:29 +08:00
end
2017-06-22 09:31:08 +08:00
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
2017-06-22 17:03:00 +08:00
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
2017-06-22 09:31:08 +08:00
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
2017-06-23 15:59:32 +08:00
school = School . where ( " name like '% #{ params [ :school ] } %' " )
2017-06-22 09:31:08 +08:00
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
2017-06-23 15:59:32 +08:00
department = Department . where ( " name like '% #{ params [ :department ] } %' " ) . all
2017-06-22 09:31:08 +08:00
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 "
2017-06-22 17:03:00 +08:00
@users = User . where ( :id = > user_id ) . where ( " concat(lastname, firstname) like '% #{ params [ :research_contents ] } %' " ) . order ( " created_on desc " )
2017-06-22 09:31:08 +08:00
elsif params [ :research_condition ] == " email "
2017-06-23 15:59:32 +08:00
@users = User . where ( :id = > user_id ) . where ( " mail like '% #{ params [ :research_contents ] } %' " ) . order ( " created_on desc " )
2017-06-22 09:31:08 +08:00
elsif params [ :research_condition ] == " phone "
2017-06-23 15:59:32 +08:00
if params [ :research_contents ] . blank?
2017-06-23 16:27:56 +08:00
@users = User . where ( :id = > user_id ) . order ( " created_on desc " )
2017-06-23 15:59:32 +08:00
else
@users = User . where ( :id = > user_id ) . where ( " phone like '% #{ params [ :research_contents ] } %' " ) . order ( " created_on desc " )
end
2017-06-22 09:31:08 +08:00
end
@users_count = @users . count
2017-06-22 17:03:00 +08:00
@limit = 20
2017-06-22 09:31:08 +08:00
@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
2017-07-07 17:22:50 +08:00
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
2017-06-22 17:03:00 +08:00
def affirm_cancel_auth
user_id = params [ :users ]
end
2017-06-07 17:39:24 +08:00
def trial_authorization
2017-06-08 11:17:29 +08:00
@menu_type = 9
2017-06-07 17:39:24 +08:00
search = params [ :search ]
@status = trial_authorization_status ( params [ :status ] )
2017-06-08 10:53:11 +08:00
# @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2]
2017-06-07 17:39:24 +08:00
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
2017-06-26 15:42:17 +08:00
@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
2017-07-14 15:39:27 +08:00
2017-06-07 17:39:24 +08:00
end
2017-06-19 17:04:55 +08:00
# 批量授权
def batch_authorization
end
2017-06-08 17:45:39 +08:00
# params[:type] 1: 拒绝 0: 同意
# authentication 会有一个初始值,不同的值代表不同的权限
# REDO: 后面权限改了后,一并要改
2017-06-07 17:39:24 +08:00
def trial_authorization_operation
apply_action = ApplyAction . find ( params [ :apply_id ] )
2017-06-13 14:17:27 +08:00
type = params [ :type ]
search = params [ :search ]
if type == " 0 "
2017-06-08 17:45:39 +08:00
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
2017-06-07 17:39:24 +08:00
apply_action . update_attributes ( :status = > ( params [ :type ] == " 1 " ? 2 : 1 ) , :reason = > params [ :reject_reason ] , :dealer_id = > User . current . id )
2017-06-13 14:17:27 +08:00
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 )
2017-07-14 15:41:31 +08:00
@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
2017-06-13 14:17:27 +08:00
respond_to do | format |
format . js
end
2017-06-07 17:39:24 +08:00
end
def index
end
2017-06-08 10:53:11 +08:00
# copy from admin
2017-06-07 17:39:24 +08:00
def identity_authentication
2017-06-08 11:17:29 +08:00
@menu_type = 9
2017-06-29 09:59:59 +08:00
@type = trial_authorization_status ( params [ :type ] )
2017-06-07 17:39:24 +08:00
type = params [ :type ] || 0 # 存在type 就用type 没有就为 0
user_id = User . find_by_sql ( " select id from users where concat(lastname,firstname) like '% #{ params [ :name ] } %' " )
2017-06-29 09:59:59 +08:00
@unapproved_user = ApplyUserAuthentication . where ( :status = > @type , :user_id = > user_id ) . order ( " updated_at desc " )
2017-06-07 17:39:24 +08:00
respond_to do | format |
format . html
format . js
end
end
2017-06-08 10:53:11 +08:00
# 拒绝身份认证
# copy from admin
def reject_authentication
apply_user = ApplyUserAuthentication . find ( params [ :apply_id ] )
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 . find ( params [ :apply_id ] )
user = User . find ( apply_user . user_id )
apply_user . update_attribute ( :status , 1 )
user . update_attribute ( :authentication , true )
@unapproved_user = ApplyUserAuthentication . where ( :status = > 0 ) . order ( " updated_at desc " )
respond_to do | format |
format . js
end
end
2017-06-21 17:26:49 +08:00
def shixun_authorization
@type = trial_authorization_status params [ :type ]
2017-06-26 17:35:55 +08:00
@authorizations = ApplyAction . where ( :container_type = > " ApplyShixun " , :status = > @type ) . order ( " created_at desc " )
2017-06-21 17:26:49 +08:00
search = params [ :search ]
unless search . blank?
2017-06-26 17:35:55 +08:00
@authorizations = @authorizations . where ( :container_id = > Shixun . where ( :id = > @authorizations . map ( & :container_id ) ) . where ( " name like '% #{ search } %' " ) . map ( & :id ) ) . order ( " created_at desc " )
2017-06-21 17:26:49 +08:00
end
2017-06-26 17:35:55 +08:00
@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
2017-06-21 17:26:49 +08:00
respond_to do | format |
format . js
format . html
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 )
2017-06-30 10:17:44 +08:00
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
2017-06-21 17:26:49 +08:00
else
2017-06-22 16:17:57 +08:00
shixun . update_column ( 'status' , 2 )
apply_action . update_attributes ( :status = > 1 , :dealer_id = > User . current . id )
2017-06-28 15:23:09 +08:00
shixun_modify_status_without_publish shixun , 1
2017-06-21 17:26:49 +08:00
end
@authorizations = ApplyAction . where ( :container_type = > " ApplyShixun " , :status = > 0 )
2017-06-29 10:43:05 +08:00
@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
2017-06-21 17:26:49 +08:00
respond_to do | format |
format . js
end
end
2017-06-07 17:39:24 +08:00
end