CaiWuXiTong/app/Console/Commands/ImportBankBillsDirectory.php
shanshi 39769abd26 feat(财务台账): 接入招商银行邮件账单 (#1392)
接入招商银行邮件账单下载、整目录导入和余额同步。
2026-11-25 10:11:08 +08:00

58 lines
1.9 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\BankBillStatementDirectoryImporter;
use Throwable;
class ImportBankBillsDirectory extends Command
{
protected $signature = 'finance-ledger:import-bank-bills-directory
{path : 已解压的银行账单目录}
{--bank= : 招商银行、华夏银行或网商银行}
{--dry-run : 只校验,不写入账单数据}';
protected $description = '一次导入目录中的多份银行账单,并统一同步余额';
public function handle(BankBillStatementDirectoryImporter $importer): int
{
try {
$result = $importer->import(
(string) $this->argument('path'),
(string) $this->option('bank'),
(bool) $this->option('dry-run'),
);
} catch (Throwable $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
}
$this->info(sprintf(
'%s%s:%d 个文件,成功 %d 个,失败 %d 个,共 %d 条;新增 %d 条,更新 %d 条,跳过 %d 条。',
$result['dry_run'] ? '校验完成,' : '账单已导入,',
$result['bank'],
$result['files'],
$result['imported_files'],
$result['failed_files'],
$result['rows'],
$result['inserted'],
$result['updated'],
$result['skipped'],
));
$this->line(sprintf(
'账务日期:%s 至 %s;涉及 %d 个账户,已同步 %d 个账户余额。',
$result['first_date'] ?? '无',
$result['last_date'] ?? '无',
$result['accounts'],
$result['synced_accounts'],
));
foreach ($result['failures'] as $failure) {
$this->error($failure);
}
return $result['failed_files'] === 0 ? self::SUCCESS : self::FAILURE;
}
}