|
|
@@ -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); // 랜덤쿠폰 고객 지급
|
|
|
+ }
|
|
|
}
|