| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450 |
- package com.style24.front.biz.service;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.core.env.Environment;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.thymeleaf.util.StringUtils;
- import com.style24.core.biz.dao.TscEnvsetDao;
- import com.style24.core.biz.service.TscKcpService;
- import com.style24.core.biz.service.TscOrderService;
- import com.style24.core.support.env.TscConstants;
- import com.style24.core.support.session.TscSession;
- import com.style24.front.biz.dao.TsfCartDao;
- import com.style24.front.biz.dao.TsfGoodsDao;
- import com.style24.front.support.security.session.TsfSession;
- import com.style24.persistence.domain.Cart;
- import com.style24.persistence.domain.Goods;
- import com.style24.persistence.domain.GoodsStock;
- import com.style24.persistence.domain.Login;
- import com.style24.persistence.domain.Order;
- import lombok.extern.slf4j.Slf4j;
- import com.gagaframework.web.parameter.GagaMap;
- /**
- * 장바구니 Service
- *
- * @author gagamel
- * @since 2020. 12. 29
- */
- @Service
- @Slf4j
- public class TsfCartService {
- @Autowired
- private TsfCartDao cartDao;
- @Autowired
- private TsfGoodsDao goodsDao;
- @Autowired
- private TsfGoodsService goodsService;
- @Autowired
- private TscOrderService coreOrderService;
- @Autowired
- private TscKcpService coreKcpService;
- @Autowired
- private Environment env;
- @Autowired
- private TscEnvsetDao coreEnvsetDao;
- /**
- * 장바구니 저장
- * 단품 : goodsCd, optCd, optCd1, optCd2
- * 세트 : goodsCd,
- * @param params
- */
- @Transactional("shopTxnManager")
- public GagaMap saveCartInfo(Collection<Cart> params) {
- GagaMap result = new GagaMap();
- List<Integer> cartSqList = new ArrayList<>();
- String newCustCanYn = "Y";
- // 로그인 유무 확인 (로그인이 되어 있지 않으면 regNo 를 0으로 장바구니에 저장한다.)
- Login login = new Login();
- if(TsfSession.isLogin()) {
- login = TsfSession.getInfo();
- } else {
- login.setCustNo(0);
- login.setCustGrade("G110");
- }
- result.put("custNo", login.getCustNo());
- String goodsType = params.iterator().next().getGoodsType();
- String cartGb = params.iterator().next().getCartGb();
- if(StringUtils.isEmpty(goodsType)) {
- goodsType = params.iterator().next().getCartCompsList().iterator().next().getGoodsType();
- }
- if(StringUtils.isEmpty(cartGb)) {
- cartGb = params.iterator().next().getCartCompsList().iterator().next().getCartGb();
- }
-
- // 2021.04.13 jsh77b 주문서에서 유효성 체크를 위해서 추가
- String checkGb = "";
- if (params.iterator().next().getCheckGb() == null) {
- checkGb = "C";
- } else {
- checkGb = params.iterator().next().getCheckGb();
- }
-
- // 장바구니 상품 및 재고 가능 여부 체크
- if(TscConstants.GoodsType.SET.value().equals(goodsType)) {
- for (Cart goodsParams : params) {
- for (Cart param : goodsParams.getCartCompsList()) {
- param.setCustNo(login.getCustNo());
- // 상품 마스터 정보 확인
- Goods goods = new Goods();
- goods.setGoodsCd(param.getGoodsCd());
- goods.setFrontGb(TsfSession.getFrontGb());
- goods.setSiteCd(TscConstants.Site.STYLE24.value());
- goods = goodsService.getGoodsInfo(goods);
- // 신규 고객 주문 가능 상품 체크
- if("Y".equals(goods.getNewCustOrdYn())) {
- Goods tmp = new Goods();
- tmp.setCustNo(login.getCustNo());
- tmp.setGoodsCd(param.getGoodsCd());
- tmp = goodsDao.getNewCustOrdCanYnInfo(tmp);
- if("N".equals(tmp.getNewCustCanYn())) {
- newCustCanYn = "N";
- }
- }
- if (goods == null) {
- result.put("message", "상품 정보가 존재하지 않습니다.");
- return result;
- } else if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
- result.put("message", "품절입니다.");
- return result;
- } else if (!TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat()) && !TscConstants.GoodsStat.APPR.value().equals(goods.getGoodsStat())) {
- result.put("message", "판매중인 상품이 아닙니다.");
- return result;
- } else if (param.getGoodsQty() > goods.getMaxOrdQty()) {
- result.put("message", goods.getGoodsNm() + " 상품의 최대 구매 수량은 " + goods.getMaxOrdQty() + " 입니다.");
- return result;
- } else if (param.getGoodsQty() < goods.getMinOrdQty()) {
- result.put("message", goods.getGoodsNm() + " 상품의 최소 구매 수량은 " + goods.getMinOrdQty() + " 입니다.");
- return result;
- }
- // 상품 구매 가능 등급 조회
- Collection<Goods> gradeList = goodsDao.getGoodsDetailOrderGradeList(goods);
- // 구매가능 등급이 없으면 전체 구매 가능
- if(gradeList != null && gradeList.size() > 0) {
- // 구매가능 등급이 존재하면 비회원은 구매 불가. 회원은 등급체크.
- if(login.getCustNo() > 0) {
- boolean chkGrade= false;
- for(Goods grade : gradeList) {
- if(grade.getCustGrade().equals(login.getCustGrade())) {
- chkGrade = true;
- }
- }
- // 구매가능 등급이 아니면 장바구니 등록 X
- if(!chkGrade) {
- result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
- return result;
- }
- } else {
- result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
- return result;
- }
- }
- // 상품 재고 확인
- GoodsStock checkParam = new GoodsStock();
- checkParam.setGoodsCd(param.getGoodsCd());
- checkParam.setItemCd(param.getItemCd());
- checkParam.setOptCd(param.getOptCd());
- checkParam.setGoodsQty(param.getGoodsQty());
- checkParam.setGoodsType(param.getGoodsType());
- String stockResult = goodsService.getCheckStock(checkParam);
- if (!"SUCCESS".equals(stockResult)) {
- result.put("message", stockResult);
- return result;
- }
- // 금일 주문 수량 체크
- if (!StringUtils.isEmpty(param.getCartGb()) && ("N".equals(param.getCartGb()) || "O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
- int goodsCartCnt = 0;
- if(param.getCustNo() != 0) {
- goodsCartCnt = cartDao.getGoodsTodayOrderCnt(param);
- }
- if (param.getGoodsQty() + goodsCartCnt > goods.getDayMaxOrdQty()) {
- result.put("message", "1일 구매한도 수량이 초과되었습니다.");
- return result;
- }
- }
- }
- }
- // 2021.04.13 jsh77b 주문서에서 유효성 체크를 위해서 추가
- if ("C".equals(checkGb)) {
- saveSetTypeCartInfo(params, cartSqList);
- }
- } else {
- for (Cart param : params) {
- param.setCustNo(login.getCustNo());
- // 상품 마스터 정보 확인
- Goods goods = new Goods();
- goods.setGoodsCd(param.getGoodsCd());
- goods.setFrontGb(TsfSession.getFrontGb());
- goods.setSiteCd(TscConstants.Site.STYLE24.value());
- goods = goodsService.getGoodsInfo(goods);
- // 신규 고객 주문 가능 상품 체크
- if("Y".equals(goods.getNewCustOrdYn())) {
- Goods tmp = new Goods();
- tmp.setCustNo(login.getCustNo());
- tmp.setGoodsCd(param.getGoodsCd());
- tmp = goodsDao.getNewCustOrdCanYnInfo(tmp);
- if("N".equals(tmp.getNewCustCanYn())) {
- newCustCanYn = "N";
- }
- }
- if (goods == null) {
- result.put("message", "상품 정보가 존재하지 않습니다.");
- return result;
- } else if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
- result.put("message", "품절입니다");
- return result;
- } else if (!TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat()) && !TscConstants.GoodsStat.APPR.value().equals(goods.getGoodsStat())) {
- result.put("message", "판매중인 상품이 아닙니다.");
- return result;
- } else if (param.getGoodsQty() > goods.getMaxOrdQty()) {
- result.put("message", goods.getGoodsNm() + " 상품의 최대 구매 수량은 " + goods.getMaxOrdQty() + " 입니다.");
- return result;
- } else if (param.getGoodsQty() < goods.getMinOrdQty()) {
- result.put("message", goods.getGoodsNm() + " 상품의 최소 구매 수량은 " + goods.getMinOrdQty() + " 입니다.");
- return result;
- }
- // 상품 구매 가능 등급 조회
- Collection<Goods> gradeList = goodsDao.getGoodsDetailOrderGradeList(goods);
- // 구매가능 등급이 없으면 전체 구매 가능
- if(gradeList != null && gradeList.size() > 0) {
- // 구매가능 등급이 존재하면 비회원은 구매 불가. 회원은 등급체크.
- if(login.getCustNo() > 0) {
- boolean chkGrade= false;
- for(Goods grade : gradeList) {
- if(grade.getCustGrade().equals(login.getCustGrade())) {
- chkGrade = true;
- }
- }
- // 구매가능 등급이 아니면 장바구니 등록 X
- if(!chkGrade) {
- result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
- return result;
- }
- } else {
- result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
- return result;
- }
- }
- // 상품 재고 확인
- GoodsStock checkParam = new GoodsStock();
- checkParam.setGoodsCd(param.getGoodsCd());
- checkParam.setItemCd(param.getItemCd());
- checkParam.setOptCd(param.getOptCd());
- checkParam.setGoodsQty(param.getGoodsQty());
- checkParam.setGoodsType(param.getGoodsType());
- String stockResult = goodsService.getCheckStock(checkParam);
- if (!"SUCCESS".equals(stockResult)) {
- result.put("message", stockResult);
- return result;
- }
- // 금일 주문 수량 체크
- if (!StringUtils.isEmpty(param.getCartGb()) && ("N".equals(param.getCartGb()) || "O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
- int goodsCartCnt = 0;
- if(param.getCustNo() != 0) {
- goodsCartCnt = cartDao.getGoodsTodayOrderCnt(param);
- }
- if (param.getGoodsQty() + goodsCartCnt > goods.getDayMaxOrdQty()) {
- result.put("message", "1일 구매한도 수량이 초과되었습니다.");
- return result;
- }
- }
- }
-
- // 2021.04.13 jsh77b 주문서에서 유효성 체크를 위해서 추가
- if ("C".equals(checkGb)) {
- saveNormalDealCartInfo(params, cartSqList);
- }
- }
- result.put("newCustCanYn", newCustCanYn);
- result.put("cartSqList", cartSqList);
- result.put("goodsType", goodsType);
- result.put("cartGb", cartGb);
- result.put("message", "SUCCESS");
- return result;
- }
- @Transactional("shopTxnManager")
- public void deleteOldCart() {
- Cart deleteCart = new Cart();
- if(TsfSession.isLogin()) {
- deleteCart.setCustNo(TsfSession.getInfo().getCustNo());
- } else {
- deleteCart.setCustNo(0);
- }
- deleteCart.setJsessionId(TsfSession.getSessionId());
- cartDao.deleteOldCart(deleteCart);
- cartDao.deleteCartDetailFromEmptyCart();
- }
- @Transactional("shopTxnManager")
- public void saveSetTypeCartInfo(Collection<Cart> params, List<Integer> cartSqs) {
- Cart cart = new Cart();
- StringBuilder sb = new StringBuilder();
- String cartGb = "";
- // 로그인 정보
- if(TsfSession.isLogin()) {
- Login login = TsfSession.getInfo();
- cart.setRegNo(login.getCustNo());
- cart.setCustNo(login.getCustNo());
- cart.setUpdNo(login.getCustNo());
- } else {
- cart.setCustNo(0);
- cart.setRegNo(0);
- cart.setUpdNo(0);
- }
- cart.setJsessionId(TscSession.getSessionId());
- boolean chkGoOrderForm = false;
- List<String> sendCartSqList = new ArrayList<String>();
- for (Cart carts : params) {
- int i = 1;
- // 장바구니 보유 CART_SQ 쿼리
- Collection<Cart> cartInfos = carts.getCartCompsList();
- sb = new StringBuilder();
- for(Cart param : cartInfos) {
- sb.append("SELECT CD.CART_SQ \n FROM TB_CART_DETAIL CD \n INNER JOIN TB_CART C \n ON CD.CART_SQ = C.CART_SQ \n WHERE C.CUST_NO = ");
- if (cart.getCustNo() == 0) {
- sb.append(cart.getCustNo()).append("\n AND JSESSION_ID = '").append(cart.getJsessionId()).append("'");
- } else {
- sb.append(cart.getCustNo());
- }
- sb.append("\n AND CD.ITEM_CD = '").append(param.getItemCd()).append("' \n AND CD.OPT_CD = '").append(param.getOptCd()).append("' AND C.CART_GB = 'G026_BC' ");
- if (i < cartInfos.size()) {
- i++;
- sb.append("\n UNION ALL \n");
- }
- }
- // cart 정보 세팅
- cart.setContentsLoc(cartInfos.iterator().next().getContentsLoc());
- cart.setAfLinkCd(cartInfos.iterator().next().getAfLinkCd());
- cart.setIthrCd(cartInfos.iterator().next().getIthrCd());
- cart.setPlanDtlSq(cartInfos.iterator().next().getPlanDtlSq());
- cart.setGoodsCd(cartInfos.iterator().next().getGoodsCd());
- cart.setGoodsQty(cartInfos.iterator().next().getGoodsQty());
- cart.setGoodsType(cartInfos.iterator().next().getGoodsType());
- cart.setItemCdSql(sb.toString());
- Collection<Cart> cartSqList = null;
- if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && "C".equals(cartInfos.iterator().next().getCartGb())) {
- cart.setCartGb(TscConstants.CartGb.CART.value());
- // 같은 장바구니 상품 확인
- cartSqList = cartDao.selectHasSetItemCartList(cart);
- } else if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && ("N".equals(cartInfos.iterator().next().getCartGb()) || "O".equals(cartInfos.iterator().next().getCartGb()))) {
- if ("P".equals(TsfSession.getFrontGb())) {
- cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
- } else {
- cart.setCartGb(TscConstants.CartGb.MOB_ORDER.value());
- }
- if("O".equals(cartInfos.iterator().next().getCartGb())) {
- chkGoOrderForm = true;
- }
- } else if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && "G".equals(cartInfos.iterator().next().getCartGb())) {
- chkGoOrderForm = true;
- cart.setCartGb(TscConstants.CartGb.GIFT.value());
- } else {
- cart.setCartGb(TscConstants.CartGb.CREATE_ORDER.value());
- }
- if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
- if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
- throw new IllegalStateException("장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
- } else {
- cart.setCartSq(cartSqList.iterator().next().getCartSq());
- cartSqs.add(cart.getCartSq());
- cartDao.updateCartInfo(cart); // 장바구니 정보 수정
- cartDao.insertCartHst(cart); // 장바구니 수정 이력 저장
- }
- } else {
- cartDao.insertCartInfo(cart); // 장바구니 마스터 정보 저장
- cartDao.insertCartHst(cart); // 장바구니 이력 정보 저장
- cartSqs.add(cart.getCartSq());
- sendCartSqList.add(cart.getCartSq() + "");
- for (Cart param : cartInfos) {
- param.setCartSq(cart.getCartSq());
- param.setRegNo(cart.getRegNo());
- param.setCustNo(cart.getCustNo());
- param.setUpdNo(cart.getUpdNo());
- cartDao.insertCartDetailInfo(param); // 장바구니 상세 저장
- cartDao.insertCartDetailHst(param); // 장바구니 상세 이력 저장
- }
- }
- }
- // 상품상세 > 바로구매 로그인 후 구매 클릭시 주문서로 송부할 장바구니번호
- StringBuilder cartSqComma = new StringBuilder();
- int i = 0;
- for(String cartSq : sendCartSqList) {
- if(i > 0) {
- cartSqComma.append(",");
- }
- cartSqComma.append(cartSq);
- i++;
- }
- if(chkGoOrderForm) {
- TsfSession.setAttribute("cartSqArr", cartSqComma.toString());
- }
- }
- @Transactional("shopTxnManager")
- public void saveNormalDealCartInfo(Collection<Cart> params, List<Integer> cartSqs) {
- Cart cart = new Cart();
- // 로그인 정보
- if(TsfSession.isLogin()) {
- Login login = TsfSession.getInfo();
- cart.setCustNo(login.getCustNo());
- } else {
- cart.setCustNo(0);
- }
- cart.setJsessionId(TscSession.getSessionId());
- if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "C".equals(params.iterator().next().getCartGb())) {
- cart.setCartGb(TscConstants.CartGb.CART.value());
- } else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && ("N".equals(params.iterator().next().getCartGb()) || "O".equals(params.iterator().next().getCartGb()))) {
- if ("P".equals(TsfSession.getFrontGb())) {
- cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
- } else {
- cart.setCartGb(TscConstants.CartGb.MOB_ORDER.value());
- }
- } else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "G".equals(params.iterator().next().getCartGb())) {
- cart.setCartGb(TscConstants.CartGb.GIFT.value());
- } else {
- cart.setCartGb(TscConstants.CartGb.CREATE_ORDER.value());
- }
- // 세션 추가용 변수
- String cartGb = params.iterator().next().getCartGb();
- List<String> sendCartSqList = new ArrayList<String>();
- for(Cart item : params) {
- item.setCartGb(cart.getCartGb());
- item.setCustNo(cart.getCustNo());
- item.setRegNo(cart.getCustNo());
- item.setUpdNo(cart.getCustNo());
- item.setJsessionId(cart.getJsessionId());
- // 같은 장바구니 상품 확인
- Collection<Integer> cartSqList = null;
- if(TscConstants.CartGb.CART.value().equals(cart.getCartGb())) {
- cartSqList = cartDao.selectHasNormalDealItemCartList(item);
- }
- if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
- if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
- throw new IllegalStateException("장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
- } else {
- item.setCartSq(cartSqList.iterator().next());
- cartSqs.add(item.getCartSq());
- cartDao.updateCartInfo(item);
- cartDao.insertCartHst(item); // 장바구니 수정 이력 저장
- }
- } else {
- cartDao.insertCartInfo(item); // 장바구니 마스터 정보 저장
- cartDao.insertCartHst(item); // 장바구니 수정 이력 저장
- cartDao.insertCartDetailInfo(item); // 장바구니 상세 저장
- cartDao.insertCartDetailHst(item); // 장바구니 수정 이력 저장
- cartSqs.add(item.getCartSq());
- sendCartSqList.add(item.getCartSq() + "");
- }
- }
- StringBuilder cartSqComma = new StringBuilder();
- int i = 0;
- for(String cartSq : sendCartSqList) {
- if(i > 0) {
- cartSqComma.append(",");
- }
- cartSqComma.append(cartSq);
- i++;
- }
- if (!StringUtils.isEmpty(cartGb) && ("O".equals(cartGb) || "G".equals(cartGb))) {
- TsfSession.setAttribute("cartSqArr", cartSqComma.toString());
- }
- }
- // 장바구니 상품 리스트 조회 서비스
- @SuppressWarnings("unchecked")
- public Order getCartGoodsList(Order order) {
- //ModelAndView result = new ModelAndView();
- GagaMap result = new GagaMap(); // return
- List<Integer> cartSqs = new ArrayList<Integer>(); // 품절 제외 장바구니 리스트
- // 로그인 체크
- if(TsfSession.isLogin()) {
- order.setCustNo(TsfSession.getInfo().getCustNo());
- } else {
- order.setCustNo(0);
- }
- order.setFrontGb(TsfSession.getFrontGb());
- order.setJsessionId(TscSession.getSessionId());
- // 장바구니 상품 조회
- Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);
- // 품절 아닌 상품만 체크
- for (Order goods : cartGoodsList) {
- if ("N".equals(goods.getSoldoutYn()) && "Y".equals(goods.getOrdCanYn()) && "Y".equals(goods.getNewCustCanYn()) && goods.getGoodsQty() >= goods.getMinOrdQty() && goods.getGoodsQty() <= goods.getMaxOrdQty()) {
- cartSqs.add(goods.getCartSq());
- }
- goods.setOrgSavePntAmt((int) (goods.getCurrPrice() * goods.getPntRate() / 100.0));
- }
- order.setCartSqArr(cartSqs.stream().mapToInt(Integer::intValue).toArray());
- if(cartSqs.size() > 0) {
- // 다다익선 할인 상품 조회 (품절 상품 제외)
- Collection<Order> moreBetterAmtList = new ArrayList<Order>();
- //if(order.getCustNo() > 0) { // 비회원도 다다익선 적용 여부 및 금액 노출되도록 수정. (한수인리더 요청) :: 20210517
- order.setCartYn("Y");
- moreBetterAmtList = getMoreBetterAmtList(order);
- //}
- // 다다익선 할인 정보 및 상품 정보 장바구니에 등록
- for (Order cart : cartGoodsList) {
- for (Order info : moreBetterAmtList) {
- if (cart.getCartSq().equals(info.getCartSq())) {
- cart.setTmtbDcAmt(info.getTmtbDcAmt());
- cart.setApplyAmtSectionYn(info.getApplyAmtSectionYn());
- cart.setApplyQtySectionYn(info.getApplyQtySectionYn());
- cart.setQtyTmtbNm(info.getQtyTmtbNm());
- cart.setAmtTmtbNm(info.getAmtTmtbNm());
- cart.setQtyTmtbSq(info.getQtyTmtbSq());
- cart.setAmtTmtbSq(info.getAmtTmtbSq());
- }
- }
- if (cart.getTmtbDcAmt() == 0) {
- cart.setTmtbDcAmt(cart.getCurrPrice());
- }
- if(cart.getPntRate() > 0) {
- cart.setSavePntAmt((int) (cart.getTmtbDcAmt() * cart.getPntRate() / 100.0));
- } else {
- cart.setSavePntAmt(0);
- }
- }
- }
- // 자사 / 입점업체 리스트 분리
- order = getCartDelvGoodsCntList(cartGoodsList, order);
- // 장바구니 업체별 배송비 계산
- setCartListDelvFeeInfo(cartGoodsList, order);
- // 총계 금액 계산
- setCartListTotAmtInfo(cartGoodsList, order);
- // 전체 장바구니 정보
- order.setDelvAllCartList(cartGoodsList);
- order.setAllCartCnt(cartGoodsList.size());
- return order;
- }
- // 장바구니 수량 계산(품절제거)
- @SuppressWarnings("unchecked")
- public Order getCartNotSoldoutCnt() {
- Order order = new Order();
- //ModelAndView result = new ModelAndView();
- GagaMap result = new GagaMap(); // return
- List<Integer> cartSqs = new ArrayList<Integer>(); // 품절 제외 장바구니 리스트
- // 로그인 체크
- if(TsfSession.isLogin()) {
- order.setCustNo(TsfSession.getInfo().getCustNo());
- } else {
- order.setCustNo(0);
- }
- order.setFrontGb(TsfSession.getFrontGb());
- order.setJsessionId(TscSession.getSessionId());
- // 장바구니 상품 조회
- Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);
- // 총계 금액 계산 (수량 계산 내부에 존재)
- setCartListTotAmtInfo(cartGoodsList, order);
- return order;
- }
- /**
- * 다다익선 할인 금액 조회
- * @param param
- * param.cartSqArr[] : 필수
- * @return String
- * @author xodud1202
- * @since 2021. 01. 28
- */
- public Collection<Order> getMoreBetterAmtList(Order param) {
- // 장바구니 상품 조회
- param.setFrontGb(TsfSession.getFrontGb());
- Collection<Order> cartGoodsList = coreOrderService.getCartGoodsList(param);
- String cartYn = "N";
- if(!StringUtils.isEmpty(param.getCartYn())) {
- cartYn = param.getCartYn();
- }
- if(param.getCustNo() > 0 || "Y".equals(cartYn)) {
- // 장바구니 내 수량 다다익선 적용 가능 리스트 조회 (등록된 기본,적용 상품 정보 전체 조회)
- Collection<Order> tmtbApplyList = cartDao.selectMoreBetterApplyCartList(param);
- // 장바구니 등록 다다익선 일련번호 지정
- List<Integer> applySq = new ArrayList<Integer>();
- for(Order tmtbApply : tmtbApplyList) {
- if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb()) || TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
- if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb())) {
- applySq.add(tmtbApply.getQtyTmtbSq());
- }
- if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
- applySq.add(tmtbApply.getAmtTmtbSq());
- }
- }
- }
- param.setTmtbSqs(applySq.stream().mapToInt(Integer::intValue).toArray());
- // 섹션 정보 조회 후 할인 여부 판단
- Collection<Order> tmtbSectionList = cartDao.selectTmtbSectionValList(applySq);
- for(Order applyInfo : tmtbApplyList) { // 기준 상품 및 다다익선 정보 조회
- // 다다익선 할인 조건 조회
- for(Order section : tmtbSectionList) {
- if(applyInfo.getQtyTmtbSq() == section.getTmtbSq()) {
- // 수량 적용 다다익선
- if (section.getSectionVal() <= applyInfo.getQtyTmtbSumQty()) { // 장바구니 수량 할인 기준 달성시
- if (applyInfo.getQtySectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
- applyInfo.setQtySectionVal(section.getSectionVal());
- applyInfo.setApplyQtySectionYn("Y");
- applyInfo.setQtyDcWay(section.getDcWay());
- applyInfo.setQtyDcVal(section.getDcVal());
- }
- } else {
- if (applyInfo.getQtySectionVal() < 1 && applyInfo.getQtyGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
- applyInfo.setApplyQtySectionYn("N");
- }
- }
- }
- if (applyInfo.getAmtTmtbSq() == section.getTmtbSq()) {
- // 금액 적용 다다익선
- if(section.getSectionVal() <= applyInfo.getAmtTmtbSumAmt()) { // 장바구니 수량 할인 기준 달성시
- if(applyInfo.getAmtSectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
- applyInfo.setAmtSectionVal(section.getSectionVal());
- applyInfo.setApplyAmtSectionYn("Y");
- applyInfo.setAmtDcWay(section.getDcWay());
- applyInfo.setAmtDcVal(section.getDcVal());
- }
- } else {
- if(applyInfo.getAmtSectionVal() < 1 && applyInfo.getAmtGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
- applyInfo.setApplyAmtSectionYn("N");
- }
- }
- }
- }
- }
- // 수량 다다익선에 맞춰 정렬
- Collections.sort((ArrayList<Order>) tmtbApplyList, new Comparator<Order>() {
- @Override
- public int compare(Order c1, Order c2) {
- return c1.getQtyTmtbSq() - c2.getQtyTmtbSq();
- }
- });
- // 수량 다다익선 적용 상품 할인 금액 계산
- int leftAmt = 0;
- int i = 0;
- for(Order resultAmt : tmtbApplyList) {
- int tempAmt = 0;
- if("Y".equals(resultAmt.getApplyQtySectionYn()) && resultAmt.getQtyTmtbSq() > 0) {
- if (TscConstants.DcWay.AMT.value().equals(resultAmt.getQtyDcWay())) { // 할인 방식 금액일경우
- i++;
- tempAmt = resultAmt.getCurrPrice();
- if (i == 1) {
- leftAmt = resultAmt.getQtyDcVal();
- }
- if (i == resultAmt.getQtyTmtbCnt()) {
- resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
- resultAmt.setTmtb1DcAmt(leftAmt); // tmtb1 할인금액
- leftAmt = 0;
- i = 0;
- } else {
- double tempDcAmt = resultAmt.getQtyDcVal() * ((tempAmt) / (double)resultAmt.getQtyTmtbSumAmt());
- leftAmt -= (int)tempDcAmt;
- resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
- resultAmt.setTmtb1DcAmt((int)tempDcAmt); // tmtb1 할인금액
- }
- } else { // 할인 방식 할인율일 경우
- tempAmt = resultAmt.getCurrPrice();
- tempAmt = (tempAmt - (int) (tempAmt * (resultAmt.getQtyDcVal() / 100.0)));
- resultAmt.setTmtbDcAmt(tempAmt);
- // 2021.04.29 다다익선할인금액수정
- resultAmt.setTmtb1DcAmt((int) (resultAmt.getCurrPrice() * (resultAmt.getQtyDcVal() / 100.0))); // tmtb1 할인금액
- }
- }
- if (resultAmt.getTmtbDcAmt() > 0) {
- resultAmt.setCurrPrice(resultAmt.getTmtbDcAmt());
- }
- }
- // 금액 다다익선에 맞춰 정렬
- Collections.sort((ArrayList<Order>) tmtbApplyList, new Comparator<Order>() {
- @Override
- public int compare(Order c1, Order c2) {
- return c1.getAmtTmtbSq() - c2.getAmtTmtbSq();
- }
- });
- // 금액 다다익선 할인 계산
- leftAmt = 0;
- i = 0;
- for(Order resultAmt : tmtbApplyList) {
- int tempAmt = 0;
- if("Y".equals(resultAmt.getApplyAmtSectionYn()) && resultAmt.getAmtTmtbSq() > 0) {
- if (TscConstants.DcWay.AMT.value().equals(resultAmt.getAmtDcWay())) { // 할인 방식 금액일경우
- i++;
- tempAmt = resultAmt.getCurrPrice();
- if (i == 1) {
- leftAmt = resultAmt.getAmtDcVal();
- }
- if (i == resultAmt.getAmtTmtbCnt()) {
- resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
- resultAmt.setTmtb2DcAmt(leftAmt); // tmtb1 할인금액
- leftAmt = 0;
- i = 0;
- } else {
- double tempDcAmt = resultAmt.getAmtDcVal() * ((tempAmt) / (double)resultAmt.getAmtTmtbSumAmt());
- leftAmt -= (int)tempDcAmt;
- resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
- resultAmt.setTmtb2DcAmt((int)tempDcAmt); // tmtb1 할인금액
- }
- } else { // 할인 방식 할인율일 경우
- tempAmt = resultAmt.getCurrPrice();
- tempAmt = (tempAmt - (int) (tempAmt * (resultAmt.getAmtDcVal() / 100.0)));
- resultAmt.setTmtbDcAmt(tempAmt);
- // 2021.04.29 다다익선할인금액수정
- resultAmt.setTmtb2DcAmt((int) (resultAmt.getCurrPrice() * (resultAmt.getAmtDcVal() / 100.0))); // tmtb2 할인금액
- }
- }
- }
- // 장바구니 정보에 수량 다다익선 정보 입력
- for (Order cart : cartGoodsList) {
- for (Order apply : tmtbApplyList) {
- if (cart.getCartSq().equals(apply.getCartSq())) {
- // 2021.02.24 jsh77b
- cart.setTmtb1DcAmt(apply.getTmtb1DcAmt());
- cart.setTmtb2DcAmt(apply.getTmtb2DcAmt());
- cart.setTmtbDcAmt(apply.getTmtbDcAmt());
-
- log.info("cart.getTmtb1DcAmt() ::: {}", cart.getTmtb1DcAmt());
- log.info("cart.getTmtb2DcAmt() ::: {}", cart.getTmtb2DcAmt());
- log.info("cart.getTmtbDcAmt() ::: {}", cart.getTmtbDcAmt());
-
- cart.setApplyQtySectionYn(apply.getApplyQtySectionYn());
- cart.setQtyTmtbNm(apply.getQtyTmtbNm());
- cart.setQtyTmtbSq(apply.getQtyTmtbSq());
- cart.setApplyAmtSectionYn(apply.getApplyAmtSectionYn());
- cart.setAmtTmtbNm(apply.getAmtTmtbNm());
- cart.setAmtTmtbSq(apply.getAmtTmtbSq());
- }
- }
- }
- }
- //return result;
- return cartGoodsList;
- }
- /**
- * 장바구니 배송단위별 상품 정보 조회
- *
- * @param cartGoodsList
- * @author xodud1202
- * @since 2021. 02. 02
- */
- public Order getCartDelvGoodsCntList(Collection<Order> cartGoodsList, Order paramOrder) {
- // 1. 장바구니 상품 배송단위별 건수 체크 로직 (자사:총알배송, 자사:일반배송, 입점업체, 예약배송)
- Order delvOrder = new Order();
- Collection<Order> shotCartList = new ArrayList<Order>();
- Collection<Order> wmsCartList = new ArrayList<Order>();
- Collection<Order> delvCartList = new ArrayList<Order>();
- for (Order order : cartGoodsList) {
- // 1.1 세트상품 옵션별 배열로 담기
- if (order.getItemNm().contains("!@!")) {
- order.setItemNmArr(order.getItemNm().split("!@!"));
- order.setOptCdArr(order.getOptCd().split(","));
- order.setItemQtyArr(order.getItemQtyr().split(","));
- order.setOptCd1Arr(order.getOptCd1().split(","));
- order.setOptCd2Arr(order.getOptCd2().split(","));
- order.setColorNmArr(order.getColorNm().split(","));
- } else {
- String[] arr = {order.getItemNm()}, arr2 = {order.getOptCd1()}, arr3 = {order.getOptCd2()}, arr4 = {order.getItemQtyr()}, arr5 = {order.getColorNm()};
- order.setItemNmArr(arr);
- order.setOptCd1Arr(arr2);
- order.setOptCd2Arr(arr3);
- order.setItemQtyArr(arr4);
- order.setColorNmArr(arr5);
- }
- // 1.3 배송정책별 상품 구분
- if ("SHOT".equals(order.getCartDelvFeeCd())) {
- if(paramOrder.getShotDelvUseYn() != null && "N".equals(paramOrder.getShotDelvUseYn())) {
- wmsCartList.add(order);
- } else {
- shotCartList.add(order);
- }
- } else if ("WMS".equals(order.getCartDelvFeeCd())) {
- wmsCartList.add(order);
- } else {
- delvCartList.add(order);
- }
- }
- delvOrder.setShotCartList(shotCartList); // 자사 총알배송 상품 목록
- delvOrder.setWmsCartList(wmsCartList); // 자사 일반상품 목록
- delvOrder.setDelvCartList(delvCartList); // 입점 업체 상품 목록
- return delvOrder;
- }
- /**
- * 장바구니 배송단위별 배송비 계산
- *
- * @param params
- * @author xodud1202
- * @since 2021. 02. 02
- */
- public void setCartListDelvFeeInfo(Collection<Order> params, Order order) {
- Order delvInfo = new Order();
- List<Integer> cartSqArr = new ArrayList<Integer>();
- // 장바구니 일련번호 세팅
- for (Order param : params) {
- cartSqArr.add(param.getCartSq());
- }
- delvInfo.setCartSqArr(cartSqArr.stream().mapToInt(Integer::intValue).toArray());
- // 장바구니 업체별 배송비 정보 조회
- Collection<Order> delvFeeInfo = new ArrayList<Order>();
- if(delvInfo.getCartSqArr() != null && delvInfo.getCartSqArr().length > 0) {
- delvFeeInfo = cartDao.getCartListDelvFeeInfoList(delvInfo);
- }
- // 업체별 상품 합계 금액 저장
- int compCnt = 0;
- String delvYn;
- Order lastCompCheck = new Order();
- for (Order delv : delvFeeInfo) {
- lastCompCheck = null;
- compCnt = 0;
- delvYn = "N";
- for (Order param : params) {
- if (param.getDelvFeeCd().equals(delv.getDelvFeeCd())) {
- compCnt++;
- if("N".equals(param.getSoldoutYn()) && "Y".equals(param.getOrdCanYn()) && "Y".equals(param.getNewCustCanYn()) && param.getGoodsQty() >= param.getMinOrdQty() && param.getGoodsQty() <= param.getMaxOrdQty()) {
- delv.setCompSumPrice(delv.getCompSumPrice() + param.getCurrPrice());
- delvYn = "Y";
- }
- if (compCnt == 1) {
- param.setFirstCompYn("Y");
- }
- // 한 업체의 마지막 params를 확인
- lastCompCheck = param;
- }
- }
- if(lastCompCheck != null) {
- // 한 업체의 마지막 상품 체크
- lastCompCheck.setAddDelvFeeYn("Y");
- // 배송 상품 존재 여부
- lastCompCheck.setDelvYn(delvYn);
- // 배송상품 금액차이
- }
- }
- int wmsSumPrice = 0, wmsMinOrdAmt = 0, wmsDelvFee = 0;
- // 장바구니 업체별 합계 금액으로 무료배송 여부 저장
- for (Order param : params) {
- // 입점업체 배송비
- for (Order delv : delvFeeInfo) {
- if (param.getDelvFeeCd().equals(delv.getDelvFeeCd()) && !"WMS".equals(param.getDelvFeeCd())) {
- param.setCompCnt(delv.getCompCnt());
- param.setDelvFeeCrite(delv.getDelvFeeCrite());
- if (TscConstants.DelvFeeCrite.FREE.value().equals(delv.getDelvFeeCrite())) {
- param.setDelvFee(0);
- } else if (TscConstants.DelvFeeCrite.NORMAL.value().equals(delv.getDelvFeeCrite()) && delv.getCompSumPrice() > delv.getMinOrdAmt()) {
- param.setDelvFee(0);
- } else {
- param.setCompSumPrice(delv.getCompSumPrice());
- param.setMinOrdAmt(delv.getMinOrdAmt());
- param.setDelvFee(delv.getDelvFee());
- }
- }
- }
- // 자사 상품 가격 계산
- if("WMS".equals(param.getDelvFeeCd())) {
- if("N".equals(param.getSoldoutYn()) && "Y".equals(param.getOrdCanYn())&& "Y".equals(param.getNewCustCanYn()) && param.getGoodsQty() >= param.getMinOrdQty() && param.getGoodsQty() <= param.getMaxOrdQty()) {
- wmsSumPrice = wmsSumPrice + param.getCurrPrice();
- wmsMinOrdAmt = param.getMinOrdAmt();
- wmsDelvFee = param.getDelvFee();
- }
- }
- }
- // 자사 배송비 등록
- if(params.size() > 0) {
- if (wmsSumPrice > wmsMinOrdAmt) {
- order.setWmsDelvFee(0);
- } else {
- order.setWmsDelvFee(wmsDelvFee);
- order.setCompSumPrice(wmsSumPrice);
- order.setMinOrdAmt(wmsMinOrdAmt);
- }
- // 배송 상품 존재 여부
- if(wmsSumPrice > 0) {
- order.setDelvYn("Y");
- }
- }
- }
- /**
- * 장바구니 배송비 합계금액 계산
- * @param cartGoodsList
- * @param order
- * @author xodud1202
- * @since 2021. 02. 02
- */
- public void setCartListTotAmtInfo(Collection<Order> cartGoodsList, Order order) {
- // 장바구니 합계 금액 계산
- int notSoldoutCnt = 0;
- for(Order cart : cartGoodsList) {
- if("N".equals(cart.getSoldoutYn()) && "Y".equals(cart.getOrdCanYn()) && "Y".equals(cart.getNewCustCanYn()) && cart.getGoodsQty() >= cart.getMinOrdQty() && cart.getGoodsQty() <= cart.getMaxOrdQty()) {
- notSoldoutCnt++;
- // 상품 금액 합계
- order.setSumOrdAmt(order.getSumOrdAmt() + cart.getCurrPrice());
- order.setSumRealPayAmt(order.getSumRealPayAmt() + cart.getTmtbDcAmt());
- order.setSumListPrice(order.getSumListPrice() + cart.getListPrice());
- // 배송비 합계
- if ("Y".equals(cart.getFirstCompYn())) {
- order.setTotDelvFee(order.getTotDelvFee() + cart.getDelvFee());
- }
- }
- }
- // 자사 배송비 추가
- order.setTotDelvFee(order.getTotDelvFee() + order.getWmsDelvFee());
- // 상품 할인금액 총계
- // order.setTotDcAmt(order.getSumRealPayAmt() - order.getSumOrdAmt()); /* 다다익선 금액이 상품금액일 경우 해당 주석 제거 */
- order.setTotDcAmt(order.getSumRealPayAmt() - order.getSumListPrice());
- // 장바구니 총액 계산 상품 총 수량
- order.setTotCartCnt(notSoldoutCnt);
- order.setCartGoodsList(cartGoodsList);
- }
- @Transactional("shopTxnManager")
- public void deleteCart(Cart param) {
- cartDao.deleteCart(param);
- }
- /**
- * 로그인 후 장바구니 Update
- * 회원 로그인 후 호출됨으로 세션 정보 있음
- * @param custNo - 고객번호
- * @author gagamel
- * @since 2021. 2. 24
- */
- @Transactional("shopTxnManager")
- public void updateCartToAfterLogin(Integer custNo) {
- Cart cart = new Cart();
- cart.setJsessionId(TsfSession.getSessionId());
- cart.setCustNo(custNo);
- cart.setUpdNo(custNo);
- log.info("cart: {}", cart);
- // 로그인 후 고객번호 Update
- int procCnt = cartDao.updateCartOfCustNo(cart);
- if (procCnt > 0) {
- // 로그인 후 처리할 장바구니 목록
- Collection<Cart> cartList = cartDao.getCartListAfterLogin(cart);
- for (Cart updCart : cartList) {
- updCart.setCustNo(custNo);
- updCart.setRegNo(custNo);
- // 로그인 후 장바구니 수정
- cartDao.updateCartAfterLogin(updCart);
- // 로그인 후 장바구니단품 삭제
- cartDao.deleteCartItemAfterLogin(updCart);
- // 로그인 후 장바구니 삭제
- cartDao.deleteCartAfterLogin(updCart);
- // 로그인 후 장바구니 이력 생성(삭제할 장바구니번호가 있을 때만)
- if (updCart.getDelCartSq() > 0) {
- cartDao.createCartHistoryAfterLogin(updCart);
- }
- }
- }
- }
- public Collection<Goods> getDelvFeeSaveGoodsList(Order param) {
- Goods goods = new Goods();
- if(StringUtils.isEmpty(param.getDelvFeeCd())) {
- return null;
- }
- if("WMS".equals(param.getDelvFeeCd())) {
- goods.setSelfGoodsYn("Y");
- } else {
- goods.setDelvFeeCd(param.getDelvFeeCd());
- }
- goods.setPrice(param.getDelvFeeSaveGoodsAmt());
- goods.setFrontGb(TsfSession.getFrontGb());
- if(TsfSession.isLogin()) {
- goods.setCustNo(TsfSession.getInfo().getCustNo());
- } else {
- goods.setCustNo(0);
- }
- return goodsDao.getDelvFeeSaveGoodsList(goods);
- }
- public Cart getCartGoodsInfo(Cart param) {
- // 장바구니 상품 마스터 정보 조회
- param.setFrontGb(TsfSession.getFrontGb());
- Cart cart = cartDao.selectCartGoodsInfo(param);
- if(cart == null) {
- throw new IllegalStateException("장바구니 상품 정보가 없습니다.\n새로고침 후 다시 시도해주세요.");
- }
- if(TscConstants.GoodsStat.SOLDOUT.value().equals(cart.getGoodsStat())) {
- cart.setSoldoutYn("Y");
- } else {
- cart.setSoldoutYn("N");
- }
- // 세트 상품일 경우
- if(TscConstants.GoodsType.SET.value().equals(cart.getGoodsType())) {
- cart.setCartCompsList(cartDao.selectCartSetGoodsInfo(cart));
- for(Cart comp : cart.getCartCompsList()) {
- comp.setCartSq(cart.getCartSq());
- comp.setCartColorList(cartDao.selectCartGoodsColorList(comp));
- if("Y".equals(cart.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(comp.getGoodsStat())) {
- comp.setSoldoutYn("Y");
- } else {
- comp.setSoldoutYn("N");
- }
- for(Cart color : comp.getCartColorList()) {
- if("Y".equals(comp.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(color.getGoodsStat())) {
- color.setSoldoutYn("Y");
- } else {
- color.setSoldoutYn("N");
- }
- color.setCartSq(comp.getCartSq());
- color.setCartSizeList(cartDao.selectCartGoodsSizeList(color));
- }
- }
- cart.setCartImgList(cartDao.selectCartDelvGoodsOptionImgList(cart)); // TB_GOODS.MAIN_COLOR_CD의 이미지를 가져옴.
- } else { // 일반, DEAL 상품일 경우
- cart.setCartCompsList(new ArrayList<Cart>());
- cart.getCartCompsList().add(new Cart());
- for(Cart comp : cart.getCartCompsList()) {
- comp.setSoldoutYn(cart.getSoldoutYn());
- comp.setCartColorList(cartDao.selectCartGoodsColorList(cart));
- for(Cart color : comp.getCartColorList()) {
- if("Y".equals(comp.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(color.getGoodsStat())) {
- color.setSoldoutYn("Y");
- } else {
- color.setSoldoutYn("N");
- }
- if(color.getCartDtlSq() > 0) {
- comp.setCartDtlSq(color.getCartDtlSq());
- comp.setColorNm(color.getCartColorNm());
- comp.setOptCd1(color.getOptCd1());
- comp.setGoodsCd(cart.getGoodsCd());
- }
- color.setCartSq(cart.getCartSq());
- color.setCartImgList(cartDao.selectCartSelfGoodsOptionImgList(color));
- color.setCartSizeList(cartDao.selectCartGoodsSizeList(color));
- for(Cart size : color.getCartSizeList()) {
- if(size.getCartDtlSq() > 0) {
- comp.setOptCd(size.getCartOptCd());
- comp.setOptCd2(size.getCartOptCd2());
- }
- }
- }
- }
- if(!"Y".equals(cart.getSelfGoodsYn())) { // 입점 상품은 TB_GOODS_IMG.COLOR_CD = TB_GOODS.MAIN_COLOR_CD
- cart.setCartImgList(cartDao.selectCartDelvGoodsOptionImgList(cart));
- }
- }
- cart.setImgPath(env.getProperty("upload.goods.view"));
- return cart;
- }
- @Transactional("shopTxnManager")
- public GagaMap updateCartOption(Cart param) {
- GagaMap result = new GagaMap();
- param.setJsessionId(TsfSession.getSessionId());
- param.setFrontGb(TsfSession.getFrontGb());
- if(TsfSession.isLogin()) {
- param.setCustNo(TsfSession.getInfo().getCustNo());
- param.setRegNo(param.getCustNo());
- param.setUpdNo(param.getCustNo());
- } else {
- param.setCustNo(0);
- param.setRegNo(0);
- param.setUpdNo(0);
- }
- // 재고 체크
- Goods goods = new Goods();
- goods.setGoodsCd(param.getGoodsCd());
- goods.setFrontGb(TsfSession.getFrontGb());
- goods.setSiteCd(TscConstants.Site.STYLE24.value());
- goods = goodsService.getGoodsInfo(goods);
- if (goods == null) {
- result.put("status", "FAIL");
- result.put("message", "상품 정보가 존재하지 않습니다.");
- return result;
- }
- if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
- result.put("status", "FAIL");
- result.put("message", "품절입니다.");
- return result;
- }
- // 구성 상품 재고 확인
- for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
- // 상품 재고 확인
- GoodsStock checkParam = new GoodsStock();
- checkParam.setGoodsCd(param.getGoodsCd());
- checkParam.setItemCd(param.getItemCds()[i]);
- checkParam.setOptCd(param.getOptCds()[i]);
- checkParam.setGoodsQty(param.getGoodsQty());
- checkParam.setGoodsType(param.getGoodsType());
- String stockResult = goodsService.getCheckStock(checkParam);
- if (!"SUCCESS".equals(stockResult)) {
- result.put("status", "FAIL");
- result.put("message", stockResult);
- return result;
- }
- }
- // 각 구성상품의 품절 여부 체크 후 최소, 최대 상품 수량 체크
- if (goods.getMinOrdQty() > param.getGoodsQty()) {
- result.put("status", "FAIL");
- result.put("message", "해당 상품의 최소 주문 수량은 " + goods.getMinOrdQty() + "개 입니다.");
- return result;
- } else if (goods.getMaxOrdQty() < param.getGoodsQty()) {
- result.put("status", "FAIL");
- result.put("message", "해당 상품의 최대 주문 수량은 " + goods.getMaxOrdQty() + "개 입니다.");
- return result;
- }
- StringBuilder sb = new StringBuilder();
- if(TscConstants.GoodsType.SET.value().equals(param.getGoodsType())) {
- // 장바구니 보유 CART_SQ 쿼리
- for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
- sb.append("SELECT CD.CART_SQ \n FROM TB_CART C \n INNER JOIN TB_CART_DETAIL CD \n ON C.CART_SQ = CD.CART_SQ \n WHERE C.CUST_NO = ");
- if (param.getCustNo() == 0) {
- sb.append(param.getCustNo()).append("\n AND JSESSION_ID = '").append(param.getJsessionId()).append("'");
- } else {
- sb.append(param.getCustNo());
- }
- sb.append("\n AND CD.ITEM_CD = '").append(param.getItemCds()[i]).append("' \n AND CD.OPT_CD = '").append(param.getOptCds()[i]).append("' AND C.CART_GB = 'G026_BC' ");
- if (i < param.getCartDtlSqArr().length - 1) {
- sb.append("\n UNION ALL \n");
- }
- }
- param.setItemCdSql(sb.toString());
- param.setCartGb(TscConstants.CartGb.CART.value());
- // 장바구니내 같은 상품 확인
- param.setNotCartSq(param.getCartSq()); // 수정 장바구니 번호 제외
- Collection<Cart> cartList = cartDao.selectHasSetItemCartList(param);
- // 동일 상품 존재시
- if (cartList != null && cartList.size() > 0) { // 장바구니 기존재
- if (cartList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
- result.put("status", "FAIL");
- result.put("message", "장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
- return result;
- } else {
- // 기존 존재 장바구니 UPDATE
- Cart cart = new Cart();
- cart.setCartSq(cartList.iterator().next().getCartSq());
- cart.setGoodsQty(param.getGoodsQty());
- cart.setAfLinkCd(param.getAfLinkCd());
- cart.setIthrCd(param.getIthrCd());
- cart.setContentsLoc(param.getContentsLoc());
- cart.setPlanDtlSq(param.getPlanDtlSq());
- cart.setUpdNo(param.getUpdNo());
- cart.setGoodsCd(param.getGoodsCd());
- cart.setCustNo(param.getCustNo());
- cart.setRegNo(param.getRegNo());
- cartDao.updateCartInfo(cart); // 장바구니 정보 수정
- cartDao.insertCartHst(cart); // 장바구니 수정 이력 저장
- // 장바구니 삭제
- int[] cartSqArr = {param.getCartSq()};
- param.setCartSqArr(cartSqArr);
- cartDao.deleteCart(param);
- cartDao.deleteCartDetail(param);
- }
- } else { // 동일 상품 없을 시 UPDATE
- cartDao.updateCartGoodsQty(param); // 장바구니 마스터 정보 저장
- cartDao.insertCartHst(param); // 장바구니 이력 정보 저장
- for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
- param.setItemCd(param.getItemCds()[i]);
- param.setCartDtlSq(param.getCartDtlSqArr()[i]);
- param.setOptCd(param.getOptCds()[i]);
- cartDao.updateCartDetail(param); // 장바구니 상세 저장
- cartDao.insertCartDetailHst(param); // 장바구니 상세 이력 저장
- }
- }
- } else {
- param.setCartGb(TscConstants.CartGb.CART.value());
- param.setNotCartSq(param.getCartSq()); // 수정 장바구니 번호 제외
- param.setOptCd(param.getOptCds()[0]);
- Collection<Integer> cartSqList = cartDao.selectHasNormalDealItemCartList(param);
- if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
- if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
- result.put("status", "FAIL");
- result.put("message", "장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
- return result;
- } else {
- param.setCartSq(cartSqList.iterator().next());
- cartDao.updateCartInfo(param); // 장바구니 기존 데이터에 UPDATE(수량증가)
- cartDao.insertCartHst(param); // 장바구니 수정 이력 저장
- // 이전 장바구니에 수정되었으므로 현재 수정된 장바구니 데이터 삭제
- int[] delCartSq = {param.getNotCartSq()};
- param.setCartSqArr(delCartSq);
- cartDao.deleteCart(param); // 현재 장바구니 삭제
- cartDao.deleteCartDetail(param); // 현재 장바구니 삭제
- }
- } else {
- cartDao.updateCartGoodsQty(param); // 장바구니 마스터 정보 저장
- cartDao.insertCartHst(param); // 장바구니 수정 이력 저장
- param.setItemCd(param.getItemCds()[0]);
- param.setCartDtlSq(param.getCartDtlSqArr()[0]);
- param.setOptCd(param.getOptCds()[0]);
- cartDao.updateCartDetail(param); // 장바구니 상세 저장
- cartDao.insertCartDetailHst(param); // 장바구니 수정 이력 저장
- }
- }
- result.put("status", "SUCCESS");
- return result;
- }
- /**
- * 마이페이지 장바구니 담기 관련 정보 조회
- *
- * @param Cart
- * @return Collection<Cart>
- * @author card007
- * @since 2021. 03. 26
- */
- public Collection<Cart> getAddCartInfoForMypage(Cart cart) {
- return cartDao.getAddCartInfoForMypage(cart);
- }
- /**
- * 장바구니 주문하기 버튼 클릭시 재고 및 상태 체크
- * @param Order
- * @return Collection<Order>
- * @author xodud1202
- * @since 2021. 04. 01
- */
- public Collection<Order> getOrderListConditionCheck(Order param) {
- int custNo = 0;
- if(TsfSession.isLogin()) {
- custNo = TsfSession.getInfo().getCustNo();
- } else {
- param.setJsessionId(TsfSession.getSessionId());
- }
- if(param.getCustNo() > 0 && custNo == 0) {
- return null;
- }
- Collection<Order> cartGoodsList = cartDao.getCartGoodsList(param);
- for(Order order : cartGoodsList) {
- if("Y".equals(order.getSoldoutYn())) {
- if(order.getOrdCanQty() < order.getGoodsQty()) {
- Collection<Order> conditionList = cartDao.getCartDetailInfo(order);
- for(Order condition : conditionList) {
- if("Y".equals(condition.getSoldoutYn())) {
- order.setItemCd(condition.getItemCd());
- order.setColorNm(condition.getColorNm());
- order.setOptCd2(condition.getOptCd2());
- order.setMaxOrdQty(condition.getMaxOrdQty());
- }
- }
- }
- }
- }
- return cartGoodsList;
- }
- /**
- * 장바구니 최소/최대 주문 수량으로 변경
- * @param Order
- * @return Collection<Order>
- * @author xodud1202
- * @since 2021. 04. 02
- */
- @Transactional("shopTxnManager")
- public Order updateCartGoodsQty(Cart param) {
- if(TsfSession.isLogin()) {
- param.setCustNo(TsfSession.getInfo().getCustNo());
- param.setUpdNo(param.getCustNo());
- } else {
- param.setCustNo(0);
- param.setUpdNo(0);
- }
- Order order = new Order();
- order.setChgQty(cartDao.updateCartGoodsQty(param));
- return order;
- }
- public Collection<Order> selectTmtbSalesValueList(Goods param) {
- List<Integer> arr = Arrays.asList(param.getArrTmtbSq());
- return cartDao.selectTmtbSectionValList(arr);
- }
- public Collection<Goods> selectTmtbSalesGoodsOptCd(Goods param) {
- Goods goods = new Goods();
- if(TsfSession.isLogin()) {
- goods.setCustNo(TsfSession.getInfo().getCustNo());
- } else {
- goods.setCustNo(0);
- }
- goods.setFrontGb(TsfSession.getFrontGb());
- goods.setGoodsCd(param.getGoodsCd());
- return goodsDao.getDelvFeeSaveGoodsList(goods);
- }
- /**
- * 장바구니 담긴 상품 전체 조회
- * @param param
- * @return
- * @author xodud1202
- * @since 2021. 07. 06
- */
- public Collection<Cart> getAllCartList(Cart param) {
- return cartDao.getAllCartList(param);
- }
- }
|