CaiWuXiTong/app/Console/Commands/ImportAlibabaAccountBalances.php

47 lines
1.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 Illuminate\Console\Command;
use Modules\EcommerceFinance\Services\AlibabaAccountBalanceWorkbookImporter;
use Throwable;
class ImportAlibabaAccountBalances extends Command
{
protected $signature = 'business:import-alibaba-account-balances
{path : 阿里巴巴账户余额 Excel 文件路径}
{--source-name= : 原始文件名,用于导入来源追溯}
{--dry-run : 只校验和统计,不写入共享业务库}';
protected $description = '校验并导入阿里巴巴账户月末余额快照';
public function handle(AlibabaAccountBalanceWorkbookImporter $importer): int
{
$path = (string) $this->argument('path');
try {
$sourceName = trim((string) $this->option('source-name'));
$result = $importer->import(
$path,
$sourceName !== '' ? $sourceName : basename($path),
(bool) $this->option('dry-run'),
);
} catch (Throwable $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
}
$action = $this->option('dry-run') ? '校验完成' : '导入完成';
$this->info(sprintf(
'%s:共 %d 条,新增 %d 条,更新 %d 条。',
$action,
$result['total'],
$result['created'],
$result['updated'],
));
return self::SUCCESS;
}
}