yueyang cc204fbb97 feat(发票数据): 自动增量抓取并补入OA发票 (#1496)
自动识别 PDF、图片、XLS/XLSX、ZIP、RAR、7Z 发票附件,每 15 分钟补扫未处理、失败和部分识别流程。
2026-11-27 10:44:37 +08:00

48 lines
1.5 KiB
PHP

<?php
namespace Modules\EcommerceFinance\Console;
use Illuminate\Console\Command;
use Modules\EcommerceFinance\Services\DingInvoiceSyncService;
use Throwable;
class SyncDingInvoices extends Command
{
protected $signature = 'ding-invoices:sync
{--month= : 付款月份 YYYY-MM}
{--limit=20 : 本轮最多扫描的流程数}
{--force : 已扫描流程也重新抓取附件}
{--auto : 自动选择最近一个仍需抓取的月份}';
protected $description = '抓取钉钉 OA 审批附件并识别发票,写入发票数据镜像';
public function handle(DingInvoiceSyncService $service): int
{
try {
$month = (string) ($this->option('month') ?: '');
if ($month === '' && $this->option('auto')) {
$month = $service->latestPendingMonth() ?? '';
if ($month === '') {
$this->info('没有待抓取的发票月份。');
return self::SUCCESS;
}
}
$result = $service->syncMonth(
$month !== '' ? $month : now()->format('Y-m'),
(int) $this->option('limit'),
(bool) $this->option('force'),
);
} catch (Throwable $exception) {
report($exception);
$this->error($exception->getMessage());
return self::FAILURE;
}
$this->info(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
return self::SUCCESS;
}
}