64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Log;
|
||
use Modules\EcommerceFinance\Services\ThirdPartyWarehouseStorageSynchronizer;
|
||
use Throwable;
|
||
|
||
class SyncThirdPartyWarehouseStorage extends Command
|
||
{
|
||
protected $signature = 'business-mirror:sync-third-party-warehouse-storage
|
||
{--full : 启动或继续聚水潭全仓流水与库存的全量校准}
|
||
{--max-batches= : 本轮最多批次数,0 表示直到完成}';
|
||
|
||
protected $description = '同步聚水潭全部仓库按商品进销存数据到共享业务镜像';
|
||
|
||
public function handle(ThirdPartyWarehouseStorageSynchronizer $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('max-batches') === null ? null : (int) $this->option('max-batches'),
|
||
);
|
||
} catch (Throwable $exception) {
|
||
Log::error('聚水潭进销存数据共享镜像同步失败。', [
|
||
'dataset' => ThirdPartyWarehouseStorageSynchronizer::DATASET_KEY,
|
||
'exception' => $exception::class,
|
||
]);
|
||
$this->error('聚水潭进销存数据同步失败,页面继续读取上一版完整数据。');
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
if ($result['status'] === 'requires_full_sync') {
|
||
$this->warn('聚水潭进销存数据尚未完成首次全量同步,请显式使用 --full。');
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
|
||
if ($result['status'] === 'already_running') {
|
||
$this->line('聚水潭进销存数据已有同步任务运行,本次不重复启动。');
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
|
||
$this->info(sprintf(
|
||
'聚水潭进销存数据%s:%s,本轮 %d 批;流水 %d 条、明细 %d 条、库存 %d 条。',
|
||
$result['mode'] === 'full' ? '全量校准' : '增量同步',
|
||
$result['status'] === 'succeeded' ? '完成' : '进行中',
|
||
$result['batches'],
|
||
$result['headers'],
|
||
$result['items'],
|
||
$result['inventory'],
|
||
));
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|