feat: enhance reconciliation job processing and reporting features
- Updated ReconcileItemIndexController to include admin user validation and improved transfer order handling. - Refactored ReconcileJobStoreController to ensure date range handling is more precise with start and end of day adjustments. - Enhanced various report controllers to include currency code in responses for better financial clarity. - Introduced new methods in AdminReconcileJobService for wallet transfer job creation and improved item scanning logic. - Added wallet lookup idempotent path configuration for integration services to enhance API interactions.
This commit is contained in:
@@ -28,15 +28,40 @@ final class WalletTransferReconcileDetector
|
||||
?Carbon $periodEnd = null,
|
||||
int $limit = 500,
|
||||
int $staleMinutes = 15,
|
||||
?int $playerId = null,
|
||||
bool $includeMainSiteCheck = true,
|
||||
): ?ReconcileJob {
|
||||
$periodEnd ??= now();
|
||||
$periodStart ??= $periodEnd->copy()->subDay();
|
||||
|
||||
[$items, $orders] = $this->scanItems($periodStart, $periodEnd, $limit, $staleMinutes, $playerId, $includeMainSiteCheck);
|
||||
|
||||
if ($items === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->persistJob($items, $periodStart, $periodEnd, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
* 0: list<array{side_a_ref: string, side_b_ref: ?string, difference_amount: int, status: string}>,
|
||||
* 1: \Illuminate\Support\Collection<int, TransferOrder>
|
||||
* }
|
||||
*/
|
||||
public function scanItems(
|
||||
Carbon $periodStart,
|
||||
Carbon $periodEnd,
|
||||
int $limit = 500,
|
||||
int $staleMinutes = 15,
|
||||
?int $playerId = null,
|
||||
bool $includeMainSiteCheck = true,
|
||||
): array {
|
||||
$limit = max(1, $limit);
|
||||
$staleMinutes = max(1, $staleMinutes);
|
||||
|
||||
$staleCutoff = $periodEnd->copy()->subMinutes($staleMinutes);
|
||||
|
||||
$orders = TransferOrder::query()
|
||||
$query = TransferOrder::query()
|
||||
->where(function ($q) use ($periodStart, $periodEnd, $staleCutoff): void {
|
||||
$q->whereBetween('created_at', [$periodStart, $periodEnd])
|
||||
->orWhere('status', 'pending_reconcile')
|
||||
@@ -46,11 +71,16 @@ final class WalletTransferReconcileDetector
|
||||
});
|
||||
})
|
||||
->orderBy('id')
|
||||
->limit($limit)
|
||||
->get();
|
||||
->limit($limit);
|
||||
|
||||
if ($playerId !== null) {
|
||||
$query->where('player_id', $playerId);
|
||||
}
|
||||
|
||||
$orders = $query->get();
|
||||
|
||||
if ($orders->isEmpty()) {
|
||||
return null;
|
||||
return [[], $orders];
|
||||
}
|
||||
|
||||
$txnsByTransferNo = WalletTxn::query()
|
||||
@@ -73,16 +103,28 @@ final class WalletTransferReconcileDetector
|
||||
}
|
||||
}
|
||||
|
||||
if ($items === []) {
|
||||
return null;
|
||||
if ($includeMainSiteCheck) {
|
||||
$items = app(WalletTransferMainSiteReconcileChecker::class)->appendIssues($items, $orders);
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($items, $periodStart, $periodEnd): ReconcileJob {
|
||||
return [$items, $orders];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array{side_a_ref: string, side_b_ref: ?string, difference_amount: int, status: string}> $items
|
||||
*/
|
||||
public function persistJob(
|
||||
array $items,
|
||||
Carbon $periodStart,
|
||||
Carbon $periodEnd,
|
||||
?int $adminUserId,
|
||||
): ReconcileJob {
|
||||
return DB::transaction(function () use ($items, $periodStart, $periodEnd, $adminUserId): ReconcileJob {
|
||||
$jobNo = 'REC'.now()->format('YmdHis').strtoupper(str_replace('-', '', Str::uuid()->toString()));
|
||||
|
||||
$job = ReconcileJob::query()->create([
|
||||
'job_no' => $jobNo,
|
||||
'admin_user_id' => null,
|
||||
'admin_user_id' => $adminUserId,
|
||||
'reconcile_type' => self::RECONCILE_TYPE,
|
||||
'status' => 'completed',
|
||||
'period_start' => $periodStart,
|
||||
|
||||
Reference in New Issue
Block a user