41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Services\ErpRequestReportService;
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Log;
|
||
|
||
class ErpRequestReportCommand extends Command
|
||
{
|
||
protected $signature = 'erp-request-report:send
|
||
{--date= : 统计单日(Y-m-d;与 --from/--to 互斥,默认昨天)}
|
||
{--from= : 开始时间(Y-m-d 或 Y-m-d H:i:s,含)}
|
||
{--to= : 结束时间(Y-m-d 或 Y-m-d H:i:s;仅日期时含整天)}';
|
||
|
||
protected $description = '汇总指定时间段 ERP OpenAPI 请求并发送钉钉日报(默认昨天)';
|
||
|
||
public function handle(ErpRequestReportService $service): int
|
||
{
|
||
try {
|
||
$result = $service->sendReport(
|
||
$this->option('date'),
|
||
$this->option('from'),
|
||
$this->option('to')
|
||
);
|
||
|
||
Log::channel('erp-request-report')->info('ERP 请求日报已发送', $result);
|
||
$this->info("ERP 请求日报已发送:{$result['date']},{$result['company_count']} 家公司,{$result['request_count']} 次请求。");
|
||
|
||
return self::SUCCESS;
|
||
} catch (\Throwable $e) {
|
||
Log::channel('erp-request-report')->error('ERP 请求日报发送失败', [
|
||
'message' => $e->getMessage(),
|
||
]);
|
||
$this->error($e->getMessage());
|
||
|
||
return self::FAILURE;
|
||
}
|
||
}
|
||
}
|