user agents rake

dev_aliyun
jingquan huang 5 years ago
parent 972c8e6f3c
commit e20628fcc2

@ -42,7 +42,7 @@ class WelcomeController < ApplicationController
# 运营引流个人数据展示
def user_agents
@user_agents = UserAgent.where(key: params[:edu]).includes(:user_actionss)
@user_agents = UserAgent.where(key: params[:edu])
@agents_count = @user_agents.count
limit = 20
@agents_pages = Paginator.new @agents_count, limit, params['page'] || 1

@ -24,22 +24,41 @@ module WelcomeHelper
# 引流注册情况
def register_info user_agent
if user_agent.agent_type.to_i == UserAgent::USER_AD
user_id = user_agent.user_actionss.first.try(:user_id)
if user_id && User.where("id = #{user_id} and created_on < '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 = user_agent.user_actionss.first.try(:user_id)
if user_id && User.where("id = #{user_id} and created_on < '2019-07-15 00:00:00'").present?
"代理前注册"
else
"代理后注册"
case user_agent.register_status
when 0
"改IP未登录"
when 1
"代理之前注册"
when 2
"代理之后注册"
end
# if user_agent.agent_type.to_i == UserAgent::USER_AD
# user_id = user_agent.user_actionss.first.try(:user_id)
# if user_id && User.where("id = #{user_id} and created_on < '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 = user_agent.user_actionss.first.try(:user_id)
# if user_id && User.where("id = #{user_id} and created_on < '2019-07-15 00:00:00'").present?
# "代理前注册"
# else
# "代理后注册"
# end
# end
end
def competion_info user_agent
case user_agent.action_status
when 0
"未报名"
when 1
"代理之前报名"
when 2
"代理之后报名"
end
end

@ -1,3 +1,5 @@
# register_status: 0未注册1: 代理之前注册2代理之后注册
# action_status: 0未注册1: 代理之前报名2代理之后报名
class UserAgent < ActiveRecord::Base
has_many :user_actionss, :foreign_key => "ip", :primary_key => "ip"
USER_AD = 1 # 广告宣传的引流

@ -15,7 +15,7 @@
<td class="edu-txt-left"><span><%= link_to ua.key, user_path(ua.key), :target => "_blank" %></span></td>
<td><%= link_to user.try(:show_real_name), user_path(user), target:'_blank' %></td>
<td><%= register_info(ua) %></td>
<td><%= ua.agent_type.to_i == UserAgent::USER_COMPETITION ? "已报名" : "未报名" %></td>
<td><%= competion_info(ua) %></td>
<td><%= ua.ip %></td>
</tr>
<% end %>

@ -0,0 +1,37 @@
# register_status: 0未注册1: 代理之前注册2代理之后注册
# register_action: 0未报名1: 代理之前报名2代理之后报名
desc "sync user_agents"
namespace :sync do
task :user_agent => :environment do
UserAgent.find_each do |ua|
puts ua.id
user_action = UserActions.find_by_ip(ua.ip)
params = {}
# 用户注册情况
if user_action
user = User.find(user_action.try(:user_id))
# 即代理之前注册
if user.created_on < ua.created_at
params = params.merge(:register_status => 1)
else
# 代理之后注册的
params = params.merge(:register_status => 2)
end
end
# 用户报名情况
team_member = TeamMember.find_by_user_id(user_action.try(:user_id))
if team_member
# 即代理之前报名的
if team_member.created_on < ua.created_at
params = params.merge(:action_status => 1)
else
# 代理之后报名的
params = params.merge(:action_status => 2)
end
end
ua.update_attributes(params)
end
end
end
Loading…
Cancel
Save