CaiWuXiTong/app/Console/Commands/ImportWangshangBankBills.php
92451 67c85678e6 feat: 接入网商银行每日动账明细 (#831)
Co-authored-by: 92451 <924518135@qq.com>
Co-committed-by: 92451 <924518135@qq.com>
2026-11-02 20:58:42 +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\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'],
));
return self::SUCCESS;
}
}