52 lines
1.7 KiB
PHP
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;
|
|
}
|
|
}
|