50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace Modules\EcommerceFinance\Console;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Modules\EcommerceFinance\Services\DingInvoiceWorkbookImporter;
|
||
use Throwable;
|
||
|
||
class ImportDingInvoiceWorkbook extends Command
|
||
{
|
||
protected $signature = 'ding-invoices:import
|
||
{file : 报销发票识别 Excel 文件路径}
|
||
{--scope=personal_permission : 镜像来源范围}
|
||
{--keep-existing-months : 保留同月份现有镜像后再写入}';
|
||
|
||
protected $description = '导入“报销发票识别”台账到 OA 发票数据镜像';
|
||
|
||
public function handle(DingInvoiceWorkbookImporter $importer): int
|
||
{
|
||
$startedAt = microtime(true);
|
||
try {
|
||
$result = $importer->import(
|
||
(string) $this->argument('file'),
|
||
(string) $this->option('scope'),
|
||
! $this->option('keep-existing-months'),
|
||
);
|
||
} catch (Throwable $exception) {
|
||
report($exception);
|
||
$this->error($exception->getMessage());
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$this->info(sprintf(
|
||
'发票台账导入完成:%d 个流程、%d 张发票、开票金额 %.2f 元;月份 %s。',
|
||
$result['flows'],
|
||
$result['invoices'],
|
||
$result['invoice_total'],
|
||
implode(',', $result['months']),
|
||
));
|
||
$this->line(sprintf(
|
||
'耗时 %.2f 秒;PHP 峰值内存 %.1f MiB。',
|
||
microtime(true) - $startedAt,
|
||
memory_get_peak_usage(true) / 1024 / 1024,
|
||
));
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|