52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Modules\EcommerceFinance\Services\DingInvoiceRefreshQueue;
|
|
use Modules\EcommerceFinance\Services\DingInvoiceSyncService;
|
|
use Throwable;
|
|
|
|
class ProcessDingInvoiceRefreshRequests extends Command
|
|
{
|
|
protected $signature = 'ding-invoices:process-refresh-requests
|
|
{--limit=50 : 单轮最多扫描的流程数}';
|
|
|
|
protected $description = '处理发票数据页面提交的附件抓取请求';
|
|
|
|
public function handle(
|
|
DingInvoiceRefreshQueue $queue,
|
|
DingInvoiceSyncService $sync,
|
|
): int {
|
|
$queue->cleanup();
|
|
$request = $queue->claimNext();
|
|
if ($request === null) {
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
try {
|
|
$result = $sync->syncMonth(
|
|
(string) ($request['month'] ?? ''),
|
|
(int) $this->option('limit'),
|
|
(bool) ($request['force'] ?? false),
|
|
);
|
|
if ((int) ($result['remaining_flows'] ?? 0) > 0) {
|
|
$queue->defer((string) $request['token'], $result, false);
|
|
$this->info('本批发票抓取完成,剩余流程等待下一批处理。');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
$queue->complete((string) $request['token'], $result);
|
|
$this->info(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
|
|
return self::SUCCESS;
|
|
} catch (Throwable $exception) {
|
|
report($exception);
|
|
$queue->fail((string) $request['token'], $exception->getMessage());
|
|
$this->error($exception->getMessage());
|
|
|
|
return self::FAILURE;
|
|
}
|
|
}
|
|
}
|