From 243de8ed7e5a23f84bd9953198aa69f00053e195 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 18:56:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=8A=A5=E9=94=99?= 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 | 4 ++++ app/controllers/competition_teams_controller.rb | 6 ++---- app/services/users_service.rb | 4 ---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/api/mobile/apis/memos.rb b/app/api/mobile/apis/memos.rb index 98597f85..4e8f4f97 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) + ua = UserAgent.where(:ip => ip) unless ua - UserAgent.create(:key => params[:edu].strip, :ip => ip, :type => UserAgent::AD) + 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 068996b0..849999da 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 = @env['HTTP_X_REAL_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..a269d71e 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -349,9 +349,7 @@ 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 + ua = UserAgent.find_by_id(:ip => ip) + ua.update_column(:type, UserAgent::COMPETITION) if ua end end 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)