Skip to content

Commit 0bf702f

Browse files
authored
주문 취소/교환/환불 엔티티 및 OrderStatus enum 구현 (#185)
1 parent 6bc9d15 commit 0bf702f

File tree

6 files changed

+279
-9
lines changed

6 files changed

+279
-9
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.back.domain.order.exchange.entity;
2+
3+
import com.back.domain.order.order.entity.Order;
4+
import com.back.domain.user.entity.User;
5+
import com.back.global.jpa.entity.BaseEntity;
6+
import jakarta.persistence.*;
7+
import lombok.AccessLevel;
8+
import lombok.Builder;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
12+
@Entity
13+
@Getter
14+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
15+
@Table(name = "exchanges")
16+
public class Exchange extends BaseEntity {
17+
18+
@ManyToOne(fetch = FetchType.LAZY)
19+
@JoinColumn(name = "order_id", nullable = false)
20+
private Order order;
21+
22+
@ManyToOne(fetch = FetchType.LAZY)
23+
@JoinColumn(name = "user_id", nullable = false)
24+
private User user;
25+
26+
@Enumerated(EnumType.STRING)
27+
@Column(nullable = false)
28+
private ExchangeStatus status;
29+
30+
@Column(nullable = false)
31+
private String reason;
32+
33+
@Column(columnDefinition = "TEXT")
34+
private String detailReason;
35+
36+
@Enumerated(EnumType.STRING)
37+
@Column(nullable = false)
38+
private ExchangeMethod exchangeMethod;
39+
40+
@Column(columnDefinition = "TEXT")
41+
private String attachmentFiles; // 파일명들을 쉼표로 구분하여 저장
42+
43+
// 교환 시 새 배송지 정보
44+
@Column(length = 500)
45+
private String newShippingAddress1;
46+
47+
@Column(length = 500)
48+
private String newShippingAddress2;
49+
50+
@Column(length = 10)
51+
private String newShippingZip;
52+
53+
@Column(length = 100)
54+
private String newRecipientName;
55+
56+
@Column(length = 20)
57+
private String newRecipientPhone;
58+
59+
@Builder
60+
public Exchange(Order order, User user, ExchangeStatus status, String reason,
61+
String detailReason, ExchangeMethod exchangeMethod, String attachmentFiles,
62+
String newShippingAddress1, String newShippingAddress2, String newShippingZip,
63+
String newRecipientName, String newRecipientPhone) {
64+
this.order = order;
65+
this.user = user;
66+
this.status = status;
67+
this.reason = reason;
68+
this.detailReason = detailReason;
69+
this.exchangeMethod = exchangeMethod;
70+
this.attachmentFiles = attachmentFiles;
71+
this.newShippingAddress1 = newShippingAddress1;
72+
this.newShippingAddress2 = newShippingAddress2;
73+
this.newShippingZip = newShippingZip;
74+
this.newRecipientName = newRecipientName;
75+
this.newRecipientPhone = newRecipientPhone;
76+
}
77+
78+
// 교환 승인
79+
public void approve() {
80+
this.status = ExchangeStatus.COMPLETED;
81+
}
82+
83+
// 교환 거부 (거부 시에도 COMPLETED로 처리)
84+
public void reject() {
85+
this.status = ExchangeStatus.COMPLETED;
86+
}
87+
88+
// 교환 상태 enum
89+
public enum ExchangeStatus {
90+
REQUESTED, // 교환 신청
91+
COMPLETED // 교환 완료
92+
}
93+
94+
// 교환 방법 enum
95+
public enum ExchangeMethod {
96+
PICKUP, // 수거 후 교환
97+
DIRECT // 직접 교환
98+
}
99+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.back.domain.order.exchange.entity;
2+
3+
import com.back.domain.order.orderItem.entity.OrderItem;
4+
import com.back.global.jpa.entity.BaseEntity;
5+
import jakarta.persistence.*;
6+
import lombok.AccessLevel;
7+
import lombok.Builder;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
11+
@Entity
12+
@Getter
13+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
14+
@Table(name = "exchange_items")
15+
public class ExchangeItem extends BaseEntity {
16+
17+
@ManyToOne(fetch = FetchType.LAZY)
18+
@JoinColumn(name = "exchange_id", nullable = false)
19+
private Exchange exchange;
20+
21+
@ManyToOne(fetch = FetchType.LAZY)
22+
@JoinColumn(name = "order_item_id", nullable = false)
23+
private OrderItem orderItem;
24+
25+
@Column(nullable = false)
26+
private Integer quantity;
27+
28+
@Builder
29+
public ExchangeItem(Exchange exchange, OrderItem orderItem, Integer quantity) {
30+
this.exchange = exchange;
31+
this.orderItem = orderItem;
32+
this.quantity = quantity;
33+
}
34+
}

src/main/java/com/back/domain/order/order/entity/Order.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void changeStatus(OrderStatus newStatus) {
7777
}
7878

7979
public void cancel() {
80-
this.status = OrderStatus.CANCELLED;
80+
this.status = OrderStatus.CANCELLATION_REQUESTED;
8181
}
8282

8383
public void validateOwnership(User user) {
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
package com.back.domain.order.order.entity;
22

33
public enum OrderStatus {
4-
PAYMENT_COMPLETED, // 결제완료
5-
PREPARING_SHIPMENT, // 배송준비중
6-
SHIPPING, // 배송중
7-
DELIVERED, // 배송완료
8-
CANCELLED, // 주문 취소
9-
REFUNDED, // 환불 완료
10-
REFUND_REQUESTED, // 환불 신청
11-
EXCHANGE_REQUESTED // 교환 신청
4+
PAYMENT_COMPLETED, // 결제완료 (발주 전)
5+
PREPARING_SHIPMENT, // 배송 준비중
6+
SHIPPING, // 배송중
7+
DELIVERED, // 배송완료
8+
9+
// 취소 관련
10+
CANCELLATION_REQUESTED, // 취소 신청
11+
CANCELLATION_COMPLETED, // 취소 완료
12+
13+
// 교환 관련
14+
EXCHANGE_REQUESTED, // 교환 신청
15+
EXCHANGE_COMPLETED, // 교환 완료
16+
17+
// 환불 관련
18+
REFUND_REQUESTED, // 환불 신청
19+
REFUND_COMPLETED // 환불 완료
1220
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.back.domain.order.refund.entity;
2+
3+
import com.back.domain.order.order.entity.Order;
4+
import com.back.domain.user.entity.User;
5+
import com.back.global.jpa.entity.BaseEntity;
6+
import jakarta.persistence.*;
7+
import lombok.AccessLevel;
8+
import lombok.Builder;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
12+
import java.math.BigDecimal;
13+
14+
@Entity
15+
@Getter
16+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
17+
@Table(name = "refunds")
18+
public class Refund extends BaseEntity {
19+
20+
@ManyToOne(fetch = FetchType.LAZY)
21+
@JoinColumn(name = "order_id", nullable = false)
22+
private Order order;
23+
24+
@ManyToOne(fetch = FetchType.LAZY)
25+
@JoinColumn(name = "user_id", nullable = false)
26+
private User user;
27+
28+
@Enumerated(EnumType.STRING)
29+
@Column(nullable = false)
30+
private RefundStatus status;
31+
32+
@Column(nullable = false)
33+
private String reason;
34+
35+
@Column(columnDefinition = "TEXT")
36+
private String detailReason;
37+
38+
@Column(precision = 12, scale = 2, nullable = false)
39+
private BigDecimal refundAmount;
40+
41+
@Enumerated(EnumType.STRING)
42+
@Column(nullable = false)
43+
private RefundMethod refundMethod;
44+
45+
@Column(columnDefinition = "TEXT")
46+
private String attachmentFiles; // 파일명들을 쉼표로 구분하여 저장
47+
48+
@Builder
49+
public Refund(Order order, User user, RefundStatus status, String reason,
50+
String detailReason, BigDecimal refundAmount, RefundMethod refundMethod,
51+
String attachmentFiles) {
52+
this.order = order;
53+
this.user = user;
54+
this.status = status;
55+
this.reason = reason;
56+
this.detailReason = detailReason;
57+
this.refundAmount = refundAmount;
58+
this.refundMethod = refundMethod;
59+
this.attachmentFiles = attachmentFiles;
60+
}
61+
62+
// 환불 승인
63+
public void approve() {
64+
this.status = RefundStatus.COMPLETED;
65+
}
66+
67+
// 환불 거부 (거부 시에도 COMPLETED로 처리)
68+
public void reject() {
69+
this.status = RefundStatus.COMPLETED;
70+
}
71+
72+
// 환불 상태 enum
73+
public enum RefundStatus {
74+
REQUESTED, // 환불 신청
75+
COMPLETED // 환불 완료
76+
}
77+
78+
// 환불 방법 enum
79+
public enum RefundMethod {
80+
ORIGINAL_PAYMENT, // 원 결제수단
81+
CASH, // 현금
82+
BANK_TRANSFER // 계좌이체
83+
}
84+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.back.domain.order.refund.entity;
2+
3+
import com.back.domain.order.orderItem.entity.OrderItem;
4+
import com.back.global.jpa.entity.BaseEntity;
5+
import jakarta.persistence.*;
6+
import lombok.AccessLevel;
7+
import lombok.Builder;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
11+
import java.math.BigDecimal;
12+
13+
@Entity
14+
@Getter
15+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
16+
@Table(name = "refund_items")
17+
public class RefundItem extends BaseEntity {
18+
19+
@ManyToOne(fetch = FetchType.LAZY)
20+
@JoinColumn(name = "refund_id", nullable = false)
21+
private Refund refund;
22+
23+
@ManyToOne(fetch = FetchType.LAZY)
24+
@JoinColumn(name = "order_item_id", nullable = false)
25+
private OrderItem orderItem;
26+
27+
@Column(nullable = false)
28+
private Integer quantity;
29+
30+
@Column(precision = 12, scale = 2, nullable = false)
31+
private BigDecimal refundPrice;
32+
33+
@Builder
34+
public RefundItem(Refund refund, OrderItem orderItem, Integer quantity, BigDecimal refundPrice) {
35+
this.refund = refund;
36+
this.orderItem = orderItem;
37+
this.quantity = quantity;
38+
this.refundPrice = refundPrice;
39+
}
40+
41+
// 환불 금액 계산
42+
public BigDecimal getTotalRefundAmount() {
43+
return this.refundPrice.multiply(BigDecimal.valueOf(this.quantity));
44+
}
45+
}

0 commit comments

Comments
 (0)