From f919ab7e2c450c1323d239e01e7304a969b4d387 Mon Sep 17 00:00:00 2001 From: SeoJin Kim Date: Mon, 13 Dec 2021 23:18:20 +0900 Subject: [PATCH] =?UTF-8?q?[Spring][=EC=87=BC=ED=95=91=EB=AA=B0=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8][42]=20=EC=A3=BC=EB=AC=B8?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=20-=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://kimvampa.tistory.com/278 --- .../com/vam/controller/OrderController.java | 12 ++ .../src/main/java/com/vam/model/OrderDTO.java | 190 ++++++++++++++++++ .../main/java/com/vam/model/OrderItemDTO.java | 134 ++++++++++++ VamPa/src/main/webapp/WEB-INF/views/order.jsp | 63 +++++- .../com/vam/controller/OrderController.java | 14 +- .../src/main/java/com/vam/model/OrderDTO.java | 189 +++++++++++++++++ .../main/java/com/vam/model/OrderItemDTO.java | 132 ++++++++++++ .../src/main/webapp/WEB-INF/views/order.jsp | 63 +++++- 8 files changed, 794 insertions(+), 3 deletions(-) create mode 100644 VamPa/src/main/java/com/vam/model/OrderDTO.java create mode 100644 VamPa/src/main/java/com/vam/model/OrderItemDTO.java create mode 100644 VamPa_MySQL/src/main/java/com/vam/model/OrderDTO.java create mode 100644 VamPa_MySQL/src/main/java/com/vam/model/OrderItemDTO.java diff --git a/VamPa/src/main/java/com/vam/controller/OrderController.java b/VamPa/src/main/java/com/vam/controller/OrderController.java index f105235..e93a3f1 100644 --- a/VamPa/src/main/java/com/vam/controller/OrderController.java +++ b/VamPa/src/main/java/com/vam/controller/OrderController.java @@ -1,11 +1,15 @@ package com.vam.controller; +import javax.servlet.http.HttpServletRequest; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import com.vam.model.OrderDTO; import com.vam.model.OrderPageDTO; import com.vam.service.MemberService; import com.vam.service.OrderService; @@ -29,4 +33,12 @@ public class OrderController { return "/order"; } + @PostMapping("/order") + public String orderPagePost(OrderDTO od, HttpServletRequest request) { + + System.out.println(od); + + return "redirect:/main"; + } + } diff --git a/VamPa/src/main/java/com/vam/model/OrderDTO.java b/VamPa/src/main/java/com/vam/model/OrderDTO.java new file mode 100644 index 0000000..93dd6a0 --- /dev/null +++ b/VamPa/src/main/java/com/vam/model/OrderDTO.java @@ -0,0 +1,190 @@ +package com.vam.model; + +import java.util.Date; +import java.util.List; + +public class OrderDTO { + + /* 주문 번호 */ + private String orderId; + + /* 배송 받는이 */ + private String addressee; + + /* 주문 회원 아이디 */ + private String memberId; + + /* 우편번호 */ + private String memberAddr1; + + /* 회원 주소 */ + private String memberAddr2; + + /* 회원 상세주소 */ + private String memberAddr3; + + /* 주문 상태 */ + private String orderState; + + /* 주문 상품 */ + private List orders; + + /* 배송비 */ + private int deliveryCost; + + /* 사용 포인트 */ + private int usePoint; + + /* 주문 날짜 */ + private Date orderDate; + + /* DB테이블 존재 하지 않는 데이터 */ + + /* 판매가(모든 상품 비용) */ + private int orderSalePrice; + + /* 적립 포인트 */ + private int orderSavePoint; + + /* 최종 판매 비용 */ + private int orderFinalSalePrice; + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public String getAddressee() { + return addressee; + } + + public void setAddressee(String addressee) { + this.addressee = addressee; + } + + public String getMemberId() { + return memberId; + } + + public void setMemberId(String memberId) { + this.memberId = memberId; + } + + public String getMemberAddr1() { + return memberAddr1; + } + + public void setMemberAddr1(String memberAddr1) { + this.memberAddr1 = memberAddr1; + } + + public String getMemberAddr2() { + return memberAddr2; + } + + public void setMemberAddr2(String memberAddr2) { + this.memberAddr2 = memberAddr2; + } + + public String getMemberAddr3() { + return memberAddr3; + } + + public void setMemberAddr3(String memberAddr3) { + this.memberAddr3 = memberAddr3; + } + + public String getOrderState() { + return orderState; + } + + public void setOrderState(String orderState) { + this.orderState = orderState; + } + + public List getOrders() { + return orders; + } + + public void setOrders(List orders) { + this.orders = orders; + } + + public int getDeliveryCost() { + return deliveryCost; + } + + public void setDeliveryCost(int deliveryCost) { + this.deliveryCost = deliveryCost; + } + + public int getUsePoint() { + return usePoint; + } + + public void setUsePoint(int usePoint) { + this.usePoint = usePoint; + } + + public Date getOrderDate() { + return orderDate; + } + + public void setOrderDate(Date orderDate) { + this.orderDate = orderDate; + } + + public int getOrderSalePrice() { + return orderSalePrice; + } + + public void setOrderSalePrice(int orderSalePrice) { + this.orderSalePrice = orderSalePrice; + } + + public int getOrderSavePoint() { + return orderSavePoint; + } + + public void setOrderSavePoint(int orderSavePoint) { + this.orderSavePoint = orderSavePoint; + } + + public int getOrderFinalSalePrice() { + return orderFinalSalePrice; + } + + public void setOrderFinalSalePrice(int orderFinalSalePrice) { + this.orderFinalSalePrice = orderFinalSalePrice; + } + + @Override + public String toString() { + return "OrderDTO [orderId=" + orderId + ", addressee=" + addressee + ", memberId=" + memberId + ", memberAddr1=" + + memberAddr1 + ", memberAddr2=" + memberAddr2 + ", memberAddr3=" + memberAddr3 + ", orderState=" + + orderState + ", orders=" + orders + ", deliveryCost=" + deliveryCost + ", usePoint=" + usePoint + + ", orderDate=" + orderDate + ", orderSalePrice=" + orderSalePrice + ", orderSavePoint=" + + orderSavePoint + ", orderFinalSalePrice=" + orderFinalSalePrice + "]"; + } + + public void getOrderPriceInfo() { + /* 상품 비용 & 적립포인트 */ + for(OrderItemDTO order : orders) { + orderSalePrice += order.getTotalPrice(); + orderSavePoint += order.getTotalSavePoint(); + } + /* 배송비용 */ + if(orderSalePrice >= 30000) { + deliveryCost = 0; + } else { + deliveryCost = 3000; + } + /* 최종 비용(상품 비용 + 배송비 - 사용 포인트) */ + orderFinalSalePrice = orderSalePrice + deliveryCost - usePoint; + } + + +} diff --git a/VamPa/src/main/java/com/vam/model/OrderItemDTO.java b/VamPa/src/main/java/com/vam/model/OrderItemDTO.java new file mode 100644 index 0000000..f1765c5 --- /dev/null +++ b/VamPa/src/main/java/com/vam/model/OrderItemDTO.java @@ -0,0 +1,134 @@ +package com.vam.model; + +public class OrderItemDTO { + + /* 주문 번호 */ + private String orderId; + + /* 상품 번호 */ + private int bookId; + + /* 주문 수량 */ + private int bookCount; + + /* vam_orderItem 기본키 */ + private int orderItemId; + + /* 상품 한 개 가격 */ + private int bookPrice; + + /* 상품 할인 율 */ + private double bookDiscount; + + /* 상품 한개 구매 시 획득 포인트 */ + private int savePoint; + + /* DB테이블 존재 하지 않는 데이터 */ + + /* 할인 적용된 가격 */ + private int salePrice; + + /* 총 가격(할인 적용된 가격 * 주문 수량) */ + private int totalPrice; + + /* 총 획득 포인트(상품 한개 구매 시 획득 포인트 * 수량) */ + private int totalSavePoint; + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public int getBookId() { + return bookId; + } + + public void setBookId(int bookId) { + this.bookId = bookId; + } + + public int getBookCount() { + return bookCount; + } + + public void setBookCount(int bookCount) { + this.bookCount = bookCount; + } + + public int getOrderItemId() { + return orderItemId; + } + + public void setOrderItemId(int orderItemId) { + this.orderItemId = orderItemId; + } + + public int getBookPrice() { + return bookPrice; + } + + public void setBookPrice(int bookPrice) { + this.bookPrice = bookPrice; + } + + public double getBookDiscount() { + return bookDiscount; + } + + public void setBookDiscount(double bookDiscount) { + this.bookDiscount = bookDiscount; + } + + public int getSavePoint() { + return savePoint; + } + + public void setSavePoint(int savePoint) { + this.savePoint = savePoint; + } + + public int getSalePrice() { + return salePrice; + } + + public void setSalePrice(int salePrice) { + this.salePrice = salePrice; + } + + public int getTotalPrice() { + return totalPrice; + } + + public void setTotalPrice(int totalPrice) { + this.totalPrice = totalPrice; + } + + public int getTotalSavePoint() { + return totalSavePoint; + } + + public void setTotalSavePoint(int totalSavePoint) { + this.totalSavePoint = totalSavePoint; + } + + @Override + public String toString() { + return "OrderItemDTO [orderId=" + orderId + ", bookId=" + bookId + ", bookCount=" + bookCount + ", orderItemId=" + + orderItemId + ", bookPrice=" + bookPrice + ", bookDiscount=" + bookDiscount + ", savePoint=" + + savePoint + ", salePrice=" + salePrice + ", totalPrice=" + totalPrice + ", totalSavePoint=" + + totalSavePoint + "]"; + } + + public void initSaleTotal() { + this.salePrice = (int) (this.bookPrice * (1-this.bookDiscount)); + this.totalPrice = this.salePrice*this.bookCount; + this.savePoint = (int)(Math.floor(this.salePrice*0.05)); + this.totalSavePoint =this.savePoint * this.bookCount; + } + + + +} diff --git a/VamPa/src/main/webapp/WEB-INF/views/order.jsp b/VamPa/src/main/webapp/WEB-INF/views/order.jsp index 8ecb7c6..3af6bbc 100644 --- a/VamPa/src/main/webapp/WEB-INF/views/order.jsp +++ b/VamPa/src/main/webapp/WEB-INF/views/order.jsp @@ -128,7 +128,12 @@ 주소 - ${memberInfo.memberAddr1} ${memberInfo.memberAddr2}
${memberInfo.memberAddr3} + ${memberInfo.memberAddr1} ${memberInfo.memberAddr2}
${memberInfo.memberAddr3} + + + + + @@ -275,6 +280,20 @@ + + +
+ + + + + + + + + + +
@@ -362,6 +381,14 @@ function showAdress(className){ $(".address_btn").css('backgroundColor', '#555'); /* 지정 색상 변경 */ $(".address_btn_"+className).css('backgroundColor', '#3c3838'); + /* selectAddress T/F */ + /* 모든 selectAddress F만들기 */ + $(".addressInfo_input_div").each(function(i, obj){ + $(obj).find(".selectAddress").val("F"); + }); + /* 선택한 selectAdress T만들기 */ + $(".addressInfo_input_div_" + className).find(".selectAddress").val("T"); + } /* 다음 주소 연동 */ @@ -530,6 +557,40 @@ function setTotalInfo(){ } +/* 주문 요청 */ +$(".order_btn").on("click", function(){ + + /* 주소 정보 & 받는이*/ + $(".addressInfo_input_div").each(function(i, obj){ + if($(obj).find(".selectAddress").val() === 'T'){ + $("input[name='addressee']").val($(obj).find(".addressee_input").val()); + $("input[name='memberAddr1']").val($(obj).find(".address1_input").val()); + $("input[name='memberAddr2']").val($(obj).find(".address2_input").val()); + $("input[name='memberAddr3']").val($(obj).find(".address3_input").val()); + } + }); + + /* 사용 포인트 */ + $("input[name='usePoint']").val($(".order_point_input").val()); + + /* 상품정보 */ + let form_contents = ''; + $(".goods_table_price_td").each(function(index, element){ + let bookId = $(element).find(".individual_bookId_input").val(); + let bookCount = $(element).find(".individual_bookCount_input").val(); + let bookId_input = ""; + form_contents += bookId_input; + let bookCount_input = ""; + form_contents += bookCount_input; + }); + $(".order_form").append(form_contents); + + /* 서버 전송 */ + $(".order_form").submit(); + +}); + + diff --git a/VamPa_MySQL/src/main/java/com/vam/controller/OrderController.java b/VamPa_MySQL/src/main/java/com/vam/controller/OrderController.java index 4f3dc34..f75929a 100644 --- a/VamPa_MySQL/src/main/java/com/vam/controller/OrderController.java +++ b/VamPa_MySQL/src/main/java/com/vam/controller/OrderController.java @@ -1,11 +1,15 @@ package com.vam.controller; +import javax.servlet.http.HttpServletRequest; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import com.vam.model.OrderDTO; import com.vam.model.OrderPageDTO; import com.vam.service.MemberService; import com.vam.service.OrderService; @@ -27,6 +31,14 @@ public class OrderController { return "/order"; - } + } + + @PostMapping("/order") + public String orderPagePost(OrderDTO od, HttpServletRequest request) { + + System.out.println(od); + + return "redirect:/main"; + } } diff --git a/VamPa_MySQL/src/main/java/com/vam/model/OrderDTO.java b/VamPa_MySQL/src/main/java/com/vam/model/OrderDTO.java new file mode 100644 index 0000000..53b3646 --- /dev/null +++ b/VamPa_MySQL/src/main/java/com/vam/model/OrderDTO.java @@ -0,0 +1,189 @@ +package com.vam.model; + +import java.util.Date; +import java.util.List; + +public class OrderDTO { + + /* 주문 번호 */ + private String orderId; + + /* 배송 받는이 */ + private String addressee; + + /* 주문 회원 아이디 */ + private String memberId; + + /* 우편번호 */ + private String memberAddr1; + + /* 회원 주소 */ + private String memberAddr2; + + /* 회원 상세주소 */ + private String memberAddr3; + + /* 주문 상태 */ + private String orderState; + + /* 주문 상품 */ + private List orders; + + /* 배송비 */ + private int deliveryCost; + + /* 사용 포인트 */ + private int usePoint; + + /* 주문 날짜 */ + private Date orderDate; + + /* DB테이블 존재 하지 않는 데이터 */ + + /* 판매가(모든 상품 비용) */ + private int orderSalePrice; + + /* 적립 포인트 */ + private int orderSavePoint; + + /* 최종 판매 비용 */ + private int orderFinalSalePrice; + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public String getAddressee() { + return addressee; + } + + public void setAddressee(String addressee) { + this.addressee = addressee; + } + + public String getMemberId() { + return memberId; + } + + public void setMemberId(String memberId) { + this.memberId = memberId; + } + + public String getMemberAddr1() { + return memberAddr1; + } + + public void setMemberAddr1(String memberAddr1) { + this.memberAddr1 = memberAddr1; + } + + public String getMemberAddr2() { + return memberAddr2; + } + + public void setMemberAddr2(String memberAddr2) { + this.memberAddr2 = memberAddr2; + } + + public String getMemberAddr3() { + return memberAddr3; + } + + public void setMemberAddr3(String memberAddr3) { + this.memberAddr3 = memberAddr3; + } + + public String getOrderState() { + return orderState; + } + + public void setOrderState(String orderState) { + this.orderState = orderState; + } + + public List getOrders() { + return orders; + } + + public void setOrders(List orders) { + this.orders = orders; + } + + public int getDeliveryCost() { + return deliveryCost; + } + + public void setDeliveryCost(int deliveryCost) { + this.deliveryCost = deliveryCost; + } + + public int getUsePoint() { + return usePoint; + } + + public void setUsePoint(int usePoint) { + this.usePoint = usePoint; + } + + public Date getOrderDate() { + return orderDate; + } + + public void setOrderDate(Date orderDate) { + this.orderDate = orderDate; + } + + public int getOrderSalePrice() { + return orderSalePrice; + } + + public void setOrderSalePrice(int orderSalePrice) { + this.orderSalePrice = orderSalePrice; + } + + public int getOrderSavePoint() { + return orderSavePoint; + } + + public void setOrderSavePoint(int orderSavePoint) { + this.orderSavePoint = orderSavePoint; + } + + public int getOrderFinalSalePrice() { + return orderFinalSalePrice; + } + + public void setOrderFinalSalePrice(int orderFinalSalePrice) { + this.orderFinalSalePrice = orderFinalSalePrice; + } + + @Override + public String toString() { + return "OrderDTO [orderId=" + orderId + ", addressee=" + addressee + ", memberId=" + memberId + ", memberAddr1=" + + memberAddr1 + ", memberAddr2=" + memberAddr2 + ", memberAddr3=" + memberAddr3 + ", orderState=" + + orderState + ", orders=" + orders + ", deliveryCost=" + deliveryCost + ", usePoint=" + usePoint + + ", orderDate=" + orderDate + ", orderSalePrice=" + orderSalePrice + ", orderSavePoint=" + + orderSavePoint + ", orderFinalSalePrice=" + orderFinalSalePrice + "]"; + } + + public void getOrderPriceInfo() { + /* 상품 비용 & 적립포인트 */ + for(OrderItemDTO order : orders) { + orderSalePrice += order.getTotalPrice(); + orderSavePoint += order.getTotalSavePoint(); + } + /* 배송비용 */ + if(orderSalePrice >= 30000) { + deliveryCost = 0; + } else { + deliveryCost = 3000; + } + /* 최종 비용(상품 비용 + 배송비 - 사용 포인트) */ + orderFinalSalePrice = orderSalePrice + deliveryCost - usePoint; + } + +} diff --git a/VamPa_MySQL/src/main/java/com/vam/model/OrderItemDTO.java b/VamPa_MySQL/src/main/java/com/vam/model/OrderItemDTO.java new file mode 100644 index 0000000..fb43769 --- /dev/null +++ b/VamPa_MySQL/src/main/java/com/vam/model/OrderItemDTO.java @@ -0,0 +1,132 @@ +package com.vam.model; + +public class OrderItemDTO { + + /* 주문 번호 */ + private String orderId; + + /* 상품 번호 */ + private int bookId; + + /* 주문 수량 */ + private int bookCount; + + /* vam_orderItem 기본키 */ + private int orderItemId; + + /* 상품 한 개 가격 */ + private int bookPrice; + + /* 상품 할인 율 */ + private double bookDiscount; + + /* 상품 한개 구매 시 획득 포인트 */ + private int savePoint; + + /* DB테이블 존재 하지 않는 데이터 */ + + /* 할인 적용된 가격 */ + private int salePrice; + + /* 총 가격(할인 적용된 가격 * 주문 수량) */ + private int totalPrice; + + /* 총 획득 포인트(상품 한개 구매 시 획득 포인트 * 수량) */ + private int totalSavePoint; + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public int getBookId() { + return bookId; + } + + public void setBookId(int bookId) { + this.bookId = bookId; + } + + public int getBookCount() { + return bookCount; + } + + public void setBookCount(int bookCount) { + this.bookCount = bookCount; + } + + public int getOrderItemId() { + return orderItemId; + } + + public void setOrderItemId(int orderItemId) { + this.orderItemId = orderItemId; + } + + public int getBookPrice() { + return bookPrice; + } + + public void setBookPrice(int bookPrice) { + this.bookPrice = bookPrice; + } + + public double getBookDiscount() { + return bookDiscount; + } + + public void setBookDiscount(double bookDiscount) { + this.bookDiscount = bookDiscount; + } + + public int getSavePoint() { + return savePoint; + } + + public void setSavePoint(int savePoint) { + this.savePoint = savePoint; + } + + public int getSalePrice() { + return salePrice; + } + + public void setSalePrice(int salePrice) { + this.salePrice = salePrice; + } + + public int getTotalPrice() { + return totalPrice; + } + + public void setTotalPrice(int totalPrice) { + this.totalPrice = totalPrice; + } + + public int getTotalSavePoint() { + return totalSavePoint; + } + + public void setTotalSavePoint(int totalSavePoint) { + this.totalSavePoint = totalSavePoint; + } + + @Override + public String toString() { + return "OrderItemDTO [orderId=" + orderId + ", bookId=" + bookId + ", bookCount=" + bookCount + ", orderItemId=" + + orderItemId + ", bookPrice=" + bookPrice + ", bookDiscount=" + bookDiscount + ", savePoint=" + + savePoint + ", salePrice=" + salePrice + ", totalPrice=" + totalPrice + ", totalSavePoint=" + + totalSavePoint + "]"; + } + + public void initSaleTotal() { + this.salePrice = (int) (this.bookPrice * (1-this.bookDiscount)); + this.totalPrice = this.salePrice*this.bookCount; + this.savePoint = (int)(Math.floor(this.salePrice*0.05)); + this.totalSavePoint =this.savePoint * this.bookCount; + } + +} diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/order.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/order.jsp index 8ecb7c6..3af6bbc 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/views/order.jsp +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/order.jsp @@ -128,7 +128,12 @@ 주소 - ${memberInfo.memberAddr1} ${memberInfo.memberAddr2}
${memberInfo.memberAddr3} + ${memberInfo.memberAddr1} ${memberInfo.memberAddr2}
${memberInfo.memberAddr3} + + + + + @@ -275,6 +280,20 @@ + + +
+ + + + + + + + + + +
@@ -362,6 +381,14 @@ function showAdress(className){ $(".address_btn").css('backgroundColor', '#555'); /* 지정 색상 변경 */ $(".address_btn_"+className).css('backgroundColor', '#3c3838'); + /* selectAddress T/F */ + /* 모든 selectAddress F만들기 */ + $(".addressInfo_input_div").each(function(i, obj){ + $(obj).find(".selectAddress").val("F"); + }); + /* 선택한 selectAdress T만들기 */ + $(".addressInfo_input_div_" + className).find(".selectAddress").val("T"); + } /* 다음 주소 연동 */ @@ -530,6 +557,40 @@ function setTotalInfo(){ } +/* 주문 요청 */ +$(".order_btn").on("click", function(){ + + /* 주소 정보 & 받는이*/ + $(".addressInfo_input_div").each(function(i, obj){ + if($(obj).find(".selectAddress").val() === 'T'){ + $("input[name='addressee']").val($(obj).find(".addressee_input").val()); + $("input[name='memberAddr1']").val($(obj).find(".address1_input").val()); + $("input[name='memberAddr2']").val($(obj).find(".address2_input").val()); + $("input[name='memberAddr3']").val($(obj).find(".address3_input").val()); + } + }); + + /* 사용 포인트 */ + $("input[name='usePoint']").val($(".order_point_input").val()); + + /* 상품정보 */ + let form_contents = ''; + $(".goods_table_price_td").each(function(index, element){ + let bookId = $(element).find(".individual_bookId_input").val(); + let bookCount = $(element).find(".individual_bookCount_input").val(); + let bookId_input = ""; + form_contents += bookId_input; + let bookCount_input = ""; + form_contents += bookCount_input; + }); + $(".order_form").append(form_contents); + + /* 서버 전송 */ + $(".order_form").submit(); + +}); + +