|
|
@@ -1,11 +1,17 @@
|
|
|
package com.style24.front.biz.service;
|
|
|
|
|
|
+import com.style24.core.support.session.TscSession;
|
|
|
+import com.style24.front.support.env.TsfConstants;
|
|
|
+import com.style24.persistence.domain.Cart;
|
|
|
+import com.style24.persistence.domain.Goods;
|
|
|
+import com.style24.persistence.domain.GoodsStock;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.style24.front.biz.dao.TsfCartDao;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/**
|
|
|
* 장바구니 Service
|
|
|
@@ -20,4 +26,80 @@ public class TsfCartService {
|
|
|
@Autowired
|
|
|
private TsfCartDao cartDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TsfGoodsService goodsService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 장바구니 저장
|
|
|
+ * 단품 : goodsCd, optCd, optCd1, optCd2
|
|
|
+ * 세트 : goodsCd,
|
|
|
+ * @param cart
|
|
|
+ */
|
|
|
+ @Transactional("shopTxnManager")
|
|
|
+ public void saveCartInfo(Cart param) {
|
|
|
+ Cart cart = new Cart(); // 최종 정보가 담길 cart 객체
|
|
|
+ // JSESSION_ID 저장
|
|
|
+ param.setJsessionId(TscSession.getSessionId());
|
|
|
+
|
|
|
+ // 로그인 유무 확인 (로그인이 되어 있지 않으면 regNo 를 0으로 장바구니에 저장한다.)
|
|
|
+
|
|
|
+ // 상품 정보 확인
|
|
|
+ Goods goods = new Goods(); // 상품 마스터 정보
|
|
|
+ goods.setGoodsCd(param.getGoodsCd());
|
|
|
+ goods = goodsService.getGoodsInfo(goods);
|
|
|
+ if(goods == null) {
|
|
|
+ throw new IllegalArgumentException("상품 정보가 존재하지 않습니다.");
|
|
|
+ }
|
|
|
+
|
|
|
+ cart.setGoodsCd(goods.getGoodsCd());
|
|
|
+ cart.setProductNo(goods.getProductNo());
|
|
|
+ cart.setProductCode(goods.getProductCode());
|
|
|
+
|
|
|
+ // 재고 정보 확인
|
|
|
+ if(TsfConstants.GOODS_TYPE.SET.value().equals(goods.getGoodsType())) { // 장바구니 상품이 세트상품이라면
|
|
|
+ if(param.getCompsList() != null && param.getCompsList().size() > 0) {
|
|
|
+ for(int i = 0 ; i < param.getCompsList().size() ; i++) {
|
|
|
+ Cart tCart = param.getCompsList().get(i);
|
|
|
+ // 구성상품 구성정보
|
|
|
+ Goods compsGoodsInfo = new Goods();
|
|
|
+ compsGoodsInfo.setGoodsCd(param.getGoodsCd());
|
|
|
+ compsGoodsInfo.setCompsGoodsCd(tCart.getCompsGoodsCd());
|
|
|
+ compsGoodsInfo.setGoodsType(goods.getGoodsType());
|
|
|
+ compsGoodsInfo = goodsService.getGoodsCompsInfo(compsGoodsInfo);
|
|
|
+
|
|
|
+ // 구성상품 재고 정보
|
|
|
+ GoodsStock stock = new GoodsStock();
|
|
|
+ stock.setGoodsCd(compsGoodsInfo.getGoodsCd());
|
|
|
+ stock.setOptCd(tCart.getOptCd());
|
|
|
+ stock = goodsService.getGoodsStockInfo(stock);
|
|
|
+
|
|
|
+ if("Y".equals(stock.getSoldoutYn()) || stock.getCurrStockQty() < 1) {
|
|
|
+ throw new IllegalArgumentException("세트 구성 상품 중 품절 상품이 있습니다.");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 세트상품 요청 수량 * 구성상품 필요 수량이 해당 구성수량의 재고보다 많으면
|
|
|
+ if(param.getItemQty() * compsGoodsInfo.getQty() > stock.getCurrStockQty()) {
|
|
|
+ throw new IllegalArgumentException("요청하신 수량만큼의 재고가 존재하지 않습니다.");
|
|
|
+ }
|
|
|
+
|
|
|
+ tCart.setItemCd(stock.getGoodsCd());
|
|
|
+ tCart.setOptCd(stock.getOptCd());
|
|
|
+ tCart.setOptCd1(stock.getOptCd1());
|
|
|
+ tCart.setOptCd2(stock.getOptCd2());
|
|
|
+ tCart.setSkuModelNo(stock.getSKU_MODEL_NO());
|
|
|
+ tCart.setProductNo(compsGoodsInfo.getProductNo());
|
|
|
+ tCart.setProductCode(compsGoodsInfo.getProductCode());
|
|
|
+ tCart.setItemQty(param.getItemQty() * compsGoodsInfo.getQty());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("세트 상품 정보가 존재하지 않습니다.");
|
|
|
+ }
|
|
|
+ } else { // 딜상품이거나 일반 상품일 경우
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 현재 장바구니에 존재하는지 확인
|
|
|
+
|
|
|
+ // 존재하면 update 없으면 insert
|
|
|
+ }
|
|
|
}
|