CaiWuXiTong/app/Console/Commands/ImportCompanyAlipayBills.php
92451 040d0d08ae feat: 接入公司支付宝账单与台账手动编辑 (#797)
接入公司非店铺支付宝账单、受限批处理导入,并为账户总表及每日资金流水增加管理员手动编辑与审计。
Co-authored-by: 92451 <924518135@qq.com>
Co-committed-by: 92451 <924518135@qq.com>
2026-10-30 20:03:04 +08:00

59 lines
2.2 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\CompanyAlipayBillImporter;
use Throwable;
class ImportCompanyAlipayBills extends Command
{
protected $signature = 'finance-ledger:import-company-alipay
{path : 支付宝交易记录 CSV/XLSX/XLS 文件}
{--date= : 账单日期 YYYY-MM-DD,默认前一天}
{--account= : 支付宝登录账号,用于匹配账户总表}
{--account-short= : 账户总表简称;账号重复时必填}
{--dry-run : 只校验,不写入财务台账}';
protected $description = '导入公司非店铺支付宝前一天交易到财务台账动账明细';
public function handle(CompanyAlipayBillImporter $importer): int
{
$date = trim((string) ($this->option('date') ?: now()->subDay()->toDateString()));
$account = trim((string) $this->option('account'));
if ($account === '') {
$this->error('必须使用 --account 指定支付宝登录账号。');
return self::FAILURE;
}
try {
$result = $importer->import(
(string) $this->argument('path'),
$account,
$date,
$this->option('account-short') ?: null,
(bool) $this->option('dry-run'),
);
} catch (Throwable $exception) {
$this->error('支付宝账单未导入,保留原有动账明细。' . $exception->getMessage());
return self::FAILURE;
}
$this->table(['项目', '值'], [
['校验模式', $result['dry_run'] ? '仅校验' : '正式导入'],
['账单日期', $result['balance_date']],
['账户简称', $result['account_short']],
['有效笔数', $result['rows']],
['收入合计', number_format((float) $result['income'], 2)],
['支出合计', number_format((float) $result['expense'], 2)],
['替换原记录', $result['replaced']],
['每日流水行数', $result['recalculated']['flows'] ?? '-'],
]);
$this->info($result['dry_run'] ? '支付宝账单校验完成。' : '支付宝账单已接入财务台账动账明细。');
return self::SUCCESS;
}
}