option('account')); $from = trim((string) $this->option('from')); $to = trim((string) $this->option('to')); if ($account === '' || $from === '' || $to === '') { $this->error('必须指定 --account、--from 和 --to。'); return self::FAILURE; } $openingOption = trim((string) $this->option('opening-balance')); $openingBalance = $openingOption === '' ? null : (float) $openingOption; $replaceSources = array_values(array_filter(array_map( 'trim', explode(',', (string) $this->option('replace-sources')), ))); try { $result = $importer->import( (string) $this->argument('path'), $account, $from, $to, $this->option('account-short') ?: null, $openingBalance, $replaceSources, (bool) $this->option('dry-run'), ); } catch (Throwable $exception) { $this->error('支付宝流水未导入,保留原有数据。' . $exception->getMessage()); return self::FAILURE; } $this->table(['项目', '值'], [ ['校验模式', $result['dry_run'] ? '仅校验' : '正式导入'], ['日期范围', $result['from'] . ' 至 ' . $result['to']], ['账户简称', $result['account_short']], ['期初余额', number_format((float) $result['opening_balance'], 2)], ['有效笔数', $result['rows']], ['收入合计', number_format((float) $result['income'], 2)], ['支出合计', number_format((float) $result['expense'], 2)], ['期末余额', number_format((float) $result['closing_balance'], 2)], ['替换原记录', $result['replaced']], ['每日流水行数', $result['recalculated']['flows'] ?? '-'], ]); $this->info($result['dry_run'] ? '支付宝流水校验完成。' : '支付宝流水已导入财务台账。'); return self::SUCCESS; } }