40 lines
1.8 KiB
PHP
40 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Support\CourierOnboardingDingTalk;
|
|
use Illuminate\Console\Command;
|
|
|
|
class StartCourierOnboardingDingTalk extends Command
|
|
{
|
|
protected $signature = 'courier-onboarding:dingtalk {id : 入驻申请ID} {--company= : 所属公司ID} {--retry : 仅重试明确失败的请求} {--instance= : 核查并关联已有审批,不发起新单}';
|
|
|
|
protected $description = '处理指定入驻申请的钉钉审批;超时或中断请求禁止盲目重发';
|
|
|
|
public function handle(CourierOnboardingDingTalk $service): int
|
|
{
|
|
if (! ctype_digit((string) $this->argument('id')) || ! ctype_digit((string) $this->option('company'))
|
|
|| (int) $this->argument('id') < 1 || (int) $this->option('company') < 1) {
|
|
$this->error('请指定有效的入驻申请ID及 --company 公司ID。');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
if ($this->option('instance')) {
|
|
$service->reconcile((int) $this->option('company'), (int) $this->argument('id'), (string) $this->option('instance'));
|
|
$this->info('已核对并关联现有审批,没有创建新审批。');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$status = $service->start((int) $this->option('company'), (int) $this->argument('id'), (bool) $this->option('retry'));
|
|
$this->line(match ($status) {
|
|
'started' => '已发起钉钉审批。',
|
|
'disabled' => '入驻钉钉自动发起未启用。',
|
|
'skipped' => '未重复发起;已有审批、已有尝试或当前状态不允许,请查看入驻处理记录。',
|
|
default => '未确认发起成功,请查看入驻处理记录;结果待核查时请勿重发。',
|
|
});
|
|
|
|
return $status === 'started' || $status === 'skipped' ? self::SUCCESS : self::FAILURE;
|
|
}
|
|
}
|