Created
January 4, 2014 08:02
-
-
Save mimosa/8252898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def leaderboards_check(board_id, top=3, num=5) | |
board = Leaderboard.find_by_id(board_id) | |
return false if board.nil? | |
user_ids = board.rank.members.reverse[0, top] # 排名 | |
user_ids.each do |uid| | |
u = board.users[uid] | |
unless u.nil? | |
puts "#{uid}, #{u[:nickname]}, #{u[:city]}" # 推荐人 | |
puts '_'*88 | |
referring_ids = u[:referring].keys.sample(num) # 随机取下线ID | |
referring = User.where(:id.in => referring_ids).only(:nickname, :mobile) | |
unless referring.empty? | |
referring.each do |u| | |
puts "#{u.id}, #{u.nickname}, #{u.mobile}" # 手机号 | |
end | |
end | |
puts '_'*88 | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def users_count(started_at = Date.today, ended_at = Date.today) | |
started_at = started_at.to_date if started_at.is_a?(String) # 开始时间 | |
ended_at = ended_at.to_date if ended_at.is_a?(String) # 结束时间 | |
User.between(created_at: started_at.beginning_of_day..ended_at.end_of_day ).count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment