48 lines
1.5 KiB
PHP
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;
|
|
}
|
|
}
|