CaiWuXiTong/app/Console/Commands/ImportInventoryReportAuthoritativeMonth.php

69 lines
2.4 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\InventoryWarehouseMappingAlerts;
use Illuminate\Console\Command;
use Modules\EcommerceFinance\Services\InventoryReportAuthoritativeImporter;
use Throwable;
class ImportInventoryReportAuthoritativeMonth extends Command
{
protected $signature = 'business-mirror:import-inventory-report-month
{path : 聚水潭按商品、按仓库、按月多维分析完整 XLSX 导出文件}
{--company-id=1 : 提醒任务归属公司}';
protected $description = '导入进销存报表权威月明细,保留仓储方和子仓维度';
public function handle(
InventoryReportAuthoritativeImporter $importer,
InventoryWarehouseMappingAlerts $alerts,
): int
{
try {
$result = $importer->import((string) $this->argument('path'));
} catch (Throwable $exception) {
report($exception);
$this->error('进销存权威月报导入失败:' . $exception->getMessage());
$this->warn('已保留上一版有效数据。');
return self::FAILURE;
}
$this->info(sprintf(
'进销存权威月报导入完成:月份 %s,明细 %d 行。',
$result['source_month'],
$result['source_rows'],
));
try {
$alert = $alerts->syncMonth(
$result['source_month'],
max(1, (int) $this->option('company-id')),
);
if ($alert['missing_pair_count'] > 0) {
$this->warn(sprintf(
'仓库简称提醒:%d 个仓储方/仓库组合未映射,涉及 %d 行;提醒任务 #%d 已%s。',
$alert['missing_pair_count'],
$alert['missing_row_count'],
$alert['task_id'],
match ($alert['action']) {
'created' => '创建',
'reopened' => '重新打开',
default => '更新',
},
));
} else {
$this->info('仓库简称映射完整。');
}
} catch (Throwable $exception) {
report($exception);
$this->error('进销存月报已导入,但仓库简称提醒任务创建失败:' . $exception->getMessage());
return self::FAILURE;
}
return self::SUCCESS;
}
}