From 64c078abf2f87c500f72adeea38967a785910e05 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 19 Jul 2019 15:55:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E6=B5=81=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/account_controller.rb | 5 +-- app/controllers/welcome_controller.rb | 11 +++++++ app/helpers/welcome_helper.rb | 21 ++++++++++++ app/views/welcome/_user_agent_list.html.erb | 33 +++++++++++++++++++ app/views/welcome/user_agents.html.erb | 9 +++++ .../20190719062616_add_ip_for_user_actions.rb | 10 ++++++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 app/views/welcome/_user_agent_list.html.erb create mode 100644 app/views/welcome/user_agents.html.erb create mode 100644 db/migrate/20190719062616_add_ip_for_user_actions.rb diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 64833a14..b0088d44 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -80,7 +80,7 @@ class AccountController < ApplicationController set_autologin_cookie(@user) end # 记录用户登录行为 - UserActions.create(:action_id => @user.id, :action_type => "Login", :user_id => @user.id) + UserActions.create(:action_id => @user.id, :action_type => "Login", :user_id => @user.id, :ip => request.remote_ip) end respond_to do |format| format.js @@ -381,6 +381,7 @@ class AccountController < ApplicationController ip = request.remote_ip ua = UserAgent.find_by_ip(ip) ua.update_column(:agent_type, UserAgent::USER_REGISTER) if ua + UserActions.create(:action_id => @user.id, :action_type => "Register", :user_id => @user.id, :ip => ip) if !@user.new_record? self.logged_user = @user flash[:notice] = l(:notice_account_activated) @@ -1403,7 +1404,7 @@ class AccountController < ApplicationController code = /\d*/ # 记录用户登录行为 - UserActions.create(:action_id => User.current.id, :action_type => "Login", :user_id => User.current.id) + UserActions.create(:action_id => User.current.id, :action_type => "Login", :user_id => User.current.id, :ip => request.remote_ip) =begin if user.created_on.strftime('%Y-%m-%d %H:%M:%S') > "2018-01-01 00:00:00" && user.phone.blank? redirect_to change_or_bind_path(:type => 'phone') diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 4feaa3d0..85dff69a 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -40,6 +40,17 @@ class WelcomeController < ApplicationController render :json => {status: 0, message: "success"} end + # 运营引流个人数据展示 + def user_agents + @user_agents = UserAgent.find_by_key(params[:edu]) + @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 shixun_to_local identifiers = params[:identifiers].split(",") diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 2306adb9..87d1097d 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -22,6 +22,27 @@ module WelcomeHelper include CoursesHelper include ProjectsHelper + # 引流注册情况 + def register_info user_agent + if user_agent.agent_type.to_i == UserAgent::USER_AD + user_id = UserActions.find_by_ip(user_agent.ip).try(:user_id) + if user_id && UserActions.where("user_id = #{user_id} and created_at < '2019-07-15 00:00:00'").present? + "代理前注册" + else + "未转换" + end + elsif user_agent.agent_type.to_i == UserAgent::USER_REGISTER || UserActions.find_by_ip(user_agent.ip) + "代理后注册" + else + user_id = UserActions.find_by_ip(user_agent.ip).try(:user_id) + if user_id && UserActions.where("user_id = #{user_id} and created_at < '2019-07-15 00:00:00'").present? + "代理前注册" + else + "代理后注册" + end + end + end + def color_change index case index when 0 diff --git a/app/views/welcome/_user_agent_list.html.erb b/app/views/welcome/_user_agent_list.html.erb new file mode 100644 index 00000000..c677c6c7 --- /dev/null +++ b/app/views/welcome/_user_agent_list.html.erb @@ -0,0 +1,33 @@ + + + + + + + + + + + <% @user_agents.each_with_index do |ua, index| %> + <% user = User.find_by_login(ua.key) %> + + + + + + + + + + <% end %> + +
ID代理人登录名代理人姓名注册情况竞赛报名ip
<%= index+1 %><%= link_to ua.key, user_path(ua.key), :target => "_blank" %><%= link_to user.try(:show_real_name), user_path(user), target:'_blank' %><%= register_info(ua) %><%= user.agent_type.to_i == UserAgent::USER_COMPETITION ? "已报名" : "未报名" %><%= ua.ip %><%= "理由" %>
+
+
+
+ +
+
+
diff --git a/app/views/welcome/user_agents.html.erb b/app/views/welcome/user_agents.html.erb new file mode 100644 index 00000000..4fe6649c --- /dev/null +++ b/app/views/welcome/user_agents.html.erb @@ -0,0 +1,9 @@ +
+
+ 统计总计: + 引流总人数<%= @agents_count %>人, +
+
+
+ <%= render :partial => "welcome/user_agent_list" %> +
\ No newline at end of file diff --git a/db/migrate/20190719062616_add_ip_for_user_actions.rb b/db/migrate/20190719062616_add_ip_for_user_actions.rb new file mode 100644 index 00000000..d1297176 --- /dev/null +++ b/db/migrate/20190719062616_add_ip_for_user_actions.rb @@ -0,0 +1,10 @@ +class AddIpForUserActions < ActiveRecord::Migration + def up + add_column :user_actions, :ip, :string + + UserAgent.where("agent_type is null").update_all(:agent_type => 1) + end + + def down + end +end