diff --git a/lib/tasks/user_agent.rake b/lib/tasks/user_agent.rake index b80a6fb4..98d6ef8e 100644 --- a/lib/tasks/user_agent.rake +++ b/lib/tasks/user_agent.rake @@ -5,14 +5,15 @@ namespace :sync do task :user_agent => :environment do UserAgent.find_each do |ua| puts ua.id - user_action = UserActions.find_by_ip(ua.ip) + user_action = UserActions.where(ip: ua.ip).pluck(:user_id) params = {} # 用户注册情况 if user_action - user = User.find(user_action.try(:user_id)) + created_on = User.where(id: user_action).maximum(:created_on) # 即代理之前注册 - if user.created_on < ua.created_at + + if created_on < ua.created_at params = params.merge(:register_status => 1) else # 代理之后注册的 @@ -21,10 +22,10 @@ namespace :sync do end # 用户报名情况 - team_member = TeamMember.find_by_user_id(user_action.try(:user_id)) - if team_member + created_at = TeamMember.where(user_id: user_action.try(:user_id)).maximum(:created_at) + if created_at # 即代理之前报名的 - if team_member.created_at < ua.created_at + if created_at < ua.created_at params = params.merge(:action_status => 1) else # 代理之后报名的