CaiWuXiTong/app/Console/Commands/ImportStoreReportData.php

45 lines
1.7 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Modules\EcommerceFinance\Services\StoreReportDataImporter;
use Throwable;
class ImportStoreReportData extends Command
{
protected $signature = 'store-report:import-data
{--bills= : 五个平台原始账单 XLSX 文件或目录}
{--lifecycles= : 店铺生命周期 XLSX 文件}
{--batch=500 : 单批写入共享业务镜像的行数}';
protected $description = '将平台原始账单和店铺生命周期原子导入团队共享业务镜像';
public function handle(StoreReportDataImporter $importer): int
{
$bills = trim((string) $this->option('bills'));
$lifecycles = trim((string) $this->option('lifecycles'));
if ($bills === '' && $lifecycles === '') {
$this->error('请至少指定 --bills 或 --lifecycles。');
return self::INVALID;
}
try {
if ($bills !== '') {
$result = $importer->importBills($bills, (int) $this->option('batch'));
$this->info('平台账单共享镜像导入完成:' . number_format($result['row_count']) . ' 行。');
}
if ($lifecycles !== '') {
$result = $importer->importLifecycles($lifecycles, (int) $this->option('batch'));
$this->info('店铺生命周期共享镜像导入完成:' . number_format($result['row_count']) . ' 行。');
}
} catch (Throwable $exception) {
report($exception);
$this->error('店铺维度报表数据导入失败,已保留上一版共享数据。');
return self::FAILURE;
}
return self::SUCCESS;
}
}