Last active
December 20, 2015 15:19
-
-
Save mimosa/6153334 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
seller = User.all[11] | |
trades = seller.trades.where(:pay_time.ne => nil).only(:tid, :pay_time, :payment, :total_fee, 'orders.oid', 'orders.total_fee', 'orders.outer_sku_id', 'orders.num', 'orders.price') | |
require 'csv' | |
header_row = ['交易ID', '订单ID', 'SKU编码', '数量', '价格', '数量', '实付价', '支付时间'] | |
CSV.open('tttttttt.csv', "wb:GB18030", col_sep: ',') do |csv| | |
csv << header_row | |
trades.each do |trade| | |
row = {} | |
puts "#{trade.payment} / #{trade.total_fee}" | |
rate = (trade.payment.to_f / trade.total_fee.to_f).round(2) | |
puts "= #{rate}" | |
trade.orders.each do |order| | |
csv << [ | |
trade.tid, | |
order.oid, | |
order.outer_sku_id, | |
order.num, | |
order.price, | |
(rate * (order.price * order.num)).to_s, | |
trade.pay_time | |
] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment