CaiWuXiTong/app/Console/Commands/SyncThirdPartyWarehouseStorage.php
limeng 179b2cdbcc 接入并校准三方仓进销存 (#176)
新增三方仓进销存共享镜像、按日查询汇总导出、每日零点增量同步和权威历史锚点校准。
2026-09-12 20:29:43 +08:00

64 lines
2.3 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\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;
}
}