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

62 lines
2.1 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\WangshangBankBillImporter;
use Throwable;
class ImportWangshangBankBills extends Command
{
protected $signature = 'finance-ledger:import-wangshang-bank
{path : 网商银行批次 ZIP 或 manifest.json}
{--date= : 账单日期 YYYY-MM-DD,默认前一天}
{--dry-run : 只校验,不写入财务台账}';
protected $description = '批量导入网商银行影刀账单到银行账单';
public function handle(WangshangBankBillImporter $importer): int
{
$date = trim((string) ($this->option('date') ?: now()->subDay()->toDateString()));
try {
$result = $importer->import(
(string) $this->argument('path'),
$date,
(bool) $this->option('dry-run'),
);
} catch (Throwable $exception) {
$this->error('网商银行影刀账单未导入,保留原有银行账单。' . $exception->getMessage());
return self::FAILURE;
}
$this->table(
['公司', '账户尾号', '页面笔数', '有效笔数', '收入合计', '支出合计'],
array_map(static fn (array $row): array => [
$row['company'],
$row['account_last4'],
$row['expected_rows'] ?? '-',
$row['rows'],
number_format((float) $row['income'], 2),
number_format((float) $row['expense'], 2),
], $result['accounts']),
);
$this->info(sprintf(
'%s网商银行账单:%d 个账户,%d 笔,收入 %.2f,支出 %.2f。',
$result['dry_run'] ? '校验完成,' : '已写入银行账单,',
count($result['accounts']),
$result['rows'],
$result['income'],
$result['expense'],
));
$this->line(sprintf(
'已同步 %d 个账户的当前余额。',
$result['synced_accounts'],
));
return self::SUCCESS;
}
}