Created
November 12, 2012 08:39
-
-
Save mimosz/4058187 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
user = User.all[1] | |
date = '2012-11-11'.to_date | |
range = date.beginning_of_day..date.end_of_day | |
trades = user.trades.where(created: range).sales.sold.norefund | |
trades = trades.only(:payment, :num) | |
payment = 0 | |
num = 0 | |
nulls = [] | |
trades.each do |trade| | |
if trade.payment && trade.num | |
payment += trade.payment | |
num += trade.num | |
else | |
nulls << trade._id | |
end | |
end | |
Trade.in(_id: nulls).delete_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment