46 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Modules\EcommerceFinance\Repositories\ShippingOrderRepository;
class JstDump extends Command
{
protected $signature = 'jst:dump {--mode=merged} {--from=} {--to=}';
protected $description = '把 caiwu 发货数据(合并/明细)以 CSV 输出到 STDOUT,供比对';
public function handle(ShippingOrderRepository $repo): int
{
@ini_set('memory_limit', '1024M');
@set_time_limit(0);
$mode = $this->option('mode') === 'detail' ? 'detail' : 'merged';
$filters = [
'ship_from' => (string) $this->option('from'),
'ship_to' => (string) $this->option('to'),
];
$cols = [
['express_no', '快递单号'], ['trade_no', '交易单号'], ['item_id', '商品ID'], ['barcode', '条形码'],
['product_name', '商品名称'], ['qty', '数量'], ['pkg_count', '件数'], ['warehouse_name', '仓库'],
['supplier_name', '供应商'], ['platform', '平台'], ['shop_name', '店铺名称'],
['volume_cm3', '体积'], ['length_cm', '长'], ['width_cm', '宽'], ['height_cm', '高'],
['actual_weight', '实称重量'], ['online_weight', '线上重量'], ['freight', '运费'],
['ship_time', '发货时间'], ['pay_time', '付款时间'], ['product_code', '货号'],
['receiver_state', '省'], ['receiver_city', '市'], ['receiver_district', '区'],
['package_no', '配货单号'], ['amount', '金额'],
];
$fh = fopen('php://output', 'w');
fwrite($fh, chr(0xEF).chr(0xBB).chr(0xBF));
fputcsv($fh, array_map(fn ($c) => $c[1], $cols));
$n = 0;
foreach ($repo->exportRows($filters, 2000, $mode) as $row) {
fputcsv($fh, array_map(fn ($c) => (string) ($row[$c[0]] ?? ''), $cols));
$n++;
}
fflush($fh);
fwrite(STDERR, 'wrote '.$n.' rows ('.$mode.')'.PHP_EOL);
return self::SUCCESS;
}
}