From 64bf3611cc0e22debaa5cbd27af09a1942bca6c8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 15:32:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=90=A5=E4=BA=BA=E5=91=98=E5=BC=95?= =?UTF-8?q?=E6=B5=81=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/memos.rb | 4 +-- app/controllers/account_controller.rb | 30 ------------------- .../competition_teams_controller.rb | 13 ++++++++ app/models/user_agent.rb | 3 ++ app/services/users_service.rb | 4 +++ 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/app/api/mobile/apis/memos.rb b/app/api/mobile/apis/memos.rb index 14654d10..98597f85 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.find_by_ip(ip) + ua = UserAgent.where(:ip => ip, :type => UserAgent::AD) unless ua - UserAgent.create(:key => params[:edu].strip, :ip => ip) + UserAgent.create(:key => params[:edu].strip, :ip => ip, :type => UserAgent::AD) end end MemosService.new.show params, current_user diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 0476b8f2..068996b0 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -377,36 +377,6 @@ class AccountController < ApplicationController else us = UsersService.new @user = us.register user_params.merge(:should_confirmation_password => false) -=begin - case Setting.self_registration - when '1' - #register_by_email_activation(@user) - unless @user.new_record? - # if params[:user][:phone] =~ /^[a-zA-Z0-9]+([._\\]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ - # redirect_to account_email_valid_path(:mail => @user.mail, :user_id => @user.id) - # else - self.logged_user = @user - redirect_to user_info_path() - # end - # flash[:notice] = l(:notice_account_register_done) - # render action: 'email_valid', locals: {:mail => @user.mail} - end - when '3' - #register_automatically(@user) - if !@user.new_record? - self.logged_user = @user - flash[:notice] = l(:notice_account_activated) - redirect_to user_info_path() - else - redirect_to signin_path - end - else - #register_manually_by_administrator(@user) - unless @user.new_record? - account_pending - end - end -=end 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 1be642d7..f180bc06 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -113,6 +113,8 @@ class CompetitionTeamsController < ApplicationController next if user_id.to_i == User.current.id new_team.team_members.create!(user_id: user_id, role: 3, competition_id: @competition.id, is_teacher: 1) end + # 创建时,记录是否是引流用户 + record_agent_user_action end end @@ -226,6 +228,8 @@ class CompetitionTeamsController < ApplicationController end team.team_members.create!(user_id: User.current.id, role: 2, competition_id: @competition.id) + # 创建时,记录是否是引流用户 + record_agent_user_action end end @@ -341,4 +345,13 @@ class CompetitionTeamsController < ApplicationController .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') .group('shixun_id').count end + + 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 + end end diff --git a/app/models/user_agent.rb b/app/models/user_agent.rb index b71c8449..9c0e6cfe 100644 --- a/app/models/user_agent.rb +++ b/app/models/user_agent.rb @@ -1,3 +1,6 @@ class UserAgent < ActiveRecord::Base + AD = 1 # 广告宣传的引流 + REGISTER = 2 # 引流注册 + COMPETITION = 3 # 引流参加竞赛 end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index d60de29c..17ce88c0 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -136,6 +136,10 @@ 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)