- 商品来源从「下单商品 jst_OrderItem」改为「出库实发商品」:按出库单 io_id 关联发货数据视图 Jst_SendData_View_extension 取实发条码/数量,jst_OrderItem/dws 仅作兜底。消除组合/多规格包裹的多吐行与数量错误。 - 长宽高/体积/供应商/重量优先取自发货视图(体积=长×宽×高,整箱算一次)。 - 导出明细:多条码(逗号拼接)按条码拆条,数量/体积按条码数均摊,合并求和后与整行一致。 - 去除以 @ 开头、去@后已存在的重复单号(换单/重拉产生)。 - 发货单查询改为按主键翻页 + PHP 窗口过滤,避免 send_time 无索引全表扫。 - 逐天预载 dws,进度回调输出扫描/命中进度。 新增命令:jst:dump(导出对比CSV)、jst:row(抽查单号)、jst:dedup-at(去@重复)。 9.1-9.16 全量对比:共有 19.3 万包裹,数量/名称/条码/体积/供应商等字段一致率 99.9%; 导出明细件数结构 99.87% 一致。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014nvGZkg27YMEdhRy6EiUwf
46 lines
2.0 KiB
PHP
46 lines
2.0 KiB
PHP
<?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;
|
||
}
|
||
}
|