@@ -112,11 +112,15 @@ public void refundBidBizz(User user, Long amount) {
112112
113113 // 경매/즉시구매 거래 완료시 판매자 정산
114114 public void settleDealToSeller (User seller , Long amount ) {
115- changeBizz (seller , amount , WalletTransactionType .DEAL_SETTLEMENT );
115+ changeBizz (seller , amount , WalletTransactionType .RECEIVE_SETTLEMENT );
116+ }
117+
118+ public void receiveDeposit (User user , Long amount ) {
119+ changeBizz (user , amount , WalletTransactionType .RECIEVE_DEPOSIT );
116120 }
117121
118122 // A유저 -> B유저 송금
119- public void transferBizz (User fromUser , User toUser , Long amount ) {
123+ public void transferBizz (User fromUser , User toUser , Long amount , WalletTransactionType sendType ) {
120124 if (fromUser == null || toUser == null ) {
121125 throw new BusinessException (ErrorCode .USER_NOT_FOUND );
122126 }
@@ -126,6 +130,12 @@ public void transferBizz(User fromUser, User toUser, Long amount) {
126130 throw new BusinessException (ErrorCode .INVALID_TRANSFER );
127131 }
128132
133+ WalletTransactionType receiveType = switch (sendType ) {
134+ case PAY_SETTLEMENT -> receiveType = WalletTransactionType .RECEIVE_SETTLEMENT ;
135+ case PAY_TO_USER -> receiveType = WalletTransactionType .RECEIVE_FROM_USER ;
136+ default -> throw new BusinessException (ErrorCode .INVALID_WALLET_TRANSACTION_TYPE );
137+ };
138+
129139 Long fromId = fromUser .getId ();
130140 Long toId = toUser .getId ();
131141
@@ -142,16 +152,16 @@ public void transferBizz(User fromUser, User toUser, Long amount) {
142152 // 지갑 히스토리 남기기
143153 Long fromBalanceBefore = r .fromBefore ();
144154 Long frombalanceAfter = r .fromAfter ();
145- walletHistoryService .recordWalletHistory (fromUser , amount , WalletTransactionType . PAY_TO_USER , fromBalanceBefore , frombalanceAfter );
155+ walletHistoryService .recordWalletHistory (fromUser , amount , sendType , fromBalanceBefore , frombalanceAfter );
146156 Long toBalanceBefore = r .toBefore ();
147157 Long tobalanceAfter = r .toAfter ();
148- walletHistoryService .recordWalletHistory (toUser , amount , WalletTransactionType . RECEIVE_FROM_USER , toBalanceBefore , tobalanceAfter );
158+ walletHistoryService .recordWalletHistory (toUser , amount , receiveType , toBalanceBefore , tobalanceAfter );
149159 return ;
150160 }
151161
152162 // 둘 다 DB => DB 처리
153163 if (!fromRedis && !toRedis ) {
154- transferDbFallback (fromUser , toUser , amount );
164+ transferDbFallback (fromUser , toUser , amount , sendType , receiveType );
155165 return ;
156166 }
157167
@@ -161,14 +171,14 @@ public void transferBizz(User fromUser, User toUser, Long amount) {
161171 walletRedisService .changeBizzIfPresent (fromId , amount , false , "TransferBizz_OUT" , null );
162172
163173 if (!out .hit ()) {
164- transferDbFallback (fromUser , toUser , amount );
174+ transferDbFallback (fromUser , toUser , amount , sendType , receiveType );
165175 return ;
166176 }
167177
168178 try {
169179 // 1) DB 입금 시도
170180 Wallet toWallet = findByUserIdWithLockOrThrow (toId );
171- updateBizzAndRecordHistory (toWallet , toUser , amount , WalletTransactionType . RECEIVE_FROM_USER );
181+ updateBizzAndRecordHistory (toWallet , toUser , amount , receiveType );
172182
173183 // 2) "DB입금 성공 이후에만" 롤백 훅 등록
174184 runAfterRollback (() -> {
@@ -192,7 +202,7 @@ public void transferBizz(User fromUser, User toUser, Long amount) {
192202 // 히스토리
193203 Long fromBalanceBefore = out .before ();
194204 Long fromBalanceAfter = out .after ();
195- walletHistoryService .recordWalletHistory (fromUser , amount , WalletTransactionType . PAY_TO_USER , fromBalanceBefore , fromBalanceAfter );
205+ walletHistoryService .recordWalletHistory (fromUser , amount , sendType , fromBalanceBefore , fromBalanceAfter );
196206
197207 return ;
198208 }
@@ -201,7 +211,7 @@ public void transferBizz(User fromUser, User toUser, Long amount) {
201211 if (!fromRedis && toRedis ) {
202212 // DB 차감
203213 Wallet fromWallet = findByUserIdWithLockOrThrow (fromId );
204- updateBizzAndRecordHistory (fromWallet , fromUser , amount , WalletTransactionType . PAY_TO_USER );
214+ updateBizzAndRecordHistory (fromWallet , fromUser , amount , sendType );
205215
206216 // to는 Redis가 진실이므로 Redis에 입금
207217 WalletRedisService .RedisBizzChangeResult in =
@@ -214,7 +224,7 @@ public void transferBizz(User fromUser, User toUser, Long amount) {
214224
215225 Long toBalanceBefore = in .before ();
216226 Long toBalanceAfter = in .after ();
217- walletHistoryService .recordWalletHistory (toUser , amount , WalletTransactionType . RECEIVE_FROM_USER , toBalanceBefore , toBalanceAfter );
227+ walletHistoryService .recordWalletHistory (toUser , amount , receiveType , toBalanceBefore , toBalanceAfter );
218228
219229 // 롤백되면 Redis 입금 되돌리기
220230 runAfterRollback (() -> {
@@ -269,7 +279,7 @@ public HistoriesPageResponseDto getHistories(Long userId, int page) {
269279
270280 /* ==================== 이 밑으로는 헬퍼 메서드 ==================== */
271281
272- private void transferDbFallback (User fromUser , User toUser , Long amount ) {
282+ private void transferDbFallback (User fromUser , User toUser , Long amount , WalletTransactionType sendType , WalletTransactionType receiveType ) {
273283 // ID 순서대로 락 획득하여 데드락 방지
274284 Long smallerId = Math .min (fromUser .getId (), toUser .getId ());
275285 Long largerId = Math .max (fromUser .getId (), toUser .getId ());
@@ -284,8 +294,8 @@ private void transferDbFallback(User fromUser, User toUser, Long amount) {
284294 ? firstWallet : secondWallet ;
285295
286296 // 송금 실행
287- updateBizzAndRecordHistory (fromWallet , fromUser , amount , WalletTransactionType . PAY_TO_USER );
288- updateBizzAndRecordHistory (toWallet , toUser , amount , WalletTransactionType . RECEIVE_FROM_USER );
297+ updateBizzAndRecordHistory (fromWallet , fromUser , amount , sendType );
298+ updateBizzAndRecordHistory (toWallet , toUser , amount , receiveType );
289299 }
290300
291301 /** 트랜잭션이 "롤백"으로 끝나면 실행할 보상 로직 */
0 commit comments