|
|
@@ -17,10 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
+import org.thymeleaf.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 장바구니 Service
|
|
|
@@ -252,6 +255,8 @@ public class TsfCartService {
|
|
|
checkParam.setGoodsType(goods.getGoodsType());
|
|
|
String stockResult = goodsService.getCheckStock(checkParam);
|
|
|
|
|
|
+ //String stockResult = "SUCCESS";
|
|
|
+
|
|
|
if("SUCCESS".equals(stockResult)) {
|
|
|
goods.setSoldoutYn("N");
|
|
|
cartSqs.add(goods.getCartSq());
|
|
|
@@ -292,42 +297,37 @@ public class TsfCartService {
|
|
|
* @since 2021. 01. 28
|
|
|
*/
|
|
|
public Collection<Order> getMoreBetterAmtList(Order param) {
|
|
|
- //Collection<Order> result = new ArrayList<Order>();
|
|
|
-
|
|
|
// 장바구니 상품 조회
|
|
|
param.setFrontGb(TsfSession.getFrontGb());
|
|
|
Collection<Order> cartGoodsList = coreOrderService.getCartGoodsList(param);
|
|
|
|
|
|
- // 장바구니 내 적용 가능 다다익선 조회 (등록된 기본,적용 상품 정보 전체 조회)
|
|
|
- Collection<Order> tmtbApplyList = cartDao.selectMoreBetterApplyCartList(param);
|
|
|
+ // 장바구니 내 수량 다다익선 적용 가능 리스트 조회 (등록된 기본,적용 상품 정보 전체 조회)
|
|
|
+ param.setApplyGb(TscConstants.ApplyGb.QTY.value());
|
|
|
+ Collection<Order> tmtbQtyApplyList = cartDao.selectMoreBetterApplyCartList(param);
|
|
|
|
|
|
- // 장바구니에 담긴 상품 금액 (즉시할인가 + 상품 옵션가)를 tmtbApplyList 에 저장 (추후 계산식을 위함)
|
|
|
+ // 장바구니에 담긴 상품 금액 즉시할인가를 tmtbApplyList 에 저장 (추후 계산식을 위함)
|
|
|
for(Order cart : cartGoodsList) {
|
|
|
- for(Order apply : tmtbApplyList) {
|
|
|
- if(cart.getCartSq() == apply.getCartSq() && TscConstants.GoodsType.SET.value().equals(cart.getGoodsType())) {
|
|
|
- apply.setCurrPrice(cart.getCurrPrice());
|
|
|
- apply.setOptAddPrice(cart.getOptAddPrice());
|
|
|
- } else if(cart.getCartSq() == apply.getCartSq() && !TscConstants.GoodsType.SET.value().equals(cart.getGoodsType())) {
|
|
|
- apply.setCurrPrice(cart.getCurrPrice() + cart.getOptAddPrice());
|
|
|
- apply.setOptAddPrice(cart.getOptAddPrice());
|
|
|
+ for(Order apply : tmtbQtyApplyList) {
|
|
|
+ if(cart.getCartSq() == apply.getCartSq()) {
|
|
|
+ apply.setCurrPrice(cart.getCurrPrice() + cart.getOptAddPrice()); /* 즉시할인 적용가 */
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 장바구니 등록 다다익선 일련번호 지정
|
|
|
- List<Integer> applySq = new ArrayList<Integer>();
|
|
|
- for(Order tmtbApply : tmtbApplyList) {
|
|
|
+ // 장바구니 등록 수량 다다익선 일련번호 지정
|
|
|
+ List<Integer> qtyApplySq = new ArrayList<Integer>();
|
|
|
+ for(Order tmtbApply : tmtbQtyApplyList) {
|
|
|
if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getGoodsGb())) {
|
|
|
- applySq.add(tmtbApply.getTmtbSq());
|
|
|
+ qtyApplySq.add(tmtbApply.getTmtbSq());
|
|
|
}
|
|
|
}
|
|
|
- param.setTmtbSqs(applySq.stream().mapToInt(Integer::intValue).toArray());
|
|
|
+ param.setTmtbSqs(qtyApplySq.stream().mapToInt(Integer::intValue).toArray());
|
|
|
|
|
|
// 장바구니 등록 다다익선 총합 금액
|
|
|
- Collection<Order> tmtbSumDataList = cartDao.selectApplyMoreBetterCartInfoList(param);
|
|
|
+ Collection<Order> tmtbQtySumDataList = cartDao.selectApplyMoreBetterCartInfoList(param);
|
|
|
// 기본상품 목록에 총합 데이터 등록
|
|
|
- for(Order applyInfo : tmtbApplyList) {
|
|
|
- for(Order tmtbSumInfo : tmtbSumDataList) {
|
|
|
+ for(Order applyInfo : tmtbQtyApplyList) {
|
|
|
+ for(Order tmtbSumInfo : tmtbQtySumDataList) {
|
|
|
if(applyInfo.getTmtbSq() == tmtbSumInfo.getTmtbSq()) {
|
|
|
applyInfo.setTmtbSumAmt(tmtbSumInfo.getTmtbSumAmt());
|
|
|
applyInfo.setTmtbSumQty(tmtbSumInfo.getTmtbSumQty());
|
|
|
@@ -336,39 +336,139 @@ public class TsfCartService {
|
|
|
}
|
|
|
|
|
|
// 섹션 정보 조회 후 할인 여부 판단
|
|
|
- Collection<Order> tmtbSectionList = cartDao.selectTmtbSectionValList(applySq);
|
|
|
- for(Order applyInfo : tmtbApplyList) { // 기준 상품 및 다다익선 정보 조회
|
|
|
- for(Order section : tmtbSectionList) { // 다다익선 할인 조건 조회
|
|
|
+ Collection<Order> tmtbQtySectionList = cartDao.selectTmtbSectionValList(qtyApplySq);
|
|
|
+ for(Order applyInfo : tmtbQtyApplyList) { // 기준 상품 및 다다익선 정보 조회
|
|
|
+ for(Order section : tmtbQtySectionList) { // 다다익선 할인 조건 조회
|
|
|
if(applyInfo.getTmtbSq() == section.getTmtbSq()) {
|
|
|
- applyInfo.setTmtbNm(section.getTmtbNm());
|
|
|
-
|
|
|
if(TscConstants.ApplyGb.QTY.value().equals(applyInfo.getApplyGb())) { // 수량 적용
|
|
|
if(section.getSectionVal() <= applyInfo.getTmtbSumQty()) { // 장바구니 수량 할인 기준 달성시
|
|
|
if(applyInfo.getSectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
|
|
|
applyInfo.setSectionVal(section.getSectionVal());
|
|
|
- applyInfo.setApplyQtySectionVal(section.getTmtbSumQty());
|
|
|
- applyInfo.setApplyAmtSectionVal(section.getTmtbSumAmt());
|
|
|
applyInfo.setApplyQtySectionYn("Y");
|
|
|
applyInfo.setDcWay(section.getDcWay());
|
|
|
applyInfo.setDcVal(section.getDcVal());
|
|
|
}
|
|
|
} else {
|
|
|
- if(applyInfo.getGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
|
|
|
+ if(applyInfo.getSectionVal() < 1 && applyInfo.getGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
|
|
|
applyInfo.setApplyQtySectionYn("N");
|
|
|
}
|
|
|
}
|
|
|
- } else if (TscConstants.ApplyGb.AMT.value().equals(applyInfo.getApplyGb())) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 수량 다다익선 적용 상품 할인 금액 계산
|
|
|
+ int leftAmt = 0;
|
|
|
+ int i = 0;
|
|
|
+ for(Order resultAmt : tmtbQtyApplyList) {
|
|
|
+ if("Y".equals(resultAmt.getApplyQtySectionYn())) {
|
|
|
+ if (TscConstants.DcWay.AMT.value().equals(resultAmt.getDcWay())) { // 할인 방식 금액일경우
|
|
|
+ i++;
|
|
|
+ int tempAmt = resultAmt.getCurrPrice() * resultAmt.getGoodsQty();
|
|
|
+ if (i == 1) {
|
|
|
+ leftAmt = resultAmt.getDcVal();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == resultAmt.getTmtbCnt()) {
|
|
|
+ resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
|
|
|
+ leftAmt = 0;
|
|
|
+ i = 0;
|
|
|
+ } else {
|
|
|
+ double tempDcAmt = resultAmt.getDcVal() * ((tempAmt) / (double)resultAmt.getTmtbSumAmt());
|
|
|
+ leftAmt -= (int)tempDcAmt;
|
|
|
+ resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
|
|
|
+ }
|
|
|
+ } else { // 할인 방식 할인율일 경우
|
|
|
+ int tempAmt = resultAmt.getCurrPrice() * resultAmt.getGoodsQty();
|
|
|
+ tempAmt = (int) (tempAmt - (tempAmt * (resultAmt.getDcVal() / 100.0)));
|
|
|
+ resultAmt.setTmtbDcAmt(tempAmt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 장바구니 정보에 수량 다다익선 정보 입력
|
|
|
+ for(Order cart : cartGoodsList) {
|
|
|
+ for(Order apply : tmtbQtyApplyList) {
|
|
|
+ if(cart.getCartSq() == apply.getCartSq()) {
|
|
|
+ cart.setTmtbDcAmt(apply.getTmtbDcAmt());
|
|
|
+ cart.setQtySumCurrPrice(apply.getCurrPrice() * apply.getGoodsQty());
|
|
|
+ cart.setApplyQtySectionYn(apply.getApplyQtySectionYn());
|
|
|
+ cart.setQtyTmtbNm(apply.getTmtbNm());
|
|
|
+ cart.setQtyTmtbSq(apply.getTmtbSq());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 장바구니 내 금액 다다익선 적용 가능 리스트 조회 (등록된 기본,적용 상품 정보 전체 조회)
|
|
|
+ param.setApplyGb(TscConstants.ApplyGb.AMT.value());
|
|
|
+ Collection<Order> tmtbAmtApplyList = cartDao.selectMoreBetterApplyCartList(param);
|
|
|
+
|
|
|
+ // 장바구니에 담긴 상품 금액 즉시할인가를 tmtbAmtApplyList 에 저장 (추후 계산식을 위함)
|
|
|
+ for(Order cart : cartGoodsList) {
|
|
|
+ for(Order apply : tmtbAmtApplyList) {
|
|
|
+ if(cart.getCartSq() == apply.getCartSq()) {
|
|
|
+ if (StringUtils.isEmpty(cart.getQtyTmtbNm())) {
|
|
|
+ apply.setCurrPrice((cart.getCurrPrice() + cart.getOptAddPrice()) * cart.getGoodsQty());
|
|
|
+ } else {
|
|
|
+ apply.setCurrPrice(cart.getTmtbDcAmt()); /* 수량 다다익선 할인된 금액 적용 */
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 장바구니 등록 수량 다다익선 일련번호 지정
|
|
|
+ List<Integer> amtApplySq = new ArrayList<Integer>();
|
|
|
+ for(Order tmtbApply : tmtbAmtApplyList) {
|
|
|
+ if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getGoodsGb())) {
|
|
|
+ amtApplySq.add(tmtbApply.getTmtbSq());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ param.setTmtbSqs(amtApplySq.stream().mapToInt(Integer::intValue).toArray());
|
|
|
+
|
|
|
+ // 장바구니 등록 금액 다다익선 총합 금액
|
|
|
+ Collection<Order> tmtbAmtSumDataList = cartDao.selectApplyMoreBetterCartInfoList(param);
|
|
|
+
|
|
|
+ Map<Integer, Integer> tmtbAmtSumData = new HashMap<Integer, Integer>(); // 각 상품별 할인 금액을 다다익선별 SUM하기 위한 MAP
|
|
|
+ for(Order applyInfo : tmtbAmtApplyList) {
|
|
|
+ // SUM AMT는 할인된 금액으로 묶어야함.
|
|
|
+ if(tmtbAmtSumData.get(applyInfo.getTmtbSq()) != null && tmtbAmtSumData.get(applyInfo.getTmtbSq()) > 0) {
|
|
|
+ tmtbAmtSumData.put(applyInfo.getTmtbSq(), tmtbAmtSumData.get(applyInfo.getTmtbSq()) + applyInfo.getCurrPrice());
|
|
|
+ } else {
|
|
|
+ tmtbAmtSumData.put(applyInfo.getTmtbSq(), applyInfo.getCurrPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 기본상품 목록에 총합 데이터 등록
|
|
|
+ for(Order applyInfo : tmtbAmtApplyList) {
|
|
|
+ for(Order tmtbSumInfo : tmtbAmtSumDataList) {
|
|
|
+ if(applyInfo.getTmtbSq() == tmtbSumInfo.getTmtbSq()) {
|
|
|
+ applyInfo.setTmtbSumQty(tmtbSumInfo.getTmtbSumQty());
|
|
|
+
|
|
|
+ if(tmtbAmtSumData.get(applyInfo.getTmtbSq()) != null && tmtbAmtSumData.get(applyInfo.getTmtbSq()) > 0) {
|
|
|
+ applyInfo.setTmtbSumAmt(tmtbAmtSumData.get(applyInfo.getTmtbSq()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 섹션 정보 조회 후 할인 여부 판단
|
|
|
+ Collection<Order> tmtbAmtSectionList = cartDao.selectTmtbSectionValList(amtApplySq);
|
|
|
+ for(Order applyInfo : tmtbAmtApplyList) { // 기준 상품 및 다다익선 정보 조회
|
|
|
+ for(Order section : tmtbAmtSectionList) { // 다다익선 할인 조건 조회
|
|
|
+ if(applyInfo.getTmtbSq() == section.getTmtbSq()) {
|
|
|
+ if (TscConstants.ApplyGb.AMT.value().equals(applyInfo.getApplyGb())) {
|
|
|
if(section.getSectionVal() <= applyInfo.getTmtbSumAmt()) { // 장바구니 수량 할인 기준 달성시
|
|
|
if(applyInfo.getSectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
|
|
|
applyInfo.setSectionVal(section.getSectionVal());
|
|
|
- applyInfo.setApplyAmtSectionVal(section.getSectionVal());
|
|
|
applyInfo.setApplyAmtSectionYn("Y");
|
|
|
applyInfo.setDcWay(section.getDcWay());
|
|
|
applyInfo.setDcVal(section.getDcVal());
|
|
|
}
|
|
|
} else {
|
|
|
- if(applyInfo.getGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
|
|
|
- applyInfo.setApplyQtySectionYn("N");
|
|
|
+ if(applyInfo.getSectionVal() < 1 && applyInfo.getGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
|
|
|
+ applyInfo.setApplyAmtSectionYn("N");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -376,52 +476,46 @@ public class TsfCartService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 다다익선 적용 상품 할인 금액 계산
|
|
|
- // resultAmt.currPrice = 즉시할인 + 옵션가 (수량계산안한값)
|
|
|
- // resultAmt.getApplyAmtSectionVal = 다다익선 등록 상품 총합계금액 (수량, 금액 모두 들어있음)
|
|
|
- // resultAmt.getApplyQtySectionVal = 다다익선 등록 상품 총합계수량 (수량만)
|
|
|
- // resultAmt.getApplyAmtSectionYn() = 다다익선 금액할인 만족 여부
|
|
|
- // resultAmt.getApplyQtySectionYn() = 다다익선 수량할인 만족 여부
|
|
|
- int leftAmt = 0;
|
|
|
- int i = 0;
|
|
|
- boolean check = true;
|
|
|
- for(Order resultAmt : tmtbApplyList) {
|
|
|
- if("Y".equals(resultAmt.getApplyQtySectionYn())) {
|
|
|
- if(TscConstants.DcWay.AMT.value().equals(resultAmt.getDcWay())) { // 할인 방식 금액일경우
|
|
|
+ // 금액 다다익선 할인 계산
|
|
|
+ leftAmt = 0;
|
|
|
+ i = 0;
|
|
|
+ for(Order resultAmt : tmtbAmtApplyList) {
|
|
|
+ if("Y".equals(resultAmt.getApplyAmtSectionYn())) {
|
|
|
+ if (TscConstants.DcWay.AMT.value().equals(resultAmt.getDcWay())) { // 할인 방식 금액일경우
|
|
|
i++;
|
|
|
- if(i == 1) {
|
|
|
+ int tempAmt = resultAmt.getCurrPrice();
|
|
|
+ if (i == 1) {
|
|
|
leftAmt = resultAmt.getDcVal();
|
|
|
- check = false;
|
|
|
}
|
|
|
|
|
|
- if(i == resultAmt.getTmtbCnt()) {
|
|
|
- check = true;
|
|
|
- i = 0;
|
|
|
- resultAmt.setTmtbDcAmt(leftAmt);
|
|
|
+ if (i == resultAmt.getTmtbCnt()) {
|
|
|
+ resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
|
|
|
leftAmt = 0;
|
|
|
+ i = 0;
|
|
|
} else {
|
|
|
- int tempAmt = resultAmt.getDcVal() * (((resultAmt.getCurrPrice() + resultAmt.getOptAddPrice()) * resultAmt.getGoodsQty()) / resultAmt.getTmtbSumAmt());
|
|
|
- leftAmt -= tempAmt;
|
|
|
- resultAmt.setTmtbDcAmt(tempAmt);
|
|
|
+ double tempDcAmt = resultAmt.getDcVal() * ((tempAmt) / (double)resultAmt.getTmtbSumAmt());
|
|
|
+ leftAmt -= (int)tempDcAmt;
|
|
|
+ resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
|
|
|
}
|
|
|
- } else { // 할인 방식 할인율일 경우
|
|
|
- int tempAmt = (resultAmt.getCurrPrice() + resultAmt.getOptAddPrice()) * resultAmt.getGoodsQty();
|
|
|
- tempAmt = tempAmt - (tempAmt * (resultAmt.getDcVal()/100));
|
|
|
+ } else { // 할인 방식 할인율일 경우
|
|
|
+ int tempAmt = resultAmt.getCurrPrice();
|
|
|
+ tempAmt = (int) (tempAmt - (tempAmt * (resultAmt.getDcVal() / 100.0)));
|
|
|
resultAmt.setTmtbDcAmt(tempAmt);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 데이터 통합
|
|
|
+ // 장바구니 정보에 수량 다다익선 정보 입력
|
|
|
for(Order cart : cartGoodsList) {
|
|
|
- for(Order apply : tmtbApplyList) {
|
|
|
+ for(Order apply : tmtbAmtApplyList) {
|
|
|
if(cart.getCartSq() == apply.getCartSq()) {
|
|
|
- cart.setTmtbDcAmt(apply.getTmtbDcAmt());
|
|
|
- cart.setApplyQtySectionYn(apply.getApplyQtySectionYn());
|
|
|
- cart.setApplyAmtSectionYn(apply.getApplyQtySectionYn());
|
|
|
- cart.setCurrPrice((apply.getCurrPrice() + apply.getOptAddPrice()) * apply.getGoodsQty());
|
|
|
- cart.setTmtbNm(apply.getTmtbNm());
|
|
|
- cart.setTmtbSq(apply.getTmtbSq());
|
|
|
+
|
|
|
+ if(apply.getTmtbDcAmt() > 0) {
|
|
|
+ cart.setTmtbDcAmt(apply.getTmtbDcAmt());
|
|
|
+ }
|
|
|
+ cart.setApplyAmtSectionYn(apply.getApplyAmtSectionYn());
|
|
|
+ cart.setAmtTmtbNm(apply.getTmtbNm());
|
|
|
+ cart.setAmtTmtbSq(apply.getTmtbSq());
|
|
|
}
|
|
|
}
|
|
|
}
|