CaiWuXiTong/app/Console/Commands/ImportDouyinOpeningBalances.php
qiuxiang f3ad2b7a40 feat: 增加抖音账户月度期初余额
以抖音6表2026-06-30期末余额为7月基准,后续月份按期初加收入减支出滚动;新增基准导入命令、快照表、页面统计卡和回归测试。
2026-11-06 16:25:01 +08:00

52 lines
1.6 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use InvalidArgumentException;
use Modules\EcommerceFinance\Services\DouyinOpeningBalanceImporter;
use RuntimeException;
use Throwable;
class ImportDouyinOpeningBalances extends Command
{
protected $signature = 'business-mirror:import-douyin-opening-balances
{path : 抖音月度余额表 XLSX/XLS/CSV}
{--period-end= : 期末余额截止日期,必须是月末 YYYY-MM-DD}';
protected $description = '导入抖音月度期末余额,作为后续月份期初余额的滚动基准';
public function handle(DouyinOpeningBalanceImporter $importer): int
{
$periodEnd = trim((string) $this->option('period-end'));
if ($periodEnd === '') {
$this->error('缺少 --period-end。');
return self::FAILURE;
}
try {
$result = $importer->import((string) $this->argument('path'), $periodEnd);
} catch (InvalidArgumentException|RuntimeException $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
} catch (Throwable $exception) {
report($exception);
$this->error('抖音期初余额导入失败,详细原因已记录到受保护日志。');
return self::FAILURE;
}
$this->table(['截止日期', '店铺数', '期末余额合计', '替换旧行数', '来源文件'], [[
$result['period_end'],
$result['total'],
$result['balance_total'],
$result['replaced'],
$result['source_filename'],
]]);
return self::SUCCESS;
}
}