Files
sam-api/app/Jobs/Barobill/SyncBarobillDataJob.php

86 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Jobs\Barobill;
use App\Models\Barobill\BarobillMember;
use App\Services\Barobill\BarobillBankSyncService;
use App\Services\Barobill\BarobillCardSyncService;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
/**
* 바로빌 데이터 자동 동기화 Job
*
* 스케줄러에서 매일 실행하여 활성 회원의 은행/카드 거래내역을 동기화한다.
*/
class SyncBarobillDataJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public int $timeout = 300;
public function __construct(
private string $syncType = 'all',
) {}
public function handle(
BarobillBankSyncService $bankSyncService,
BarobillCardSyncService $cardSyncService,
): void {
$members = BarobillMember::withoutGlobalScopes()
->where('status', 'active')
->where('server_mode', 'production')
->get();
if ($members->isEmpty()) {
Log::info('[SyncBarobill] 활성 회원 없음, 스킵');
return;
}
$yesterday = Carbon::yesterday()->format('Ymd');
$today = Carbon::today()->format('Ymd');
foreach ($members as $member) {
try {
if (in_array($this->syncType, ['all', 'bank'])) {
$result = $bankSyncService->syncIfNeeded(
$member->tenant_id,
$yesterday,
$today
);
Log::info('[SyncBarobill] 은행 동기화 완료', [
'tenant_id' => $member->tenant_id,
'result' => $result,
]);
}
if (in_array($this->syncType, ['all', 'card'])) {
$result = $cardSyncService->syncCardTransactions(
$member->tenant_id,
$yesterday,
$today
);
Log::info('[SyncBarobill] 카드 동기화 완료', [
'tenant_id' => $member->tenant_id,
'result' => $result,
]);
}
} catch (\Throwable $e) {
Log::error('[SyncBarobill] 동기화 실패', [
'tenant_id' => $member->tenant_id,
'sync_type' => $this->syncType,
'error' => $e->getMessage(),
]);
}
}
}
}