Created
September 2, 2012 16:15
-
-
Save mimosz/3601022 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
# -*- encoding: utf-8 -*- | |
require File.join(__FILE__, '../../../../Desktop/sms_list') | |
user = User.all[5] | |
mobiles = sms_list.uniq | |
members = user.members.in('receivers.receiver_mobile' => mobiles ) | |
buyers = members.only(:buyer_nick).distinct(:buyer_nick) | |
range = '2012-10-11'.to_date.beginning_of_day..'2012-10-21'.to_date.end_of_day | |
trades = user.trades.where(pay_time: range) | |
total = { num: 0, payment: 0 } | |
sms = { num: 0, payment: 0, nicks:[] } | |
trades.each do |trade| | |
has_sms = false | |
if buyers.include?(trade.buyer_nick) | |
sms[:nicks] << trade.buyer_nick | |
has_sms = true | |
end | |
trade.orders.each do |order| | |
total[:num] += order.num | |
total[:payment] += order.payment | |
if has_sms | |
sms[:num] += order.num | |
sms[:payment] += order.payment | |
end | |
end | |
end | |
puts '手机号:' + mobiles.count.to_s | |
puts '会员数:' + members.count.to_s | |
puts '昵称:' + buyers.count.to_s | |
puts total | |
puts sms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment