63 lines
2.3 KiB
PHP
63 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Business\KukaPostingBase\KukaPostingBaseImporter;
|
|
use Illuminate\Console\Command;
|
|
use Throwable;
|
|
|
|
class ImportKukaPostingBase extends Command
|
|
{
|
|
protected $signature = 'business-mirror:import-kuka-posting-base
|
|
{path : 聚水潭销售主题分析(新版)明细导出 XLSX 文件}
|
|
{--month= : 账期 YYYY-MM}
|
|
{--sheet= : 工作表名称,默认按配置读取“发货明细表”}
|
|
{--company=1 : 公司 ID}
|
|
{--dry-run : 只校验文件、店铺和行数,不写入共享镜像}';
|
|
|
|
protected $description = '导入顾家过账基础数据(仅指定 12 家店铺)';
|
|
|
|
public function handle(KukaPostingBaseImporter $importer): int
|
|
{
|
|
$period = trim((string) $this->option('month'));
|
|
if ($period === '') {
|
|
$this->error('必须指定 --month=YYYY-MM。');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
try {
|
|
$result = $importer->import(
|
|
(string) $this->argument('path'),
|
|
$period,
|
|
$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;
|
|
}
|
|
|
|
$storeRows = [];
|
|
foreach ($result['stores'] as $store => $count) {
|
|
$storeRows[] = [$store, number_format($count)];
|
|
}
|
|
|
|
$this->table(['项目', '值'], [
|
|
['模式', $result['dry_run'] ? '仅校验' : '正式导入'],
|
|
['账期', $result['period']],
|
|
['数据行数', number_format($result['rows'])],
|
|
['店铺数', number_format($result['store_count'])],
|
|
['订单数', number_format($result['order_count'])],
|
|
['非指定店铺跳过', number_format($result['skipped_store_rows'])],
|
|
['文件 SHA-256', $result['file_sha256']],
|
|
]);
|
|
$this->table(['店铺', '行数'], $storeRows);
|
|
$this->info($result['dry_run'] ? '顾家过账基础数据校验完成。' : '顾家过账基础数据已导入共享镜像。');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|