CaiWuXiTong/app/Console/Commands/ImportXiaohongshuSettlementBills.php
qiuxiang 3cc4c6e629 feat: 新增小红书账户账单导入与查询 (#956)
新增小红书账户、聚水潭订单结算明细导入及页面查询
2026-11-06 15:45:19 +08:00

74 lines
2.8 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\XiaohongshuSettlementBillImporter;
use RuntimeException;
use Throwable;
class ImportXiaohongshuSettlementBills extends Command
{
protected $signature = 'xiaohongshu-bills:import
{path : 聚水潭导出的小红书订单结算明细 XLSX}
{--company-id=1 : 财务系统公司 ID}
{--from= : 账期开始日期,格式 YYYY-MM-DD}
{--to= : 账期结束日期,格式 YYYY-MM-DD}
{--expected-count= : 聚水潭权威笔数}
{--expected-income= : 聚水潭权威收入}
{--expected-expense= : 聚水潭权威支出}
{--batch=500 : 分批写入行数}';
protected $description = '导入并核验聚水潭小红书订单结算明细';
public function handle(XiaohongshuSettlementBillImporter $importer): int
{
foreach (['from', 'to', 'expected-count', 'expected-income', 'expected-expense'] as $option) {
if (trim((string) $this->option($option)) === '') {
$this->error("缺少 --{$option},导入必须提供账期和三项权威控制数。");
return self::FAILURE;
}
}
try {
$result = $importer->import(
(string) $this->argument('path'),
(int) $this->option('company-id'),
(string) $this->option('from'),
(string) $this->option('to'),
(int) $this->option('expected-count'),
(string) $this->option('expected-income'),
(string) $this->option('expected-expense'),
(int) $this->option('batch'),
);
} catch (RuntimeException $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
} catch (Throwable $exception) {
report($exception);
$this->error('小红书订单结算明细导入失败,详细原因已记录到受保护日志。');
return self::FAILURE;
}
$this->table(['状态', '账单行数', '店铺数', '账单项目数', '收入', '支出', '收支净额', '账期'], [[
$result['status'],
$result['row_count'],
$result['store_count'],
$result['bill_item_count'],
$result['income_total'],
$result['expense_total'],
$result['net_total'],
$result['period_start'] . ' 至 ' . $result['period_end'],
]]);
$this->line('交易类型:' . collect($result['transaction_type_counts'])
->map(fn (int $count, string $type): string => "{$type} {$count}")
->implode(';'));
$this->line('SHA-256: ' . $result['source_sha256']);
return self::SUCCESS;
}
}