CaiWuXiTong/app/Console/Commands/ImportCourierFreight.php
qiuxiang 1c90b64c29 快递运费:新增导入命令与页面数据表
财务经营报表 › 快递运费 之前是空页面。现在:
- 新增 courier_freight_rows 表(来源 / 成品配件 / 交易单号 / 提供成本运费);
- 新增 courier-freight:import 命令(xlsx / csv,按表头名匹配,支持 --replace);
- 把聚水潭导出用的 xlsx 流式读取器改成通用名 XlsxSheetReader(本次文件 57.8 万行、解压后 115MB,必须流式读);
- 页面按来源 / 成品配件 / 交易单号查询,列设置与分页复用通用目录表。
2026-10-08 13:20:01 +08:00

42 lines
1.2 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 App\Business\CourierFreightImporter;
use Illuminate\Console\Command;
use Throwable;
class ImportCourierFreight extends Command
{
protected $signature = 'courier-freight:import
{file : xlsx / csv 文件路径}
{--company=1 : 公司 ID}
{--replace : 先清空该公司已有的快递运费明细}';
protected $description = '导入「快递运费」数据(财务经营报表 › 快递运费)';
public function handle(CourierFreightImporter $importer): int
{
try {
$result = $importer->import(
(string) $this->argument('file'),
(int) $this->option('company'),
(bool) $this->option('replace'),
);
} catch (Throwable $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
}
$sources = $result['sources'];
$result['sources'] = count($sources);
$this->info(json_encode($result, JSON_UNESCAPED_UNICODE));
foreach ($sources as $name => $count) {
$this->line(sprintf(' %s:%d 行', $name === '' ? '(空来源)' : $name, $count));
}
return self::SUCCESS;
}
}