@ -1,6 +1,6 @@
# encoding: utf-8
class ManagementsController < ApplicationController
before_filter :require_ admin
before_filter :require_ business
layout 'base_management'
include ManagementsHelper
include SortHelper
@ -63,7 +63,6 @@ class ManagementsController < ApplicationController
# 工程认证视频导入模板
def ec_template
@template = EcTemplate . where ( nil )
end
def add_template
@ -1191,7 +1190,7 @@ end
if params [ :search ] . blank?
@partners = Partner . includes ( :school ) . order ( " partners.created_at desc " )
else
@partners = Partner . where( " name like ? " , " % #{ params [ :search ] } % " ) . includes ( :school ) . order ( " partners.created_at desc " )
@partners = Partner . includes( :school ) . where( " schools. name like ? " , " % #{ params [ :search ] } % " ) . order ( " partners.created_at desc " )
end
@current_partner = nil
@ -1212,6 +1211,14 @@ end
end
def delete_partner
partner = Partner . find params [ :partner_id ]
partner . destroy
@partners = Partner . includes ( :school ) . order ( " partners.created_at desc " )
@current_partner = nil
end
# 添加客户
def customers_list
@search = params [ :search ]
@ -1219,11 +1226,10 @@ end
partner_id = params [ :partner_id ]
@partner = Partner . find partner_id
@customers = @partner . customers
if @customers . present?
@schools = School . where ( " (partner_id != ? or partner_id is NULL) and customer_id is NULL " , @partner . id )
else
@schools = School . where ( " customer_id is null and (partner_id != ? or partner_id is NULL) " , @partner . id )
end
existed_school_ids = @customers . pluck ( :school_id )
existed_school_ids = existed_school_ids . present? ? existed_school_ids . join ( " , " ) : - 1
@schools = School . where ( " id not in ( #{ existed_school_ids } ) " )
if params [ :search ]
@schools = @schools . where ( " name like ? " , " % #{ @search } % " )
end
@ -1247,13 +1253,14 @@ end
def add_customers
school_ids = params [ :school_ids ]
if school_ids . length > 0
partner_id = params [ :partner_id ]
if school_ids . length > 0 && partner_id . present?
school_ids . each do | s |
school = School . where ( " id = ? " , s ) . first
if school . present?
customer = Customer . new ( partner_id: params [ :partner_id ] )
customer = Customer . new ( school_id: s )
customer . save!
school . update_attributes ( :customer_id = > customer . id )
PartnerCustomer . create ( partner_id : partner_id , customer_id : customer . id )
end
end
render :json = > { status : 1 , message : " 创建成功! " }
@ -1262,17 +1269,20 @@ end
def delete_customers
if params [ :customer ]
customer = Customer . where ( id : params [ :customer ] ) . first
@current_partner = customer . partner
customer . school . update_attributes ( :customer_id = > nil )
customer = Customer . find ( params [ :customer ] )
@current_partner = Partner . find ( params [ :partner_id ] )
customer . destroy
end
end
# 添加合作伙伴弹框数据
def all_partners
@search = params [ :search ]
@province = params [ :province ]
@schools = School . where ( " partner_id IS NULL " )
# 已经选过的合作伙伴不能再再列表中显示
used_school_ids = Partner . pluck ( :school_id )
used_school_ids = used_school_ids . blank? ? - 1 : used_school_ids . join ( " , " )
@schools = School . where ( " id not in ( #{ used_school_ids } ) " )
if params [ :search ]
@schools = @schools . where ( " name like ? " , " % #{ @search } % " )
@ -1296,26 +1306,20 @@ end
end
end
def add_partner
school_ids = params [ :school_ids ]
if school_ids . length > 0
school_ids . each do | s |
school = School . where ( " id = ? " , s ) . first
if school. present? && school . partner_id . nil ?
partner = Partner . new ( name : school . name )
old_partner = Partner . where ( :school_id = > s )
if old_partner. blank ?
partner = Partner . new ( school_id : s )
partner . save
school . update_attributes ( :partner_id = > partner . id )
end
end
end
render :json = > { status : 1 , message : " 创建成功! " }
end
# 删除部门管理员
def delete_depart_member
DepartmentMember . where ( :department_id = > params [ :depart ] , :user_id = > params [ :user_id ] ) . destroy_all
@ -3345,7 +3349,7 @@ end
end
@users = User . where ( :id = > user_id ) . where ( " #{ sql } " ) . includes ( :apply_actions , user_extensions : [ :department , :school ] ) . order ( " last_login_on desc " )
@xls_users = @users . reorder ( " created_on desc " ) . limit ( 1 000) #导出excel用户
@xls_users = @users . reorder ( " created_on desc " ) . limit ( 3 000) #导出excel用户
@page = ( params [ 'page' ] || 1 ) . to_i
@users_count = @users . count
@limit = 20
@ -4176,7 +4180,7 @@ end
sheet1 = book . create_worksheet :name = > " course "
blue = Spreadsheet :: Format . new :color = > :blue , :weight = > :bold , :size = > 10
sheet1 . row ( 0 ) . default_format = blue
sheet1 . row ( 0 ) . concat ( [ " ID " , " 课堂名称 " , " 成员 " , " 资源 " , " 普通作业 " , " 实训作业 " , " 试卷 " , " 私有 " , " 状态 " , " 创建者单位 " , " 创建者 " , " 动态时间 " ] )
sheet1 . row ( 0 ) . concat ( [ " ID " , " 课堂名称 " , " 成员 " , " 资源 " , " 普通作业 " , " 实训作业 " , " 试卷 " , " 私有 " , " 状态 " , " 创建者单位 " , " 创建者 " , " 动态时间 " , " 创建时间 " ] )
count_row = 1
courses . each do | course |
school = course . teacher . try ( :user_extensions ) . try ( :school ) . try ( :name ) . blank? ? " -- " : course . teacher . school_name
@ -4193,6 +4197,7 @@ end
sheet1 [ count_row , 9 ] = school
sheet1 [ count_row , 10 ] = teacher_name
sheet1 [ count_row , 11 ] = format_time ( course . updatetime )
sheet1 [ count_row , 12 ] = format_time ( course . created_at )
count_row += 1
end
book . write xls_report