CaiWuXiTong/app/Console/Commands/ImportPinduoduoPlatformBalances.php
qiuxiang 55f3e7d10f feat: 拼多多账户按平台余额滚动计算期初期末
以6月平台实际期末余额为基准,按财务系统每月收支滚动计算期初余额;期末余额=期初余额+收入合计-支出合计。
2026-11-06 11:37:23 +08:00

52 lines
1.7 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use InvalidArgumentException;
use Modules\EcommerceFinance\Services\PinduoduoPlatformBalanceImporter;
use RuntimeException;
use Throwable;
class ImportPinduoduoPlatformBalances extends Command
{
protected $signature = 'business-mirror:import-pdd-platform-balances
{path : 拼多多平台实际期末余额 XLSX/XLS/CSV}
{--period-end= : 余额截止日期,必须是月末 YYYY-MM-DD}';
protected $description = '导入拼多多平台实际期末余额,作为后续月份期初余额的滚动基准';
public function handle(PinduoduoPlatformBalanceImporter $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;
}
}