You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/lib/tasks/user_agent.rake

39 lines
1.2 KiB

5 years ago
# 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
# 即代理之前报名的
5 years ago
if team_member.created_at < ua.created_at
5 years ago
params = params.merge(:action_status => 1)
else
# 代理之后报名的
params = params.merge(:action_status => 2)
end
end
if ua.action_status != 2 # 代理成功报名的成绩不受影响
ua.update_attributes(params)
end
5 years ago
end
end
end