diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb index cc4e6c9a..93d2df8e 100644 --- a/app/controllers/colleges_controller.rb +++ b/app/controllers/colleges_controller.rb @@ -258,7 +258,7 @@ class CollegesController < ApplicationController unless (User.current.admin? || User.current.business? || (@department.present? && DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present?) || (User.current.user_extensions.try(:school_id) == @school.id && User.current.user_extensions.try(:identity) == 0) || - (@school.try(:customer_id) && User.current.try(:partner).try(:customer_ids) && User.current.try(:partner).try(:customer_ids).include?(@school.try(:customer_id)))) + (@school.try(:customer_id) && User.current.try(:partner).try(:customer_ids) && User.current.try(:partner).try(:customer_ids).include?(@school.try(:customer_id)))) render_403 end end diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 06a09f93..884e32a8 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -29,12 +29,21 @@ class ManagementsController < ApplicationController end def user_agents - @user_agents = UserAgent.where("user_agents.key is not order by action_status, register_status") + @user_agents = UserAgent.where("user_agents.key is not null").order("action_status asc, register_status asc") @agents_count = @user_agents.count limit = 20 @agents_pages = Paginator.new @agents_count, limit, params['page'] || 1 @offset ||= @agents_pages.offset @user_agents = paginateHelper @user_agents, limit + respond_to do |format| + format.html + format.xls{ + time = Time.now.strftime("%Y%m%d") + filename = "引流情况#{time}.xls" + send_data(user_agents_export(), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) + } + end + end # 实训课程等级体系 @@ -4369,6 +4378,39 @@ end return sheet.rows end + def user_agents_export + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "引流名单" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + count_row = 1 + sheet1.row(0).concat(["序号", "LoginId", "姓名", "学校名称", "手机号", "邮箱", "参赛人数", "参赛队伍", "访问量"]) + user_agents = UserAgent.where("user_agents.key is not null").pluck(:key).uniq + user_agents.each_with_index do |agent, index| + user = User.find_by_login(agent) + next if user.blank? + # 代理用户 + agents = UserAgent.where(key: agent) + agents_count = agents.count + competion_users = agents.where(action_status: 2).pluck(:ip) + rank_user_id = UserActions.where(ip: competion_users).pluck(:user_id).uniq + team_ids = TeamMember.where(user_id: rank_user_id).pluck(:competition_team_id).uniq + sheet1[count_row, 0] = index + 1 + sheet1[count_row, 1] = agent + sheet1[count_row, 2] = user.show_real_name + sheet1[count_row, 3] = user.school_name + sheet1[count_row, 4] = user.phone + sheet1[count_row, 5] = user.mail + sheet1[count_row, 6] = competion_users.count + sheet1[count_row, 7] = team_ids.count + sheet1[count_row, 8] = agents_count + count_row += 1 + end + book.write xls_report + xls_report.string + end + def export_subject_level_system xls_report = StringIO.new book = Spreadsheet::Workbook.new diff --git a/app/views/colleges/_student_shixun.html.erb b/app/views/colleges/_student_shixun.html.erb index 44214bc6..bdda486b 100644 --- a/app/views/colleges/_student_shixun.html.erb +++ b/app/views/colleges/_student_shixun.html.erb @@ -28,7 +28,7 @@