Skip to content

Instantly share code, notes, and snippets.

@yangxing-star
Created November 18, 2014 03:04
Show Gist options
  • Save yangxing-star/f2a7822b3e2aaf494123 to your computer and use it in GitHub Desktop.
Save yangxing-star/f2a7822b3e2aaf494123 to your computer and use it in GitHub Desktop.
绩效计算
def gene_achievement_records
CSV.generate({col_sep: "\t"}) do |csv|
csv << %w( 姓名 手机 新增 新增有效 维护 维护有效(录入) 维护有效(沟通记录) 录入 企业主 )
User.all.each do |user|
co = AchievementCount.between_date('2014-09-01', '2014-09-30').where(user_id: user.id).analysis
import_count = AchievementRecord.where('created_at >= ? and created_at <= ?', '2014-09-01', '2014-09-30').where(maintain_type: 3, is_next_login: true, user_id: user.id).count
chat_count = AchievementRecord.where('created_at >= ? and created_at <= ?', '2014-09-01', '2014-09-30').where(maintain_type: 1, is_next_login: true, user_id: user.id).count
owner_count = Customer.where('import_at >= ? and import_at <= ?', '2014-09-01', '2014-09-30').where(user_id: user.id, career: '企业主').count
csv << [ user.name, user.mobile, co.try(:newly_count), co.try(:newly_valid_count), co.try(:maintain_count), import_count, chat_count, co.try(:info_count), owner_count ]
end
end
end
def gene_p
CSV.generate({col_sep: "\t"}) do |csv|
csv << [ '姓名', '手机', '客户姓名', '客户手机号码', '证件照' ]
User.all.each do |user|
Customer.where('import_at >= ? and import_at <= ?', '2014-09-01', '2014-09-30').where(user_id: user.id, career: '企业主').each do |c|
if c.photos.count > 1
urls = c.photos.pluck(:url).join(',')
csv << [ 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