CaiWuXiTong/app/Console/Commands/SyncProductPriceMirror.php

54 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Modules\EcommerceFinance\Services\ProductPriceMirrorSynchronizer;
use Throwable;
class SyncProductPriceMirror extends Command
{
protected $signature = 'business-mirror:sync-product-prices
{--full : 执行或继续首次全量同步}
{--batch= : 每批最多读取行数}
{--max-batches= : 本轮最多批次数,0 表示直到完成}';
protected $description = '将经营分析副本库的商品价格数据同步到项目共享业务镜像库';
public function handle(ProductPriceMirrorSynchronizer $synchronizer): int
{
if (! (bool) config('upstream_mirrors.refresh_enabled', false) && ! $this->option('full')) {
return self::SUCCESS;
}
try {
$result = $synchronizer->sync(
(bool) $this->option('full'),
$this->option('batch') === null ? null : (int) $this->option('batch'),
$this->option('max-batches') === null ? null : (int) $this->option('max-batches'),
);
} catch (Throwable $exception) {
Log::error('商品价格共享镜像同步失败。', ['exception' => $exception::class]);
$this->error('商品价格共享镜像同步失败,已保留上一版共享数据。');
return self::FAILURE;
}
if ($result['status'] === 'requires_full_sync') {
$this->warn('商品价格共享镜像尚未执行首次全量同步。');
return self::SUCCESS;
}
$this->info(sprintf(
'商品价格镜像:%s,本轮 %d 批,累计处理 %d 行。',
$result['status'] === 'succeeded' ? '同步完成' : '同步进行中',
$result['batches'],
$result['rows'],
));
return self::SUCCESS;
}
}