Last active
August 29, 2015 14:11
-
-
Save yangxing-star/e054367e187859c2315b 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 generate_achievement_records(start_at=1.months.ago.beginning_of_month, end_at=1.months.ago.end_of_month) | |
CSV.open("#{Rails.root}/#{start_at.to_s}", 'w' ) do |writer| | |
writer << %w( 姓名 手机 新增 新增有效 维护 维护有效(录入) 维护有效(沟通记录) 录入 企业主 ) | |
User.all.each do |user| | |
count = AchievementCount.between_date(start_at, end_at).where(user_id: user.id).analysis | |
chat_count = AchievementRecord.where('created_at >= ? and created_at <= ?', start_at, end_at).where(maintain_type: 1, is_next_login: true, user_id: user.id).count | |
owner_count = Customer.where('import_at >= ? and import_at <= ?', start_at, end_at).where(user_id: user.id, career: 1).count | |
import_count = AchievementRecord.where('created_at >= ? and created_at <= ?', start_at, end_at).where(maintain_type: 3, is_next_login: true, user_id: user.id).count | |
writer << [ user.name, user.mobile, count.try(:newly_count).to_i, count.try(:newly_valid_count).to_i, count.try(:maintain_count).to_i, import_count.to_i, chat_count.to_i, count.try(:info_count).to_i, owner_count.to_i ] | |
end | |
puts '完成' | |
end | |
end | |
def generate_owner_data(start_at=1.months.ago.beginning_of_month, end_at=1.months.ago.end_of_month) | |
CSV.open("#{Rails.root}/photos", 'w' ) do |writer| | |
writer << [ '姓名', '手机', '客户姓名', '客户手机号码', '证件照' ] | |
User.all.each do |user| | |
Customer.where('import_at >= ? and import_at <= ?', start_at, end_at).where(user_id: user.id, career: 1).each do |c| | |
if c.photos.count > 1 | |
urls = c.photos.pluck(:url).join(',') | |
writer << [ user.name, user.mobile, c.name, c.mobile, urls ] | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment