Created
April 20, 2012 06:13
-
-
Save mimosz/2426495 to your computer and use it in GitHub Desktop.
Ruby:品牌特卖订单导出
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
require 'csv' | |
user = User.all[0] | |
user_id = user.nick.to_s | |
start_at = "2012-03-01".to_date | |
end_at = "2012-03-31".to_date | |
range = (start_at.beginning_of_day..end_at.end_of_day) | |
trades = Trade.where(seller_nick: user_id, pay_time: range, is_brand_sale: true) | |
CSV.open("./#{Time.now.to_i}.csv", "wb:GB18030") do |csv| | |
csv << ['订单号', '宝贝ID', '款式', '商家SKU', '数量','应付', '折扣', '实付', '付款时间', '发货时间', '退款ID'] | |
trades.each do |trade| | |
trade.orders.each do |order| | |
csv << [ | |
order.oid, | |
order.num_iid, | |
order.outer_iid, | |
order.outer_sku_id, | |
order.num, | |
order.total_fee, | |
order.discount_fee, | |
order.payment, | |
trade.pay_time, | |
trade.consign_time, | |
order.refund_id, | |
] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment