49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Modules\EcommerceFinance\Services\DingProcessDetailMirrorSynchronizer;
|
||
use Throwable;
|
||
|
||
class SyncDingProcessDetailMirror extends Command
|
||
{
|
||
protected $signature = 'business-mirror:sync-ding-process-details
|
||
{--full : 从配置起始日期完整重建明细和付款事实}
|
||
{--dry-run : 只读取上游并校验,不写入镜像}';
|
||
|
||
protected $description = '从钉钉结构化审批表单同步流程明细和付款事实';
|
||
|
||
public function handle(DingProcessDetailMirrorSynchronizer $synchronizer): int
|
||
{
|
||
try {
|
||
$result = $synchronizer->sync(
|
||
(bool) $this->option('full'),
|
||
(bool) $this->option('dry-run'),
|
||
);
|
||
} catch (Throwable $exception) {
|
||
$this->error('同步失败,已保留上一版共享数据:' . $exception->getMessage());
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
if ($result['status'] === 'requires_full_sync') {
|
||
$this->warn('流程明细尚未完成结构化全量同步,请使用 --full。');
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
|
||
$this->info(sprintf(
|
||
'%s:%d 个审批,%d 条明细,%d 笔付款;金额合计 %.2f,银行付款合计 %.2f。',
|
||
$result['status'] === 'validated' ? '校验通过' : '同步完成',
|
||
$result['workflows'],
|
||
$result['details'],
|
||
$result['payments'],
|
||
$result['amount_total'],
|
||
$result['bank_amount_total'],
|
||
));
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|