'decimal:2', 'withdraw' => 'decimal:2', 'balance' => 'decimal:2', 'is_manual' => 'boolean', ]; /** * 테넌트 관계 */ public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); } /** * 거래 고유 키 생성 (매칭용) * 숫자는 정수로 변환하여 형식 통일 */ public function getUniqueKeyAttribute(): string { return implode('|', [ $this->bank_account_num, $this->trans_dt, (int) $this->deposit, (int) $this->withdraw, (int) $this->balance, ]); } /** * 바로빌 로그 데이터로부터 고유 키 생성 (정적 메서드) */ public static function generateUniqueKey(array $log): string { // trans_dt 생성: transDate + transTime $transDt = ($log['transDate'] ?? '') . ($log['transTime'] ?? ''); return implode('|', [ $log['bankAccountNum'] ?? '', $transDt, $log['deposit'] ?? 0, $log['withdraw'] ?? 0, $log['balance'] ?? 0, ]); } /** * 테넌트별 거래 내역 조회 (기간별) */ public static function getByDateRange(int $tenantId, string $startDate, string $endDate, ?string $accountNum = null) { $query = self::where('tenant_id', $tenantId) ->whereBetween('trans_date', [$startDate, $endDate]) ->orderBy('trans_date', 'desc') ->orderBy('trans_time', 'desc'); if ($accountNum) { $query->where('bank_account_num', $accountNum); } return $query->get()->keyBy(fn($item) => $item->unique_key); } }