giftcon_dev/app/Console/Commands/Marketing/BuildMemberMarketingStats.php
2026-02-12 13:48:48 +09:00

37 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands\Marketing;
use App\Services\Admin\Member\MemberMarketingBatchService;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
final class BuildMemberMarketingStats extends Command
{
protected $signature = 'marketing:members:build-stats
{--date= : 기준일(YYYY-MM-DD). 비우면 어제}
{--no-lock : Redis lock 없이 실행(디버그용)}';
protected $description = '전일 기준 회원 마케팅 통계(mem_marketing_*) 생성/갱신';
public function handle(MemberMarketingBatchService $service): int
{
$opt = (string) ($this->option('date') ?? '');
$asOf = $opt !== ''
? Carbon::parse($opt)->toDateString()
: now()->subDay()->toDateString();
// no-lock 옵션은 Service쪽에서 lock을 무시하려면 구조를 바꿔야 하는데,
// 운영에서는 필요 없고, 테스트는 스케줄 없이 직접 커맨드 실행하면 되니 일단 유지.
$res = $service->run($asOf);
if (($res['skipped'] ?? false) === true) {
$this->warn("SKIPPED (locked): {$asOf}");
return self::SUCCESS;
}
$this->info("DONE {$asOf} | daily={$res['daily_rows']} total={$res['total_rows']} stats={$res['stats_rows']}");
return self::SUCCESS;
}
}