diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index c631d56f..6e9daea1 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -140,7 +140,6 @@ module Mobile # Rails.logger.info("########### host is #{request.host}") if (Rails.env.development? && session[:user_id].blank?) || - (session[:user_id].blank? && request.host.include?("testbdweb")) || params[:action] == "privateGit" session[:user_id] = 12 #116 end diff --git a/app/api/mobile/apis/memos.rb b/app/api/mobile/apis/memos.rb index 98597f85..89412316 100644 --- a/app/api/mobile/apis/memos.rb +++ b/app/api/mobile/apis/memos.rb @@ -33,9 +33,9 @@ module Mobile if params[:edu] Rails.logger.info("####11111222##{@env['HTTP_X_REAL_IP']}") ip = @env['HTTP_X_REAL_IP'] - ua = UserAgent.where(:ip => ip, :type => UserAgent::AD) - unless ua - UserAgent.create(:key => params[:edu].strip, :ip => ip, :type => UserAgent::AD) + ua = UserAgent.where(:ip => ip) + if ua.blank? + UserAgent.create!(:key => params[:edu].strip, :ip => ip, :type => UserAgent::AD) end end MemosService.new.show params, current_user diff --git a/app/api/mobile/entities/project_package.rb b/app/api/mobile/entities/project_package.rb index 278e9b85..50d4ff69 100644 --- a/app/api/mobile/entities/project_package.rb +++ b/app/api/mobile/entities/project_package.rb @@ -17,8 +17,8 @@ module Mobile expose :bidding_users_count, if: { type: :index } expose :min_price expose :max_price - expose :contact_name, if: ->(package, opts){ opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business? } - expose :contact_phone, if: ->(package, opts){ opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business? } + expose :contact_name, if: ->(package, opts){ opts[:user].present? && (opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business?) } + expose :contact_phone, if: ->(package, opts){ opts[:user].present? && (opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business?) } expose :updated_at do |package, _| package.updated_at.strftime('%Y-%m-%d %H:%M:%S') @@ -65,6 +65,7 @@ module Mobile expose :operation, if: { type: :show } do |package, opts| user = opts[:user] + return {} if user.blank? is_creator = user.id == package.creator_id is_admin = user.admin? || user.business? diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 068996b0..d362cde3 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -377,6 +377,10 @@ class AccountController < ApplicationController else us = UsersService.new @user = us.register user_params.merge(:should_confirmation_password => false) + # 注册时,记录是否是引流用户 + ip = request.remote_ip + ua = UserAgent.find_by_id(:ip => ip) + ua.update_column(:type, UserAgent::REGISTER) if ua if !@user.new_record? self.logged_user = @user flash[:notice] = l(:notice_account_activated) diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index f180bc06..092426ef 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -348,10 +348,8 @@ class CompetitionTeamsController < ApplicationController def record_agent_user_action # 注册时,记录是否是引流用户 - ip = @env['HTTP_X_REAL_IP'] - ua = UserAgent.where(:ip => ip, :type => UserAgent::AD).take - if ua && UserAgent.where(:ip => ip, :type => UserAgent::COMPETITION).blank? - UserAgent.create(:key => ua.key, :ip => ip, :type => UserAgent::COMPETITION, :user_id => User.current.id) - end + ip = request.remote_ip + ua = UserAgent.find_by_id(:ip => ip) + ua.update_column(:type, UserAgent::COMPETITION) if ua end end diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b4de6576..156ae951 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -28,6 +28,15 @@ class ManagementsController < ApplicationController render :json => {status: 1} end + def user_agents + @user_agents = UserAgent.where("user_agents.key is not null") + @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 + end + # 实训课程等级体系 def subject_level_system @levels = SubjectLevelSystem.all diff --git a/app/controllers/project_packages_controller.rb b/app/controllers/project_packages_controller.rb index fe2c1c13..6721c1c4 100644 --- a/app/controllers/project_packages_controller.rb +++ b/app/controllers/project_packages_controller.rb @@ -1,7 +1,7 @@ # encoding=utf-8 # For react class ProjectPackagesController < ApplicationController - before_filter :require_login, :except => [:index] + before_filter :require_login, :except => [:index, :show] include ApplicationHelper diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 17ce88c0..d60de29c 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -136,10 +136,6 @@ class UsersService ue = @user.user_extensions ||= UserExtensions.new ue.user_id = @user.id ue.save - # 注册时,记录是否是引流用户 - ip = @env['HTTP_X_REAL_IP'] - ua = UserAgent.where(:ip => ip, :type => UserAgent::AD).take - UserAgent.create(:key => ua.key, :ip => ip, :type => UserAgent::REGISTER, :user_id => @user.id) if ua end @user #img_url = url_to_avatar(@user) diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index f0fefec5..3392f099 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -145,6 +145,7 @@
  • <%= link_to "升级通知", update_notice_managements_path %>
  • <%= link_to "门户banner设置", setting_banner_managements_path %>
  • <%= link_to "培训会", training_2018_managements_path %>
  • +
  • <%= link_to "引流情况", user_agents_managements_path %>
  • diff --git a/app/views/libraries/_library_list.html.erb b/app/views/libraries/_library_list.html.erb index 2b142b44..fc0e6e62 100644 --- a/app/views/libraries/_library_list.html.erb +++ b/app/views/libraries/_library_list.html.erb @@ -2,7 +2,7 @@ <% if @libraries.present? %> <% @libraries.each do |library| %>
  • - <% image_url = library.cover.present? ? named_attachment_path(library.cover.id, library.cover.filename) : 'educoder/library-default-cover.png' %> + <% image_url = library.cover.present? ? download_attachment_path(library.cover.id) : 'educoder/library-default-cover.png' %> <%= image_tag(image_url, width: 120, height: 90, class: 'mr15 mt3 radius4') %>

    diff --git a/app/views/managements/_user_agent_list.html.erb b/app/views/managements/_user_agent_list.html.erb new file mode 100644 index 00000000..43886c8d --- /dev/null +++ b/app/views/managements/_user_agent_list.html.erb @@ -0,0 +1,66 @@ + + + + + + + + + + + + + <% @user_agents.each do |ua| %> + <% user = User.find_by_login(ua.key) %> + <% user_extension = user.extensions %> + <% school = user_extension.school %> + + + + + + + + + + <% end %> + +
    ID代理人登录名代理人姓名学校竞赛报名状态ipip负责人
    <%= ua.id %><%= link_to ua.key, user_path(ua.key), :target => "_blank" %><%= link_to user.try(:show_real_name), user_path(user), target:'_blank' %><%= school.name %><%= "--" %><%= ua.ip %><%= "理由" %>
    +

    +
    +
    +
      + <%= pagination_links_full @agents_pages, @agents_count, :per_page_links => false, :flag => true, :is_new => true %> +
    +
    +
    +
    + \ No newline at end of file diff --git a/app/views/managements/user_agents.html.erb b/app/views/managements/user_agents.html.erb new file mode 100644 index 00000000..d29e7bec --- /dev/null +++ b/app/views/managements/user_agents.html.erb @@ -0,0 +1,19 @@ +<%= form_tag(url_for(departments_part_managements_path),:id=>"department_part_search",:method => "post",:remote=>true) do %> +
    + + 搜索 + 清除 + <%= link_to "关联代理人",add_departments_part_managements_path(),:class => "task-btn task-btn-green fr mt6 mr30" %> + +
    +<% end %> +
    + <%= render :partial => "managements/user_agent_list" %> +
    + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a92555c1..427b4744 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -537,6 +537,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 resources :managements do collection do + get 'user_agents' get 'evaluate_simple' get 'hidden_course' match 'training_2018',:via=>[:get,:post]