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.where(ip: ua.ip).pluck(:user_id)
|
|
|
|
|
params = {}
|
|
|
|
|
# 用户注册情况
|
|
|
|
|
if user_action
|
|
|
|
|
created_on = User.where(id: user_action).maximum(:created_on)
|
|
|
|
|
|
|
|
|
|
# 即代理之前注册
|
|
|
|
|
if created_on.present?
|
|
|
|
|
if created_on < ua.created_at
|
|
|
|
|
params = params.merge(:register_status => 1)
|
|
|
|
|
else
|
|
|
|
|
# 代理之后注册的
|
|
|
|
|
params = params.merge(:register_status => 2)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 用户报名情况
|
|
|
|
|
created_at = TeamMember.where(user_id: user_action).maximum(:created_at)
|
|
|
|
|
if created_at
|
|
|
|
|
# 即代理之前报名的
|
|
|
|
|
if 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
|