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.
|
|
|
|
# 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_at < ua.created_at
|
|
|
|
|
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
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|