53 lines
2.1 KiB
PHP
53 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Modules\EcommerceFinance\Services\StoreReportMirrorSynchronizer;
|
|
use Throwable;
|
|
|
|
class SyncStoreReportMirror extends Command
|
|
{
|
|
protected $signature = 'business-mirror:sync-store-report
|
|
{--batch= : 每批最多读取账单行数}
|
|
{--max-batches= : 本轮最多处理账单批次数}
|
|
{--daily-batch= : 每批最多汇总原始账单行数}
|
|
{--daily-max-batches= : 本轮最多处理日汇总批次数}';
|
|
|
|
protected $description = '自动初始化并增量同步店铺维度报表共享镜像';
|
|
|
|
public function handle(StoreReportMirrorSynchronizer $synchronizer): int
|
|
{
|
|
if (! (bool) config('upstream_mirrors.refresh_enabled', false)
|
|
|| ! (bool) config('upstream_mirrors.store_report.enabled', true)) {
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
try {
|
|
$result = $synchronizer->sync(
|
|
$this->option('batch') === null ? null : (int) $this->option('batch'),
|
|
$this->option('max-batches') === null ? null : (int) $this->option('max-batches'),
|
|
$this->option('daily-batch') === null ? null : (int) $this->option('daily-batch'),
|
|
$this->option('daily-max-batches') === null ? null : (int) $this->option('daily-max-batches'),
|
|
);
|
|
} catch (Throwable $exception) {
|
|
Log::error('店铺维度报表共享镜像同步失败。', ['exception' => $exception::class]);
|
|
$this->error('店铺维度报表共享镜像同步失败,页面继续读取上一版数据。');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$this->info(sprintf(
|
|
'店铺报表镜像:生命周期 %s/%d 行,账单 %s/%d 行,日汇总 %s/%d 行。',
|
|
$result['lifecycles']['status'],
|
|
$result['lifecycles']['source_rows'],
|
|
$result['bills']['status'],
|
|
$result['bills']['source_rows'],
|
|
$result['daily']['status'],
|
|
$result['daily']['source_rows'],
|
|
));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|