CaiWuXiTong/app/Console/Commands/ImportBankBills.php
shanshi e76e87e4db feat(财务台账): 发布银行账单与账户资金管理 (#1385)
发布银行账单、账户资金管理、公司规划分布与余额联动。
2026-11-25 09:14:24 +08:00

57 lines
1.8 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\BankBillStatementImporter;
use Throwable;
class ImportBankBills extends Command
{
protected $signature = 'finance-ledger:import-bank-bills
{path : 银行批量账单 XLSX/XLS/CSV 文件}
{--bank= : 招商银行、华夏银行或网商银行}
{--dry-run : 只校验,不写入账单数据}
{--replace : 先清空该银行旧账单,再导入本次文件}';
protected $description = '按已导入的银行表头导入原始账单明细';
public function handle(BankBillStatementImporter $importer): int
{
try {
$result = $importer->import(
(string) $this->argument('path'),
(string) $this->option('bank'),
(bool) $this->option('dry-run'),
(bool) $this->option('replace'),
);
} catch (Throwable $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
}
$this->info(sprintf(
'%s%s:%d 条,新增 %d 条,更新 %d 条,跳过 %d 条;涉及 %d 个账户。',
$result['dry_run'] ? '校验完成,' : '账单已导入,',
$result['bank'],
$result['rows'],
$result['inserted'],
$result['updated'],
$result['skipped'],
$result['accounts'],
));
$this->line(sprintf(
'账务日期:%s 至 %s。',
$result['first_date'] ?? '无',
$result['last_date'] ?? '无',
));
$this->line(sprintf(
'已同步 %d 个账户的当前余额。',
$result['synced_accounts'],
));
return self::SUCCESS;
}
}