CaiWuXiTong/app/Console/Commands/ImportKukaPostingQuotation.php
chenxi c32dbe57b2 feat: 接入顾家报价单导入 (#1070)
feat: 接入顾家报价单导入 (#1070)
2026-11-11 13:20:51 +08:00

53 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Business\KukaPostingQuotation\KukaPostingQuotationImporter;
use Illuminate\Console\Command;
use Throwable;
class ImportKukaPostingQuotation extends Command
{
protected $signature = 'business-mirror:import-kuka-posting-quotation
{path : 顾家报价单 XLSX 文件}
{--sheet= : 工作表名称,默认 Sheet1}
{--company=1 : 公司 ID}
{--dry-run : 只校验文件、字段和物料编码,不写入共享镜像}';
protected $description = '导入顾家过账报价单';
public function handle(KukaPostingQuotationImporter $importer): int
{
try {
$result = $importer->import(
(string) $this->argument('path'),
$this->option('sheet') ?: null,
max(1, (int) $this->option('company')),
(bool) $this->option('dry-run'),
);
} catch (Throwable $exception) {
$this->error('顾家报价单未导入,原有数据未改变。' . $exception->getMessage());
return self::FAILURE;
}
$statuses = [];
foreach ($result['status_counts'] as $status => $count) {
$statuses[] = [$status, number_format($count)];
}
$this->table(['项目', '值'], [
['模式', $result['dry_run'] ? '仅校验' : '正式导入'],
['报价记录', number_format($result['rows'])],
['唯一物料', number_format($result['material_count'])],
['文件 SHA-256', $result['file_sha256']],
]);
if ($statuses !== []) {
$this->table(['状态', '记录数'], $statuses);
}
$this->info($result['dry_run'] ? '顾家报价单校验完成。' : '顾家报价单已导入共享镜像。');
return self::SUCCESS;
}
}