Przeglądaj źródła

이태영 - 20210208 장바구니 화면 생성 중

xodud1202 5 lat temu
rodzic
commit
385e0663cc

+ 8 - 0
src/main/java/com/style24/front/biz/dao/TsfCouponDao.java

@@ -20,4 +20,12 @@ public interface TsfCouponDao {
 	 * @since 2021. 02. 16
 	 */
 	Coupon getSerialCpnUseInfo(Coupon param);
+
+	/**
+	 * 입력된 시리얼 쿠폰 정보 조회
+	 * @param param
+	 * @author xodud1202
+	 * @since 2021. 02. 17
+	 */
+	Coupon getSearchSerialCpnInfo(Coupon param);
 }

+ 9 - 9
src/main/java/com/style24/front/biz/service/TsfCartService.java

@@ -115,9 +115,9 @@ public class TsfCartService {
 		StringBuilder sb = new StringBuilder();
 
 		// TODO 로그인 정보 세팅
-		cart.setRegNo(0);
-		cart.setCustNo(0);
-		cart.setUpdNo(0);
+		cart.setRegNo(1000006);
+		cart.setCustNo(1000006);
+		cart.setUpdNo(1000006);
 		cart.setJsessionId(TscSession.getSessionId());
 
 		// 장바구니 보유 CART_SQ 쿼리
@@ -189,9 +189,9 @@ public class TsfCartService {
 	public void saveNormalDealCartInfo(Cart param) {
 		// TODO 로그인 정보 세팅
 		param.setJsessionId(TscSession.getSessionId());
-		param.setRegNo(0);
-		param.setCustNo(0);
-		param.setUpdNo(0);
+		param.setRegNo(1000006);
+		param.setCustNo(1000006);
+		param.setUpdNo(1000006);
 
 		if("C".equals(param.getCartGb())) {
 			param.setCartGb(TscConstants.CartGb.CART.value());
@@ -237,9 +237,9 @@ public class TsfCartService {
 		// TODO 로그인 체크
 		order.setJsessionId(TscSession.getSessionId());
 		order.setJsessionId("aaec62cc-5f91-47bb-ba65-ebc9a61385cf");
-		order.setCustNo(0);
-		order.setRegNo(0);
-		order.setUpdNo(0);
+		order.setCustNo(1000006);
+		order.setRegNo(1000006);
+		order.setUpdNo(1000006);
 
 		// 장바구니 상품 조회
 		Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);

+ 147 - 0
src/main/java/com/style24/front/biz/service/TsfCouponService.java

@@ -1,10 +1,21 @@
 package com.style24.front.biz.service;
 
+import java.util.Collection;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.thymeleaf.util.StringUtils;
 
+import com.style24.core.biz.dao.TscCouponDao;
+import com.style24.core.biz.service.TscCouponService;
+import com.style24.core.biz.service.TscOrderService;
+import com.style24.core.support.env.TscConstants;
 import com.style24.front.biz.dao.TsfCouponDao;
+import com.style24.front.support.security.session.TsfSession;
 import com.style24.persistence.domain.Coupon;
+import com.style24.persistence.domain.CustCoupon;
+import com.style24.persistence.domain.Order;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -21,6 +32,12 @@ public class TsfCouponService {
 	@Autowired
 	private TsfCouponDao couponDao;
 
+	@Autowired
+	private TscCouponDao coreCouponDao;
+
+	@Autowired
+	private TscOrderService coreOrderService;
+
 	/**
 	 * 시리얼 쿠폰 지급 정보 조회
 	 * @param param
@@ -31,4 +48,134 @@ public class TsfCouponService {
 	public Coupon getSerialCpnUseInfo(Coupon param) {
 		return couponDao.getSerialCpnUseInfo(param);
 	}
+
+	/**
+	 * 시리얼 쿠폰 적용
+	 * @param param
+	 * @return
+	 * @author xodud1202
+	 * @since 2021. 02. 16
+	 */
+	public Coupon serialCpnApplyInfo(Coupon param) {
+		Coupon cpn = couponDao.getSearchSerialCpnInfo(param);
+		if(cpn != null && cpn.getCpnId() > 0) {
+			// 다운로드 받을 수 있는 쿠폰이 있음
+
+		} else {
+			// 다운로드 받을 수 있는 쿠폰이 존재하지 않음.
+
+		}
+
+
+
+
+
+		// 시리얼 쿠폰 지급 및 사용 내역 조회
+		Coupon useSerial = getSerialCpnUseInfo(param);
+		if(useSerial == null) {	useSerial = new Coupon();	}
+
+		useSerial.setRdCpnNm(param.getRdCpnNm());
+		useSerial.setCartSqArr(param.getCartSqArr());
+		useSerial.setCustNo(param.getCustNo());
+		useSerial.setRegNo(param.getRegNo());
+		useSerial.setUpdNo(param.getUpdNo());
+
+		Coupon coupon = new Coupon();
+
+		// 시리얼 쿠폰 다운로드하지 않았다면
+		if(useSerial != null && useSerial.getCpnId() > 0) {
+			// 해당 시리얼쿠폰을 사용한적이 있는 경우나, 받은것이 있는경우에 대한 처리
+			if(!StringUtils.isEmpty(useSerial.getUsedDt())) {
+				useSerial.setResult("해당 쿠폰은 이미 사용완료된 쿠폰입니다.");
+				return useSerial;
+			}
+		} else {
+			// 쿠폰 저장 및 할인 가격 적용
+			coupon = couponDao.getSearchSerialCpnInfo(useSerial);
+			if(coupon == null) {
+				useSerial.setResult("해당 쿠폰은 존재하지 않습니다.");
+				return useSerial;
+			} else if (!"Y".equals(coupon.getDownCanGb())) {
+				useSerial.setResult("해당 쿠폰은 사용 할 수 없습니다.");
+				return useSerial;
+			} else {
+				// 랜덤쿠폰 할당 및 쿠폰 지급
+				coupon.setCustNo(useSerial.getCustNo());
+				coupon.setRegNo(useSerial.getRegNo());
+				coupon.setUpdNo(useSerial.getUpdNo());
+				updateGiveRandomCpnInfo(coupon);
+			}
+		}
+
+		// 장바구니쿠폰 토탈 할인 금액 계산
+		coupon.setDcAmt(getCartCpnApplyTotalAmt(useSerial));
+		coupon.setResult("SUCCESS");
+
+		log.info("CHECK INFO >> {} / {}", coupon.getDcAmt(), coupon.getResult());
+
+		return coupon;
+	}
+
+	// 장바구니쿠폰 토탈 할인 금액 계산
+	public int getCartCpnApplyTotalAmt(Coupon param) {
+		// 쿠폰 할당 금액 세팅
+		Order order = new Order();
+		order.setCustNo(param.getCustNo());
+		order.setCartSqArr(param.getCartSqArr());
+		order.setCpnId(param.getCpnId());
+		order.setFrontGb(TsfSession.getFrontGb());
+
+		// 장바구니에 등록된 상품 중 적용 상품 조회
+		int totDcAmt = 0;
+		int totCurrPrice = 0;
+		int maxDcAmt = 0;
+		int buyLimitAmt = 0;
+
+		Collection<Order> serialGoodsList = coreOrderService.getSerialCpnApplyGoodsList(order);
+
+		// 각 필요 데이터 세팅
+		for(Order info : serialGoodsList) {
+			totCurrPrice = totCurrPrice + info.getCurrPrice();				// 적용 상품 구매 금액 합계((즉시할인쿠폰 + 옵션추가) * 수량)
+			maxDcAmt = info.getMaxDcAmt();									// 최대할인율과 최소주문금액은 한 쿠폰에 값이 동일
+			buyLimitAmt = info.getBuyLimitAmt();							// 최대할인율과 최소주문금액은 한 쿠폰에 값이 동일
+			if(TscConstants.DcWay.RATE.value().equals(info.getDcWay())) {	// 할인방식이 할인율이면 각 상품별 할인금액을 따로 계산해야함
+				int dcAmt = (int) (info.getCurrPrice() * (info.getDcVal() / 100.0));		// 해당상품 할인금
+				info.setCartCpnDcAmt(dcAmt);
+				totDcAmt = totDcAmt + dcAmt;								// 적용 상품 총 할인금액
+			} else {														// 할인 방식이 금액일 경우
+				totDcAmt = info.getDcVal();
+			}
+		}
+
+		// 최대 할인 금액 요건 확인 (0은 제한 없음. 최대 할인 금액보다 할인금액이 크다면 최대할인금액만큼만 할인)
+		if(maxDcAmt > 0 && maxDcAmt < totDcAmt) {
+			totDcAmt = maxDcAmt;
+		}
+
+		// 주문 최소 금액 요건 확인 (0은 제한 없음. 최소 주문 금액보다 총 상품 금액이 적으면 0원으로 세팅)
+		if(buyLimitAmt > 0 && buyLimitAmt > totCurrPrice) {
+			totDcAmt = 0;
+		}
+
+		return totDcAmt;
+	}
+
+	@Transactional("shopTxnManager")
+	public void updateGiveRandomCpnInfo(Coupon param) {
+		// 랜덤쿠폰 할당 및 쿠폰 지급
+		CustCoupon custCoupon = new CustCoupon();
+		custCoupon.setCustNo(param.getCustNo());
+		custCoupon.setRegNo(param.getRegNo());
+		custCoupon.setUpdNo(param.getUpdNo());
+		custCoupon.setCpnId(param.getCpnId());
+		custCoupon.setRdCpnId(param.getRdCpnId());
+		custCoupon.setEndAlimSendYn("N");		// 알림 발송 여부(발송되면 Y)
+		custCoupon.setAvailStdt(param.getAvailStdt());
+		custCoupon.setAvailEddt(param.getAvailEddt());
+		custCoupon.setPubReason("G068_60");		// 쿠폰 발행사유 (랜덤쿠폰등록)
+		custCoupon.setPubReasonDtl(param.getRdCpnNm() + " 쿠폰 등록");
+
+		coreCouponDao.updateGiveRandomCoupon(custCoupon);		// 랜덤쿠폰 CUST_NO UPDATE
+		coreCouponDao.saveCouponCustPub(custCoupon);			// 랜덤쿠폰 고객 지급
+	}
 }

+ 19 - 21
src/main/java/com/style24/front/biz/web/TsfCartController.java

@@ -128,34 +128,32 @@ public class TsfCartController extends TsfBaseController {
 		return super.getDeviceViewName("cart/cartListAjaxForm");
 	}
 
+	/**
+	 * 프로모션 할인 쿠폰 조회
+	 * @param param
+	 * rdCpnNm : 시리얼쿠폰명
+	 * cartSqArr[] : 장바구니 번호 배열
+	 * @return GagaMap
+	 * @author xodud1202
+	 * @since 2021. 02. 17
+	 */
 	@ResponseBody
 	@PostMapping("/list/serialCpnApply")
-	public GagaMap serialCpnApply(@RequestBody Cart param) {
-		// 시리얼 쿠폰 사용 정보 조회
-		Coupon cpn = new Coupon();
-		cpn.setRdCpnNm(param.getRdCpnNm());
-		cpn.setCartSqArr(param.getCartSqArr());
-		// TODO 로그인 정보 입력
-		cpn.setCustNo(1000006);
-
-		Coupon useSerial = couponService.getSerialCpnUseInfo(cpn);
-
-		// 시리얼 쿠폰 다운로드하지 않았다면
-		if(useSerial != null) {
-			// 해당 시리얼쿠폰을 사용한적이 있는 경우나, 받은것이 있는경우에 대한 처리(분기)
-
-		} else {
-			// 해당 쿠폰 저장
-
-		}
+	public GagaMap serialCpnApply(@RequestBody Coupon param) {
+		GagaMap result = new GagaMap();
 
-		log.info("CHECK IN >> {}", param.getSerialCpnNm());
+		log.info("CHECK IN >> {}", param.getRdCpnNm());
 		log.info("CHECK IN >> {}", param.getCartSqArr());
 
+		// TODO 로그인 정보 입력
+		param.setCustNo(1000006);
+		param.setRegNo(1000006);
+		param.setUpdNo(1000006);
 
+		// 시리얼 쿠폰 정보 조회 및 쿠폰 지급 미대상인 경우 쿠폰 지급
+		Coupon useSerial = couponService.serialCpnApplyInfo(param);
 
-		GagaMap result = new GagaMap();
-		result.put("testResult", "SUCCESS");
+		result.put("serialCpnInfo", useSerial);
 
 		return result;
 	}

+ 0 - 2
src/main/java/com/style24/persistence/domain/Cart.java

@@ -58,6 +58,4 @@ public class Cart extends TscBaseDomain {
 	private String cpnNm;
 	private String rdCpnNm;
 	private String usedDt;
-	private String serialCpnNm;
-
 }

+ 10 - 0
src/main/java/com/style24/persistence/domain/Coupon.java

@@ -19,7 +19,17 @@ public class Coupon extends TscBaseDomain {
 	private int[] cartSqArr;		// 장바구니 일련번호 배열
 	private int cpnId;				// 쿠폰번호
 	private int custNo;				// 회원번호
+	private int availDays;			// 쿠폰 다운로드 후 유효기간일
+	private int rdCpnId;			// 랜덤쿠폰번호
+	private int dcAmt;				// 할인금액
+	private String useYn;			// 쿠폰 사용 여부
 	private String cpnNm;			// 쿠폰명
 	private String rdCpnNm;			// 시리얼쿠폰 키
 	private String usedDt;			// 쿠폰 사용완료 일자
+	private String result;			// 결과
+	private String downCanGb;		// 다운로드 가능 구분
+	private String pdGb;			// 기간/일수 구분 (P : 기간, D : 일수)
+	private String availStdt;		// 쿠폰 유효일
+	private String availEddt;		// 쿠폰 유효일
+	private String endAlimYn;		// 쿠폰 종료 알림 여부
 }

+ 41 - 3
src/main/java/com/style24/persistence/mybatis/shop/TsfCoupon.xml

@@ -17,16 +17,54 @@
 	<!-- 시리얼 쿠폰 지급 정보 조회 -->
 	<select id="getSerialCpnUseInfo" parameterType="Coupon" resultType="Coupon">
 		/* TsfCoupon.getSerialCpnUseInfo */
-		SELECT CP.CPN_NM
+		SELECT CP.CPN_ID
+			 , CP.CPN_NM
+			 , CP.END_ALIM_YN
 			 , RC.RD_CPN_NM
+			 , RC.RD_CPN_ID
 			 , DATE_FORMAT(CC.USED_DT, '%Y-%m-%d %H:%i:%S') AS USED_DT
 		FROM   TB_COUPON CP
 		INNER  JOIN TB_RANDOM_COUPON RC
 		ON     CP.CPN_ID = RC.CPN_ID
 		INNER  JOIN TB_CUST_COUPON CC
 		ON     CP.CPN_ID = CC.CPN_ID
+		LEFT OUTER JOIN (SELECT CC.CPN_ID			<!-- 해당 시리얼키로 다운받은 쿠폰번호를 올려서 제거 (기간이 맞지 않은 다른 쿠폰에서 같은 시리얼키로 쿠폰이 나올 수 있어 ID로 찾아야함) -->
+							  , CC.USED_DT
+						 FROM   TB_CUST_COUPON CC
+						 INNER  JOIN TB_RANDOM_COUPON RC
+						 ON     CC.CPN_ID = RC.CPN_ID
+						 WHERE  RC.RD_CPN_NM =  #{rdCpnNm}
+						 AND    CC.CUST_NO =  #{custNo}
+						 AND    CC.USED_DT IS NOT NULL)  USE_CPN
+		ON     CP.CPN_ID = USE_CPN.CPN_ID
 		WHERE  1=1
-		AND    RC.RD_CPN_NM = ${rdCpnNm}
-		AND    CC.CUST_NO = ${custNo}
+		AND    USE_CPN.CPN_ID IS NULL				<!-- 사용한 쿠폰 제거 -->
+		AND    RC.RD_CPN_NM = #{rdCpnNm}
+		AND    CC.CUST_NO = #{custNo}
+	</select>
+
+	<!-- 입력된 시리얼 쿠폰 정보 조회 -->
+	<select id="getSearchSerialCpnInfo" parameterType="Coupon" resultType="Coupon">
+		/* TsfCoupon.getSearchSerialCpnInfo : 입력된 시리얼 쿠폰 정보 조회 */
+		SELECT CP.CPN_ID
+			 , CP.CPN_NM
+		     , CP.END_ALIM_YN
+			 , RC.RD_CPN_NM
+		     , RC.RD_CPN_ID
+			 , CASE WHEN CP.PD_GB = 'D' THEN DATE_FORMAT(NOW(), '%Y%m%d%H%i%S')
+			     	ELSE DATE_FORMAT(CP.AVAIL_STDT, '%Y%m%d%H%i%S') END AS AVAIL_STDT
+			 , CASE WHEN CP.PD_GB = 'D' THEN DATE_FORMAT(DATE_ADD(NOW(), INTERVAL CP.AVAIL_DAYS DAY), '%Y%m%d%H%i%S')
+			     	ELSE  DATE_FORMAT(CP.AVAIL_EDDT, '%Y%m%d%H%i%S') END AS AVAIL_EDDT
+			 , CASE WHEN NOW() BETWEEN CP.DOWN_STDT AND CP.DOWN_EDDT THEN 'Y'
+					ELSE 'N' END AS downCanGb
+		FROM   TB_COUPON CP
+		INNER  JOIN TB_RANDOM_COUPON RC
+		ON     CP.CPN_ID = RC.CPN_ID
+		WHERE  1=1
+		AND    RC.RD_CPN_NM = #{rdCpnNm}
+		AND    NOW() BETWEEN CP.DOWN_STDT AND CP.DOWN_EDDT
+		ORDER  BY RC.CPN_ID
+		<!-- 랜덤쿠폰은 RD_CPN_NM이 1개이나, 시리얼 쿠폰은 다수개이므로 하나의 정보만 조회 -->
+		LIMIT  1
 	</select>
 </mapper>

+ 12 - 3
src/main/webapp/WEB-INF/views/web/cart/cartListAjaxFormWeb.html

@@ -1,6 +1,8 @@
 <html lang="ko"
       xmlns:th="http://www.thymeleaf.org">
 <form id="cartListForm" method="post" action="/order/noMember">
+    <input type="hidden" name="cartCpnDcAmt" id="cartCpnDcAmt" th:value="${param.cartCpnDcAmt}" />
+
 <!-- CONT-BODY -->
 <div class="od_cont">
     <div class="sec_head" th:if="${order.shotCanYn.equals('Y')}">
@@ -294,14 +296,14 @@
                 </div>
                 <div>
                     <dt>할인금액</dt>
-                    <dd><span class="disc_amount"><em th:text="${#numbers.formatInteger(order.totDcAmt, 1, 'COMMA')}"></em>원</span></dd>
+                    <dd><span class="disc_amount"><em id="totDcAmt" th:text="${#numbers.formatInteger(order.totDcAmt, 1, 'COMMA')}"></em>원</span></dd>
                 </div>
             </dl>
         </div>
         <div class="totalprice_box">
             <dl>
                 <dt>총 결제 예정 금액</dt>
-                <dd data-weight="price" data-font="lato"><span th:text="${#numbers.formatInteger(order.sumRealPayAmt, 1, 'COMMA')}"></span>원</dd>
+                <dd data-weight="price" data-font="lato"><span id="sumRealPayAmt" th:text="${#numbers.formatInteger(order.sumRealPayAmt, 1, 'COMMA')}"></span>원</dd>
             </dl>
         </div>
         <div class="btn_box">
@@ -409,7 +411,12 @@
 </form>
 
 <script type="text/javascript">
+    let sumRealPayAmt = [[${order.sumRealPayAmt}]];
+    let totDcAmt = [[${order.totDcAmt}]];
+
     $(document).ready(function() {
+        $("#sumRealPayAmt").text(Number(sumRealPayAmt).toLocaleString());
+        $("#totDcAmt").text(Number(totDcAmt).toLocaleString());
         //$("#cartListForm").submit();
        /* $.ajax( {
             type: "POST",
@@ -443,7 +450,9 @@
             dataType : 'json',
             data : jsonData,
             success : function(result) {
-                alert(result.testResult);
+                alert(result.serialCpnInfo.result + " / " + result.serialCpnInfo.dcAmt);
+                $("#sumRealPayAmt").text(Number(sumRealPayAmt - result.serialCpnInfo.dcAmt).toLocaleString());
+                $("#totDcAmt").text(Number(totDcAmt - result.serialCpnInfo.dcAmt).toLocaleString());
             }
         });
     };