Files
toolbox/app/Console/Commands/ErpRequestReportCommand.php
T
2026-08-12 18:00:09 +08:00

41 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
}
}
}