65 lines
2.3 KiB
PHP
65 lines
2.3 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 : 从配置起始日期完整重建明细和付款事实}
|
||
{--business-id= : 只同步指定审批编号,多个用逗号分隔(最多 50 个)}
|
||
{--dry-run : 只读取上游并校验,不写入镜像}';
|
||
|
||
protected $description = '从结构化审批镜像同步流程明细,并用钉钉官方接口补取缺失付款';
|
||
|
||
public function handle(DingProcessDetailMirrorSynchronizer $synchronizer): int
|
||
{
|
||
$businessIds = array_values(array_filter(array_map(
|
||
'trim',
|
||
explode(',', (string) $this->option('business-id')),
|
||
)));
|
||
|
||
try {
|
||
if ($businessIds !== []) {
|
||
if ((bool) $this->option('full')) {
|
||
throw new \InvalidArgumentException('--full 不能和 --business-id 同时使用。');
|
||
}
|
||
$result = $synchronizer->syncBusinessIds(
|
||
$businessIds,
|
||
(bool) $this->option('dry-run'),
|
||
);
|
||
} else {
|
||
$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;
|
||
}
|
||
}
|