TsfCartService.java 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. package com.style24.front.biz.service;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.Collection;
  5. import java.util.Collections;
  6. import java.util.Comparator;
  7. import java.util.List;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.core.env.Environment;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import org.thymeleaf.util.StringUtils;
  13. import com.style24.core.biz.dao.TscEnvsetDao;
  14. import com.style24.core.biz.service.TscKcpService;
  15. import com.style24.core.biz.service.TscOrderService;
  16. import com.style24.core.support.env.TscConstants;
  17. import com.style24.core.support.session.TscSession;
  18. import com.style24.front.biz.dao.TsfCartDao;
  19. import com.style24.front.biz.dao.TsfGoodsDao;
  20. import com.style24.front.support.security.session.TsfSession;
  21. import com.style24.persistence.domain.Cart;
  22. import com.style24.persistence.domain.Goods;
  23. import com.style24.persistence.domain.GoodsStock;
  24. import com.style24.persistence.domain.Login;
  25. import com.style24.persistence.domain.Order;
  26. import lombok.extern.slf4j.Slf4j;
  27. import com.gagaframework.web.parameter.GagaMap;
  28. /**
  29. * 장바구니 Service
  30. *
  31. * @author gagamel
  32. * @since 2020. 12. 29
  33. */
  34. @Service
  35. @Slf4j
  36. public class TsfCartService {
  37. @Autowired
  38. private TsfCartDao cartDao;
  39. @Autowired
  40. private TsfGoodsDao goodsDao;
  41. @Autowired
  42. private TsfGoodsService goodsService;
  43. @Autowired
  44. private TscOrderService coreOrderService;
  45. @Autowired
  46. private TscKcpService coreKcpService;
  47. @Autowired
  48. private Environment env;
  49. @Autowired
  50. private TscEnvsetDao coreEnvsetDao;
  51. /**
  52. * 장바구니 저장
  53. * 단품 : goodsCd, optCd, optCd1, optCd2
  54. * 세트 : goodsCd,
  55. * @param params
  56. */
  57. @Transactional("shopTxnManager")
  58. public GagaMap saveCartInfo(Collection<Cart> params) {
  59. GagaMap result = new GagaMap();
  60. List<Integer> cartSqList = new ArrayList<>();
  61. String newCustCanYn = "Y";
  62. // 로그인 유무 확인 (로그인이 되어 있지 않으면 regNo 를 0으로 장바구니에 저장한다.)
  63. Login login = new Login();
  64. if(TsfSession.isLogin()) {
  65. login = TsfSession.getInfo();
  66. } else {
  67. login.setCustNo(0);
  68. login.setCustGrade("G110");
  69. }
  70. result.put("custNo", login.getCustNo());
  71. String goodsType = params.iterator().next().getGoodsType();
  72. String cartGb = params.iterator().next().getCartGb();
  73. if(StringUtils.isEmpty(goodsType)) {
  74. goodsType = params.iterator().next().getCartCompsList().iterator().next().getGoodsType();
  75. }
  76. if(StringUtils.isEmpty(cartGb)) {
  77. cartGb = params.iterator().next().getCartCompsList().iterator().next().getCartGb();
  78. }
  79. // 2021.04.13 jsh77b 주문서에서 유효성 체크를 위해서 추가
  80. String checkGb = "";
  81. if (params.iterator().next().getCheckGb() == null) {
  82. checkGb = "C";
  83. } else {
  84. checkGb = params.iterator().next().getCheckGb();
  85. }
  86. // 장바구니 상품 및 재고 가능 여부 체크
  87. if(TscConstants.GoodsType.SET.value().equals(goodsType)) {
  88. for (Cart goodsParams : params) {
  89. for (Cart param : goodsParams.getCartCompsList()) {
  90. param.setCustNo(login.getCustNo());
  91. // 상품 마스터 정보 확인
  92. Goods goods = new Goods();
  93. goods.setGoodsCd(param.getGoodsCd());
  94. goods.setFrontGb(TsfSession.getFrontGb());
  95. goods.setSiteCd(TscConstants.Site.STYLE24.value());
  96. goods = goodsService.getGoodsInfo(goods);
  97. // 신규 고객 주문 가능 상품 체크
  98. if("Y".equals(goods.getNewCustOrdYn())) {
  99. Goods tmp = new Goods();
  100. tmp.setCustNo(login.getCustNo());
  101. tmp.setGoodsCd(param.getGoodsCd());
  102. tmp = goodsDao.getNewCustOrdCanYnInfo(tmp);
  103. if("N".equals(tmp.getNewCustCanYn())) {
  104. newCustCanYn = "N";
  105. }
  106. }
  107. if (goods == null) {
  108. result.put("message", "상품 정보가 존재하지 않습니다.");
  109. return result;
  110. } else if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
  111. result.put("message", "품절입니다.");
  112. return result;
  113. } else if (!TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat()) && !TscConstants.GoodsStat.APPR.value().equals(goods.getGoodsStat())) {
  114. result.put("message", "판매중인 상품이 아닙니다.");
  115. return result;
  116. } else if (param.getGoodsQty() > goods.getMaxOrdQty()) {
  117. result.put("message", goods.getGoodsNm() + " 상품의 최대 구매 수량은 " + goods.getMaxOrdQty() + " 입니다.");
  118. return result;
  119. } else if (param.getGoodsQty() < goods.getMinOrdQty()) {
  120. result.put("message", goods.getGoodsNm() + " 상품의 최소 구매 수량은 " + goods.getMinOrdQty() + " 입니다.");
  121. return result;
  122. }
  123. // 상품 구매 가능 등급 조회
  124. Collection<Goods> gradeList = goodsDao.getGoodsDetailOrderGradeList(goods);
  125. // 구매가능 등급이 없으면 전체 구매 가능
  126. if(gradeList != null && gradeList.size() > 0) {
  127. // 구매가능 등급이 존재하면 비회원은 구매 불가. 회원은 등급체크.
  128. if(login.getCustNo() > 0) {
  129. boolean chkGrade= false;
  130. for(Goods grade : gradeList) {
  131. if(grade.getCustGrade().equals(login.getCustGrade())) {
  132. chkGrade = true;
  133. }
  134. }
  135. // 구매가능 등급이 아니면 장바구니 등록 X
  136. if(!chkGrade) {
  137. result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
  138. return result;
  139. }
  140. } else {
  141. result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
  142. return result;
  143. }
  144. }
  145. // 상품 재고 확인
  146. GoodsStock checkParam = new GoodsStock();
  147. checkParam.setGoodsCd(param.getGoodsCd());
  148. checkParam.setItemCd(param.getItemCd());
  149. checkParam.setOptCd(param.getOptCd());
  150. checkParam.setGoodsQty(param.getGoodsQty());
  151. checkParam.setGoodsType(param.getGoodsType());
  152. String stockResult = goodsService.getCheckStock(checkParam);
  153. if (!"SUCCESS".equals(stockResult)) {
  154. result.put("message", stockResult);
  155. return result;
  156. }
  157. // 금일 주문 수량 체크
  158. if (!StringUtils.isEmpty(param.getCartGb()) && ("N".equals(param.getCartGb()) || "O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
  159. int goodsCartCnt = 0;
  160. if(param.getCustNo() != 0) {
  161. goodsCartCnt = cartDao.getGoodsTodayOrderCnt(param);
  162. }
  163. if (param.getGoodsQty() + goodsCartCnt > goods.getDayMaxOrdQty()) {
  164. result.put("message", "1일 구매한도 수량이 초과되었습니다.");
  165. return result;
  166. }
  167. }
  168. }
  169. }
  170. // 2021.04.13 jsh77b 주문서에서 유효성 체크를 위해서 추가
  171. if ("C".equals(checkGb)) {
  172. saveSetTypeCartInfo(params, cartSqList);
  173. }
  174. } else {
  175. for (Cart param : params) {
  176. param.setCustNo(login.getCustNo());
  177. // 상품 마스터 정보 확인
  178. Goods goods = new Goods();
  179. goods.setGoodsCd(param.getGoodsCd());
  180. goods.setFrontGb(TsfSession.getFrontGb());
  181. goods.setSiteCd(TscConstants.Site.STYLE24.value());
  182. goods = goodsService.getGoodsInfo(goods);
  183. // 신규 고객 주문 가능 상품 체크
  184. if("Y".equals(goods.getNewCustOrdYn())) {
  185. Goods tmp = new Goods();
  186. tmp.setCustNo(login.getCustNo());
  187. tmp.setGoodsCd(param.getGoodsCd());
  188. tmp = goodsDao.getNewCustOrdCanYnInfo(tmp);
  189. if("N".equals(tmp.getNewCustCanYn())) {
  190. newCustCanYn = "N";
  191. }
  192. }
  193. if (goods == null) {
  194. result.put("message", "상품 정보가 존재하지 않습니다.");
  195. return result;
  196. } else if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
  197. result.put("message", "품절입니다");
  198. return result;
  199. } else if (!TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat()) && !TscConstants.GoodsStat.APPR.value().equals(goods.getGoodsStat())) {
  200. result.put("message", "판매중인 상품이 아닙니다.");
  201. return result;
  202. } else if (param.getGoodsQty() > goods.getMaxOrdQty()) {
  203. result.put("message", goods.getGoodsNm() + " 상품의 최대 구매 수량은 " + goods.getMaxOrdQty() + " 입니다.");
  204. return result;
  205. } else if (param.getGoodsQty() < goods.getMinOrdQty()) {
  206. result.put("message", goods.getGoodsNm() + " 상품의 최소 구매 수량은 " + goods.getMinOrdQty() + " 입니다.");
  207. return result;
  208. }
  209. // 상품 구매 가능 등급 조회
  210. Collection<Goods> gradeList = goodsDao.getGoodsDetailOrderGradeList(goods);
  211. // 구매가능 등급이 없으면 전체 구매 가능
  212. if(gradeList != null && gradeList.size() > 0) {
  213. // 구매가능 등급이 존재하면 비회원은 구매 불가. 회원은 등급체크.
  214. if(login.getCustNo() > 0) {
  215. boolean chkGrade= false;
  216. for(Goods grade : gradeList) {
  217. if(grade.getCustGrade().equals(login.getCustGrade())) {
  218. chkGrade = true;
  219. }
  220. }
  221. // 구매가능 등급이 아니면 장바구니 등록 X
  222. if(!chkGrade) {
  223. result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
  224. return result;
  225. }
  226. } else {
  227. result.put("message", "해당 상품을 구매 하실 수 없는 등급입니다.");
  228. return result;
  229. }
  230. }
  231. // 상품 재고 확인
  232. GoodsStock checkParam = new GoodsStock();
  233. checkParam.setGoodsCd(param.getGoodsCd());
  234. checkParam.setItemCd(param.getItemCd());
  235. checkParam.setOptCd(param.getOptCd());
  236. checkParam.setGoodsQty(param.getGoodsQty());
  237. checkParam.setGoodsType(param.getGoodsType());
  238. String stockResult = goodsService.getCheckStock(checkParam);
  239. if (!"SUCCESS".equals(stockResult)) {
  240. result.put("message", stockResult);
  241. return result;
  242. }
  243. // 금일 주문 수량 체크
  244. if (!StringUtils.isEmpty(param.getCartGb()) && ("N".equals(param.getCartGb()) || "O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
  245. int goodsCartCnt = 0;
  246. if(param.getCustNo() != 0) {
  247. goodsCartCnt = cartDao.getGoodsTodayOrderCnt(param);
  248. }
  249. if (param.getGoodsQty() + goodsCartCnt > goods.getDayMaxOrdQty()) {
  250. result.put("message", "1일 구매한도 수량이 초과되었습니다.");
  251. return result;
  252. }
  253. }
  254. }
  255. // 2021.04.13 jsh77b 주문서에서 유효성 체크를 위해서 추가
  256. if ("C".equals(checkGb)) {
  257. saveNormalDealCartInfo(params, cartSqList);
  258. }
  259. }
  260. result.put("newCustCanYn", newCustCanYn);
  261. result.put("cartSqList", cartSqList);
  262. result.put("goodsType", goodsType);
  263. result.put("cartGb", cartGb);
  264. result.put("message", "SUCCESS");
  265. return result;
  266. }
  267. @Transactional("shopTxnManager")
  268. public void deleteOldCart() {
  269. Cart deleteCart = new Cart();
  270. if(TsfSession.isLogin()) {
  271. deleteCart.setCustNo(TsfSession.getInfo().getCustNo());
  272. } else {
  273. deleteCart.setCustNo(0);
  274. }
  275. deleteCart.setJsessionId(TsfSession.getSessionId());
  276. cartDao.deleteOldCart(deleteCart);
  277. cartDao.deleteCartDetailFromEmptyCart();
  278. }
  279. @Transactional("shopTxnManager")
  280. public void saveSetTypeCartInfo(Collection<Cart> params, List<Integer> cartSqs) {
  281. Cart cart = new Cart();
  282. StringBuilder sb = new StringBuilder();
  283. String cartGb = "";
  284. // 로그인 정보
  285. if(TsfSession.isLogin()) {
  286. Login login = TsfSession.getInfo();
  287. cart.setRegNo(login.getCustNo());
  288. cart.setCustNo(login.getCustNo());
  289. cart.setUpdNo(login.getCustNo());
  290. } else {
  291. cart.setCustNo(0);
  292. cart.setRegNo(0);
  293. cart.setUpdNo(0);
  294. }
  295. cart.setJsessionId(TscSession.getSessionId());
  296. boolean chkGoOrderForm = false;
  297. List<String> sendCartSqList = new ArrayList<String>();
  298. for (Cart carts : params) {
  299. int i = 1;
  300. // 장바구니 보유 CART_SQ 쿼리
  301. Collection<Cart> cartInfos = carts.getCartCompsList();
  302. sb = new StringBuilder();
  303. for(Cart param : cartInfos) {
  304. 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 = ");
  305. if (cart.getCustNo() == 0) {
  306. sb.append(cart.getCustNo()).append("\n AND JSESSION_ID = '").append(cart.getJsessionId()).append("'");
  307. } else {
  308. sb.append(cart.getCustNo());
  309. }
  310. 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' ");
  311. if (i < cartInfos.size()) {
  312. i++;
  313. sb.append("\n UNION ALL \n");
  314. }
  315. }
  316. // cart 정보 세팅
  317. cart.setContentsLoc(cartInfos.iterator().next().getContentsLoc());
  318. cart.setAfLinkCd(cartInfos.iterator().next().getAfLinkCd());
  319. cart.setIthrCd(cartInfos.iterator().next().getIthrCd());
  320. cart.setPlanDtlSq(cartInfos.iterator().next().getPlanDtlSq());
  321. cart.setGoodsCd(cartInfos.iterator().next().getGoodsCd());
  322. cart.setGoodsQty(cartInfos.iterator().next().getGoodsQty());
  323. cart.setGoodsType(cartInfos.iterator().next().getGoodsType());
  324. cart.setItemCdSql(sb.toString());
  325. Collection<Cart> cartSqList = null;
  326. if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && "C".equals(cartInfos.iterator().next().getCartGb())) {
  327. cart.setCartGb(TscConstants.CartGb.CART.value());
  328. // 같은 장바구니 상품 확인
  329. cartSqList = cartDao.selectHasSetItemCartList(cart);
  330. } else if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && ("N".equals(cartInfos.iterator().next().getCartGb()) || "O".equals(cartInfos.iterator().next().getCartGb()))) {
  331. if ("P".equals(TsfSession.getFrontGb())) {
  332. cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
  333. } else {
  334. cart.setCartGb(TscConstants.CartGb.MOB_ORDER.value());
  335. }
  336. if("O".equals(cartInfos.iterator().next().getCartGb())) {
  337. chkGoOrderForm = true;
  338. }
  339. } else if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && "G".equals(cartInfos.iterator().next().getCartGb())) {
  340. chkGoOrderForm = true;
  341. cart.setCartGb(TscConstants.CartGb.GIFT.value());
  342. } else {
  343. cart.setCartGb(TscConstants.CartGb.CREATE_ORDER.value());
  344. }
  345. if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
  346. if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
  347. throw new IllegalStateException("장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
  348. } else {
  349. cart.setCartSq(cartSqList.iterator().next().getCartSq());
  350. cartSqs.add(cart.getCartSq());
  351. cartDao.updateCartInfo(cart); // 장바구니 정보 수정
  352. }
  353. } else {
  354. cartDao.insertCartInfo(cart); // 장바구니 마스터 정보 저장
  355. cartSqs.add(cart.getCartSq());
  356. sendCartSqList.add(cart.getCartSq() + "");
  357. for (Cart param : cartInfos) {
  358. param.setCartSq(cart.getCartSq());
  359. param.setRegNo(cart.getRegNo());
  360. param.setCustNo(cart.getCustNo());
  361. param.setUpdNo(cart.getUpdNo());
  362. cartDao.insertCartDetailInfo(param); // 장바구니 상세 저장
  363. }
  364. }
  365. }
  366. // 상품상세 > 바로구매 로그인 후 구매 클릭시 주문서로 송부할 장바구니번호
  367. StringBuilder cartSqComma = new StringBuilder();
  368. int i = 0;
  369. for(String cartSq : sendCartSqList) {
  370. if(i > 0) {
  371. cartSqComma.append(",");
  372. }
  373. cartSqComma.append(cartSq);
  374. i++;
  375. }
  376. if(chkGoOrderForm) {
  377. TsfSession.setAttribute("cartSqArr", cartSqComma.toString());
  378. }
  379. }
  380. @Transactional("shopTxnManager")
  381. public void saveNormalDealCartInfo(Collection<Cart> params, List<Integer> cartSqs) {
  382. Cart cart = new Cart();
  383. // 로그인 정보
  384. if(TsfSession.isLogin()) {
  385. Login login = TsfSession.getInfo();
  386. cart.setCustNo(login.getCustNo());
  387. } else {
  388. cart.setCustNo(0);
  389. }
  390. cart.setJsessionId(TscSession.getSessionId());
  391. if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "C".equals(params.iterator().next().getCartGb())) {
  392. cart.setCartGb(TscConstants.CartGb.CART.value());
  393. } else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && ("N".equals(params.iterator().next().getCartGb()) || "O".equals(params.iterator().next().getCartGb()))) {
  394. if ("P".equals(TsfSession.getFrontGb())) {
  395. cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
  396. } else {
  397. cart.setCartGb(TscConstants.CartGb.MOB_ORDER.value());
  398. }
  399. } else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "G".equals(params.iterator().next().getCartGb())) {
  400. cart.setCartGb(TscConstants.CartGb.GIFT.value());
  401. } else {
  402. cart.setCartGb(TscConstants.CartGb.CREATE_ORDER.value());
  403. }
  404. // 세션 추가용 변수
  405. String cartGb = params.iterator().next().getCartGb();
  406. List<String> sendCartSqList = new ArrayList<String>();
  407. for(Cart item : params) {
  408. item.setCartGb(cart.getCartGb());
  409. item.setCustNo(cart.getCustNo());
  410. item.setRegNo(cart.getCustNo());
  411. item.setUpdNo(cart.getCustNo());
  412. item.setJsessionId(cart.getJsessionId());
  413. // 같은 장바구니 상품 확인
  414. Collection<Integer> cartSqList = null;
  415. if(TscConstants.CartGb.CART.value().equals(cart.getCartGb())) {
  416. cartSqList = cartDao.selectHasNormalDealItemCartList(item);
  417. }
  418. if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
  419. if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
  420. throw new IllegalStateException("장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
  421. } else {
  422. item.setCartSq(cartSqList.iterator().next());
  423. cartSqs.add(item.getCartSq());
  424. cartDao.updateCartInfo(item);
  425. }
  426. } else {
  427. cartDao.insertCartInfo(item); // 장바구니 마스터 정보 저장
  428. cartDao.insertCartDetailInfo(item); // 장바구니 상세 저장
  429. cartSqs.add(item.getCartSq());
  430. sendCartSqList.add(item.getCartSq() + "");
  431. }
  432. }
  433. StringBuilder cartSqComma = new StringBuilder();
  434. int i = 0;
  435. for(String cartSq : sendCartSqList) {
  436. if(i > 0) {
  437. cartSqComma.append(",");
  438. }
  439. cartSqComma.append(cartSq);
  440. i++;
  441. }
  442. if (!StringUtils.isEmpty(cartGb) && ("O".equals(cartGb) || "G".equals(cartGb))) {
  443. TsfSession.setAttribute("cartSqArr", cartSqComma.toString());
  444. }
  445. }
  446. // 장바구니 상품 리스트 조회 서비스
  447. @SuppressWarnings("unchecked")
  448. public Order getCartGoodsList(Order order) {
  449. //ModelAndView result = new ModelAndView();
  450. GagaMap result = new GagaMap(); // return
  451. List<Integer> cartSqs = new ArrayList<Integer>(); // 품절 제외 장바구니 리스트
  452. // 로그인 체크
  453. if(TsfSession.isLogin()) {
  454. order.setCustNo(TsfSession.getInfo().getCustNo());
  455. } else {
  456. order.setCustNo(0);
  457. }
  458. order.setFrontGb(TsfSession.getFrontGb());
  459. order.setJsessionId(TscSession.getSessionId());
  460. // 장바구니 상품 조회
  461. Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);
  462. // 품절 아닌 상품만 체크
  463. for (Order goods : cartGoodsList) {
  464. if ("N".equals(goods.getSoldoutYn()) && "Y".equals(goods.getOrdCanYn()) && "Y".equals(goods.getNewCustCanYn()) && goods.getGoodsQty() >= goods.getMinOrdQty() && goods.getGoodsQty() <= goods.getMaxOrdQty()) {
  465. cartSqs.add(goods.getCartSq());
  466. }
  467. goods.setOrgSavePntAmt((int) (goods.getCurrPrice() * goods.getPntRate() / 100.0));
  468. }
  469. order.setCartSqArr(cartSqs.stream().mapToInt(Integer::intValue).toArray());
  470. if(cartSqs.size() > 0) {
  471. // 다다익선 할인 상품 조회 (품절 상품 제외)
  472. Collection<Order> moreBetterAmtList = new ArrayList<Order>();
  473. //if(order.getCustNo() > 0) { // 비회원도 다다익선 적용 여부 및 금액 노출되도록 수정. (한수인리더 요청) :: 20210517
  474. order.setCartYn("Y");
  475. moreBetterAmtList = getMoreBetterAmtList(order);
  476. //}
  477. // 다다익선 할인 정보 및 상품 정보 장바구니에 등록
  478. for (Order cart : cartGoodsList) {
  479. for (Order info : moreBetterAmtList) {
  480. if (cart.getCartSq().equals(info.getCartSq())) {
  481. cart.setTmtbDcAmt(info.getTmtbDcAmt());
  482. cart.setApplyAmtSectionYn(info.getApplyAmtSectionYn());
  483. cart.setApplyQtySectionYn(info.getApplyQtySectionYn());
  484. cart.setQtyTmtbNm(info.getQtyTmtbNm());
  485. cart.setAmtTmtbNm(info.getAmtTmtbNm());
  486. cart.setQtyTmtbSq(info.getQtyTmtbSq());
  487. cart.setAmtTmtbSq(info.getAmtTmtbSq());
  488. }
  489. }
  490. if (cart.getTmtbDcAmt() == 0) {
  491. cart.setTmtbDcAmt(cart.getCurrPrice());
  492. }
  493. if(cart.getPntRate() > 0) {
  494. cart.setSavePntAmt((int) (cart.getTmtbDcAmt() * cart.getPntRate() / 100.0));
  495. } else {
  496. cart.setSavePntAmt(0);
  497. }
  498. }
  499. }
  500. // 자사 / 입점업체 리스트 분리
  501. order = getCartDelvGoodsCntList(cartGoodsList, order);
  502. // 장바구니 업체별 배송비 계산
  503. setCartListDelvFeeInfo(cartGoodsList, order);
  504. // 총계 금액 계산
  505. setCartListTotAmtInfo(cartGoodsList, order);
  506. // 전체 장바구니 정보
  507. order.setDelvAllCartList(cartGoodsList);
  508. order.setAllCartCnt(cartGoodsList.size());
  509. return order;
  510. }
  511. // 장바구니 수량 계산(품절제거)
  512. @SuppressWarnings("unchecked")
  513. public Order getCartNotSoldoutCnt() {
  514. Order order = new Order();
  515. //ModelAndView result = new ModelAndView();
  516. GagaMap result = new GagaMap(); // return
  517. List<Integer> cartSqs = new ArrayList<Integer>(); // 품절 제외 장바구니 리스트
  518. // 로그인 체크
  519. if(TsfSession.isLogin()) {
  520. order.setCustNo(TsfSession.getInfo().getCustNo());
  521. } else {
  522. order.setCustNo(0);
  523. }
  524. order.setFrontGb(TsfSession.getFrontGb());
  525. order.setJsessionId(TscSession.getSessionId());
  526. // 장바구니 상품 조회
  527. Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);
  528. // 총계 금액 계산 (수량 계산 내부에 존재)
  529. setCartListTotAmtInfo(cartGoodsList, order);
  530. return order;
  531. }
  532. /**
  533. * 다다익선 할인 금액 조회
  534. * @param param
  535. * param.cartSqArr[] : 필수
  536. * @return String
  537. * @author xodud1202
  538. * @since 2021. 01. 28
  539. */
  540. public Collection<Order> getMoreBetterAmtList(Order param) {
  541. // 장바구니 상품 조회
  542. param.setFrontGb(TsfSession.getFrontGb());
  543. Collection<Order> cartGoodsList = coreOrderService.getCartGoodsList(param);
  544. String cartYn = "N";
  545. if(!StringUtils.isEmpty(param.getCartYn())) {
  546. cartYn = param.getCartYn();
  547. }
  548. if(param.getCustNo() > 0 || "Y".equals(cartYn)) {
  549. // 장바구니 내 수량 다다익선 적용 가능 리스트 조회 (등록된 기본,적용 상품 정보 전체 조회)
  550. Collection<Order> tmtbApplyList = cartDao.selectMoreBetterApplyCartList(param);
  551. // 장바구니 등록 다다익선 일련번호 지정
  552. List<Integer> applySq = new ArrayList<Integer>();
  553. for(Order tmtbApply : tmtbApplyList) {
  554. if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb()) || TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
  555. if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb())) {
  556. applySq.add(tmtbApply.getQtyTmtbSq());
  557. }
  558. if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
  559. applySq.add(tmtbApply.getAmtTmtbSq());
  560. }
  561. }
  562. }
  563. param.setTmtbSqs(applySq.stream().mapToInt(Integer::intValue).toArray());
  564. // 섹션 정보 조회 후 할인 여부 판단
  565. Collection<Order> tmtbSectionList = cartDao.selectTmtbSectionValList(applySq);
  566. for(Order applyInfo : tmtbApplyList) { // 기준 상품 및 다다익선 정보 조회
  567. // 다다익선 할인 조건 조회
  568. for(Order section : tmtbSectionList) {
  569. if(applyInfo.getQtyTmtbSq() == section.getTmtbSq()) {
  570. // 수량 적용 다다익선
  571. if (section.getSectionVal() <= applyInfo.getQtyTmtbSumQty()) { // 장바구니 수량 할인 기준 달성시
  572. if (applyInfo.getQtySectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
  573. applyInfo.setQtySectionVal(section.getSectionVal());
  574. applyInfo.setApplyQtySectionYn("Y");
  575. applyInfo.setQtyDcWay(section.getDcWay());
  576. applyInfo.setQtyDcVal(section.getDcVal());
  577. }
  578. } else {
  579. if (applyInfo.getQtySectionVal() < 1 && applyInfo.getQtyGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
  580. applyInfo.setApplyQtySectionYn("N");
  581. }
  582. }
  583. }
  584. if (applyInfo.getAmtTmtbSq() == section.getTmtbSq()) {
  585. // 금액 적용 다다익선
  586. if(section.getSectionVal() <= applyInfo.getAmtTmtbSumAmt()) { // 장바구니 수량 할인 기준 달성시
  587. if(applyInfo.getAmtSectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
  588. applyInfo.setAmtSectionVal(section.getSectionVal());
  589. applyInfo.setApplyAmtSectionYn("Y");
  590. applyInfo.setAmtDcWay(section.getDcWay());
  591. applyInfo.setAmtDcVal(section.getDcVal());
  592. }
  593. } else {
  594. if(applyInfo.getAmtSectionVal() < 1 && applyInfo.getAmtGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
  595. applyInfo.setApplyAmtSectionYn("N");
  596. }
  597. }
  598. }
  599. }
  600. }
  601. // 수량 다다익선에 맞춰 정렬
  602. Collections.sort((ArrayList<Order>) tmtbApplyList, new Comparator<Order>() {
  603. @Override
  604. public int compare(Order c1, Order c2) {
  605. return c1.getQtyTmtbSq() - c2.getQtyTmtbSq();
  606. }
  607. });
  608. // 수량 다다익선 적용 상품 할인 금액 계산
  609. int leftAmt = 0;
  610. int i = 0;
  611. for(Order resultAmt : tmtbApplyList) {
  612. int tempAmt = 0;
  613. if("Y".equals(resultAmt.getApplyQtySectionYn()) && resultAmt.getQtyTmtbSq() > 0) {
  614. if (TscConstants.DcWay.AMT.value().equals(resultAmt.getQtyDcWay())) { // 할인 방식 금액일경우
  615. i++;
  616. tempAmt = resultAmt.getCurrPrice();
  617. if (i == 1) {
  618. leftAmt = resultAmt.getQtyDcVal();
  619. }
  620. if (i == resultAmt.getQtyTmtbCnt()) {
  621. resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
  622. resultAmt.setTmtb1DcAmt(leftAmt); // tmtb1 할인금액
  623. leftAmt = 0;
  624. i = 0;
  625. } else {
  626. double tempDcAmt = resultAmt.getQtyDcVal() * ((tempAmt) / (double)resultAmt.getQtyTmtbSumAmt());
  627. leftAmt -= (int)tempDcAmt;
  628. resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
  629. resultAmt.setTmtb1DcAmt((int)tempDcAmt); // tmtb1 할인금액
  630. }
  631. } else { // 할인 방식 할인율일 경우
  632. tempAmt = resultAmt.getCurrPrice();
  633. tempAmt = (tempAmt - (int) (tempAmt * (resultAmt.getQtyDcVal() / 100.0)));
  634. resultAmt.setTmtbDcAmt(tempAmt);
  635. // 2021.04.29 다다익선할인금액수정
  636. resultAmt.setTmtb1DcAmt((int) (resultAmt.getCurrPrice() * (resultAmt.getQtyDcVal() / 100.0))); // tmtb1 할인금액
  637. }
  638. }
  639. if (resultAmt.getTmtbDcAmt() > 0) {
  640. resultAmt.setCurrPrice(resultAmt.getTmtbDcAmt());
  641. }
  642. }
  643. // 금액 다다익선에 맞춰 정렬
  644. Collections.sort((ArrayList<Order>) tmtbApplyList, new Comparator<Order>() {
  645. @Override
  646. public int compare(Order c1, Order c2) {
  647. return c1.getAmtTmtbSq() - c2.getAmtTmtbSq();
  648. }
  649. });
  650. // 금액 다다익선 할인 계산
  651. leftAmt = 0;
  652. i = 0;
  653. for(Order resultAmt : tmtbApplyList) {
  654. int tempAmt = 0;
  655. if("Y".equals(resultAmt.getApplyAmtSectionYn()) && resultAmt.getAmtTmtbSq() > 0) {
  656. if (TscConstants.DcWay.AMT.value().equals(resultAmt.getAmtDcWay())) { // 할인 방식 금액일경우
  657. i++;
  658. tempAmt = resultAmt.getCurrPrice();
  659. if (i == 1) {
  660. leftAmt = resultAmt.getAmtDcVal();
  661. }
  662. if (i == resultAmt.getAmtTmtbCnt()) {
  663. resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
  664. resultAmt.setTmtb2DcAmt(leftAmt); // tmtb1 할인금액
  665. leftAmt = 0;
  666. i = 0;
  667. } else {
  668. double tempDcAmt = resultAmt.getAmtDcVal() * ((tempAmt) / (double)resultAmt.getAmtTmtbSumAmt());
  669. leftAmt -= (int)tempDcAmt;
  670. resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
  671. resultAmt.setTmtb2DcAmt((int)tempDcAmt); // tmtb1 할인금액
  672. }
  673. } else { // 할인 방식 할인율일 경우
  674. tempAmt = resultAmt.getCurrPrice();
  675. tempAmt = (tempAmt - (int) (tempAmt * (resultAmt.getAmtDcVal() / 100.0)));
  676. resultAmt.setTmtbDcAmt(tempAmt);
  677. // 2021.04.29 다다익선할인금액수정
  678. resultAmt.setTmtb2DcAmt((int) (resultAmt.getCurrPrice() * (resultAmt.getAmtDcVal() / 100.0))); // tmtb2 할인금액
  679. }
  680. }
  681. }
  682. // 장바구니 정보에 수량 다다익선 정보 입력
  683. for (Order cart : cartGoodsList) {
  684. for (Order apply : tmtbApplyList) {
  685. if (cart.getCartSq().equals(apply.getCartSq())) {
  686. // 2021.02.24 jsh77b
  687. cart.setTmtb1DcAmt(apply.getTmtb1DcAmt());
  688. cart.setTmtb2DcAmt(apply.getTmtb2DcAmt());
  689. cart.setTmtbDcAmt(apply.getTmtbDcAmt());
  690. log.info("cart.getTmtb1DcAmt() ::: {}", cart.getTmtb1DcAmt());
  691. log.info("cart.getTmtb2DcAmt() ::: {}", cart.getTmtb2DcAmt());
  692. log.info("cart.getTmtbDcAmt() ::: {}", cart.getTmtbDcAmt());
  693. cart.setApplyQtySectionYn(apply.getApplyQtySectionYn());
  694. cart.setQtyTmtbNm(apply.getQtyTmtbNm());
  695. cart.setQtyTmtbSq(apply.getQtyTmtbSq());
  696. cart.setApplyAmtSectionYn(apply.getApplyAmtSectionYn());
  697. cart.setAmtTmtbNm(apply.getAmtTmtbNm());
  698. cart.setAmtTmtbSq(apply.getAmtTmtbSq());
  699. }
  700. }
  701. }
  702. }
  703. //return result;
  704. return cartGoodsList;
  705. }
  706. /**
  707. * 장바구니 배송단위별 상품 정보 조회
  708. *
  709. * @param cartGoodsList
  710. * @author xodud1202
  711. * @since 2021. 02. 02
  712. */
  713. public Order getCartDelvGoodsCntList(Collection<Order> cartGoodsList, Order paramOrder) {
  714. // 1. 장바구니 상품 배송단위별 건수 체크 로직 (자사:총알배송, 자사:일반배송, 입점업체, 예약배송)
  715. Order delvOrder = new Order();
  716. Collection<Order> shotCartList = new ArrayList<Order>();
  717. Collection<Order> wmsCartList = new ArrayList<Order>();
  718. Collection<Order> delvCartList = new ArrayList<Order>();
  719. for (Order order : cartGoodsList) {
  720. // 1.1 세트상품 옵션별 배열로 담기
  721. if (order.getItemNm().contains("!@!")) {
  722. order.setItemNmArr(order.getItemNm().split("!@!"));
  723. order.setOptCdArr(order.getOptCd().split(","));
  724. order.setItemQtyArr(order.getItemQtyr().split(","));
  725. order.setOptCd1Arr(order.getOptCd1().split(","));
  726. order.setOptCd2Arr(order.getOptCd2().split(","));
  727. order.setColorNmArr(order.getColorNm().split(","));
  728. } else {
  729. String[] arr = {order.getItemNm()}, arr2 = {order.getOptCd1()}, arr3 = {order.getOptCd2()}, arr4 = {order.getItemQtyr()}, arr5 = {order.getColorNm()};
  730. order.setItemNmArr(arr);
  731. order.setOptCd1Arr(arr2);
  732. order.setOptCd2Arr(arr3);
  733. order.setItemQtyArr(arr4);
  734. order.setColorNmArr(arr5);
  735. }
  736. // 1.3 배송정책별 상품 구분
  737. if ("SHOT".equals(order.getCartDelvFeeCd())) {
  738. if(paramOrder.getShotDelvUseYn() != null && "N".equals(paramOrder.getShotDelvUseYn())) {
  739. wmsCartList.add(order);
  740. } else {
  741. shotCartList.add(order);
  742. }
  743. } else if ("WMS".equals(order.getCartDelvFeeCd())) {
  744. wmsCartList.add(order);
  745. } else {
  746. delvCartList.add(order);
  747. }
  748. }
  749. delvOrder.setShotCartList(shotCartList); // 자사 총알배송 상품 목록
  750. delvOrder.setWmsCartList(wmsCartList); // 자사 일반상품 목록
  751. delvOrder.setDelvCartList(delvCartList); // 입점 업체 상품 목록
  752. return delvOrder;
  753. }
  754. /**
  755. * 장바구니 배송단위별 배송비 계산
  756. *
  757. * @param params
  758. * @author xodud1202
  759. * @since 2021. 02. 02
  760. */
  761. public void setCartListDelvFeeInfo(Collection<Order> params, Order order) {
  762. Order delvInfo = new Order();
  763. List<Integer> cartSqArr = new ArrayList<Integer>();
  764. // 장바구니 일련번호 세팅
  765. for (Order param : params) {
  766. cartSqArr.add(param.getCartSq());
  767. }
  768. delvInfo.setCartSqArr(cartSqArr.stream().mapToInt(Integer::intValue).toArray());
  769. // 장바구니 업체별 배송비 정보 조회
  770. Collection<Order> delvFeeInfo = new ArrayList<Order>();
  771. if(delvInfo.getCartSqArr() != null && delvInfo.getCartSqArr().length > 0) {
  772. delvFeeInfo = cartDao.getCartListDelvFeeInfoList(delvInfo);
  773. }
  774. // 업체별 상품 합계 금액 저장
  775. int compCnt = 0;
  776. String delvYn;
  777. Order lastCompCheck = new Order();
  778. for (Order delv : delvFeeInfo) {
  779. lastCompCheck = null;
  780. compCnt = 0;
  781. delvYn = "N";
  782. for (Order param : params) {
  783. if (param.getDelvFeeCd().equals(delv.getDelvFeeCd())) {
  784. compCnt++;
  785. if("N".equals(param.getSoldoutYn()) && "Y".equals(param.getOrdCanYn()) && "Y".equals(param.getNewCustCanYn()) && param.getGoodsQty() >= param.getMinOrdQty() && param.getGoodsQty() <= param.getMaxOrdQty()) {
  786. delv.setCompSumPrice(delv.getCompSumPrice() + param.getCurrPrice());
  787. delvYn = "Y";
  788. }
  789. if (compCnt == 1) {
  790. param.setFirstCompYn("Y");
  791. }
  792. // 한 업체의 마지막 params를 확인
  793. lastCompCheck = param;
  794. }
  795. }
  796. if(lastCompCheck != null) {
  797. // 한 업체의 마지막 상품 체크
  798. lastCompCheck.setAddDelvFeeYn("Y");
  799. // 배송 상품 존재 여부
  800. lastCompCheck.setDelvYn(delvYn);
  801. // 배송상품 금액차이
  802. }
  803. }
  804. int wmsSumPrice = 0, wmsMinOrdAmt = 0, wmsDelvFee = 0;
  805. // 장바구니 업체별 합계 금액으로 무료배송 여부 저장
  806. for (Order param : params) {
  807. // 입점업체 배송비
  808. for (Order delv : delvFeeInfo) {
  809. if (param.getDelvFeeCd().equals(delv.getDelvFeeCd()) && !"WMS".equals(param.getDelvFeeCd())) {
  810. param.setCompCnt(delv.getCompCnt());
  811. param.setDelvFeeCrite(delv.getDelvFeeCrite());
  812. if (TscConstants.DelvFeeCrite.FREE.value().equals(delv.getDelvFeeCrite())) {
  813. param.setDelvFee(0);
  814. } else if (TscConstants.DelvFeeCrite.NORMAL.value().equals(delv.getDelvFeeCrite()) && delv.getCompSumPrice() > delv.getMinOrdAmt()) {
  815. param.setDelvFee(0);
  816. } else {
  817. param.setCompSumPrice(delv.getCompSumPrice());
  818. param.setMinOrdAmt(delv.getMinOrdAmt());
  819. param.setDelvFee(delv.getDelvFee());
  820. }
  821. }
  822. }
  823. // 자사 상품 가격 계산
  824. if("WMS".equals(param.getDelvFeeCd())) {
  825. if("N".equals(param.getSoldoutYn()) && "Y".equals(param.getOrdCanYn())&& "Y".equals(param.getNewCustCanYn()) && param.getGoodsQty() >= param.getMinOrdQty() && param.getGoodsQty() <= param.getMaxOrdQty()) {
  826. wmsSumPrice = wmsSumPrice + param.getCurrPrice();
  827. wmsMinOrdAmt = param.getMinOrdAmt();
  828. wmsDelvFee = param.getDelvFee();
  829. }
  830. }
  831. }
  832. // 자사 배송비 등록
  833. if(params.size() > 0) {
  834. if (wmsSumPrice > wmsMinOrdAmt) {
  835. order.setWmsDelvFee(0);
  836. } else {
  837. order.setWmsDelvFee(wmsDelvFee);
  838. order.setCompSumPrice(wmsSumPrice);
  839. order.setMinOrdAmt(wmsMinOrdAmt);
  840. }
  841. // 배송 상품 존재 여부
  842. if(wmsSumPrice > 0) {
  843. order.setDelvYn("Y");
  844. }
  845. }
  846. }
  847. /**
  848. * 장바구니 배송비 합계금액 계산
  849. * @param cartGoodsList
  850. * @param order
  851. * @author xodud1202
  852. * @since 2021. 02. 02
  853. */
  854. public void setCartListTotAmtInfo(Collection<Order> cartGoodsList, Order order) {
  855. // 장바구니 합계 금액 계산
  856. int notSoldoutCnt = 0;
  857. for(Order cart : cartGoodsList) {
  858. if("N".equals(cart.getSoldoutYn()) && "Y".equals(cart.getOrdCanYn()) && "Y".equals(cart.getNewCustCanYn()) && cart.getGoodsQty() >= cart.getMinOrdQty() && cart.getGoodsQty() <= cart.getMaxOrdQty()) {
  859. notSoldoutCnt++;
  860. // 상품 금액 합계
  861. order.setSumOrdAmt(order.getSumOrdAmt() + cart.getCurrPrice());
  862. order.setSumRealPayAmt(order.getSumRealPayAmt() + cart.getTmtbDcAmt());
  863. order.setSumListPrice(order.getSumListPrice() + cart.getListPrice());
  864. // 배송비 합계
  865. if ("Y".equals(cart.getFirstCompYn())) {
  866. order.setTotDelvFee(order.getTotDelvFee() + cart.getDelvFee());
  867. }
  868. }
  869. }
  870. // 자사 배송비 추가
  871. order.setTotDelvFee(order.getTotDelvFee() + order.getWmsDelvFee());
  872. // 상품 할인금액 총계
  873. // order.setTotDcAmt(order.getSumRealPayAmt() - order.getSumOrdAmt()); /* 다다익선 금액이 상품금액일 경우 해당 주석 제거 */
  874. order.setTotDcAmt(order.getSumRealPayAmt() - order.getSumListPrice());
  875. // 장바구니 총액 계산 상품 총 수량
  876. order.setTotCartCnt(notSoldoutCnt);
  877. order.setCartGoodsList(cartGoodsList);
  878. }
  879. @Transactional("shopTxnManager")
  880. public void deleteCart(Cart param) {
  881. cartDao.deleteCart(param);
  882. }
  883. /**
  884. * 로그인 후 장바구니 Update
  885. * 회원 로그인 후 호출됨으로 세션 정보 있음
  886. * @param custNo - 고객번호
  887. * @author gagamel
  888. * @since 2021. 2. 24
  889. */
  890. @Transactional("shopTxnManager")
  891. public void updateCartToAfterLogin(Integer custNo) {
  892. Cart cart = new Cart();
  893. cart.setJsessionId(TsfSession.getSessionId());
  894. cart.setCustNo(custNo);
  895. cart.setUpdNo(custNo);
  896. log.info("cart: {}", cart);
  897. // 로그인 후 고객번호 Update
  898. int procCnt = cartDao.updateCartOfCustNo(cart);
  899. if (procCnt > 0) {
  900. // 로그인 후 처리할 장바구니 목록
  901. Collection<Cart> cartList = cartDao.getCartListAfterLogin(cart);
  902. for (Cart updCart : cartList) {
  903. updCart.setCustNo(custNo);
  904. updCart.setRegNo(custNo);
  905. // 로그인 후 장바구니 수정
  906. cartDao.updateCartAfterLogin(updCart);
  907. // 로그인 후 장바구니단품 삭제
  908. cartDao.deleteCartItemAfterLogin(updCart);
  909. // 로그인 후 장바구니 삭제
  910. cartDao.deleteCartAfterLogin(updCart);
  911. // 로그인 후 장바구니 이력 생성(삭제할 장바구니번호가 있을 때만)
  912. if (updCart.getDelCartSq() > 0) {
  913. cartDao.createCartHistoryAfterLogin(updCart);
  914. }
  915. }
  916. }
  917. }
  918. public Collection<Goods> getDelvFeeSaveGoodsList(Order param) {
  919. Goods goods = new Goods();
  920. if(StringUtils.isEmpty(param.getDelvFeeCd())) {
  921. return null;
  922. }
  923. if("WMS".equals(param.getDelvFeeCd())) {
  924. goods.setSelfGoodsYn("Y");
  925. } else {
  926. goods.setDelvFeeCd(param.getDelvFeeCd());
  927. }
  928. goods.setPrice(param.getDelvFeeSaveGoodsAmt());
  929. goods.setFrontGb(TsfSession.getFrontGb());
  930. if(TsfSession.isLogin()) {
  931. goods.setCustNo(TsfSession.getInfo().getCustNo());
  932. } else {
  933. goods.setCustNo(0);
  934. }
  935. return goodsDao.getDelvFeeSaveGoodsList(goods);
  936. }
  937. public Cart getCartGoodsInfo(Cart param) {
  938. // 장바구니 상품 마스터 정보 조회
  939. param.setFrontGb(TsfSession.getFrontGb());
  940. Cart cart = cartDao.selectCartGoodsInfo(param);
  941. if(cart == null) {
  942. throw new IllegalStateException("장바구니 상품 정보가 없습니다.\n새로고침 후 다시 시도해주세요.");
  943. }
  944. if(TscConstants.GoodsStat.SOLDOUT.value().equals(cart.getGoodsStat())) {
  945. cart.setSoldoutYn("Y");
  946. } else {
  947. cart.setSoldoutYn("N");
  948. }
  949. // 세트 상품일 경우
  950. if(TscConstants.GoodsType.SET.value().equals(cart.getGoodsType())) {
  951. cart.setCartCompsList(cartDao.selectCartSetGoodsInfo(cart));
  952. for(Cart comp : cart.getCartCompsList()) {
  953. comp.setCartSq(cart.getCartSq());
  954. comp.setCartColorList(cartDao.selectCartGoodsColorList(comp));
  955. if("Y".equals(cart.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(comp.getGoodsStat())) {
  956. comp.setSoldoutYn("Y");
  957. } else {
  958. comp.setSoldoutYn("N");
  959. }
  960. for(Cart color : comp.getCartColorList()) {
  961. if("Y".equals(comp.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(color.getGoodsStat())) {
  962. color.setSoldoutYn("Y");
  963. } else {
  964. color.setSoldoutYn("N");
  965. }
  966. color.setCartSq(comp.getCartSq());
  967. color.setCartSizeList(cartDao.selectCartGoodsSizeList(color));
  968. }
  969. }
  970. cart.setCartImgList(cartDao.selectCartDelvGoodsOptionImgList(cart)); // TB_GOODS.MAIN_COLOR_CD의 이미지를 가져옴.
  971. } else { // 일반, DEAL 상품일 경우
  972. cart.setCartCompsList(new ArrayList<Cart>());
  973. cart.getCartCompsList().add(new Cart());
  974. for(Cart comp : cart.getCartCompsList()) {
  975. comp.setSoldoutYn(cart.getSoldoutYn());
  976. comp.setCartColorList(cartDao.selectCartGoodsColorList(cart));
  977. for(Cart color : comp.getCartColorList()) {
  978. if("Y".equals(comp.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(color.getGoodsStat())) {
  979. color.setSoldoutYn("Y");
  980. } else {
  981. color.setSoldoutYn("N");
  982. }
  983. if(color.getCartDtlSq() > 0) {
  984. comp.setCartDtlSq(color.getCartDtlSq());
  985. comp.setColorNm(color.getCartColorNm());
  986. comp.setOptCd1(color.getOptCd1());
  987. comp.setGoodsCd(cart.getGoodsCd());
  988. }
  989. color.setCartSq(cart.getCartSq());
  990. color.setCartImgList(cartDao.selectCartSelfGoodsOptionImgList(color));
  991. color.setCartSizeList(cartDao.selectCartGoodsSizeList(color));
  992. for(Cart size : color.getCartSizeList()) {
  993. if(size.getCartDtlSq() > 0) {
  994. comp.setOptCd(size.getCartOptCd());
  995. comp.setOptCd2(size.getCartOptCd2());
  996. }
  997. }
  998. }
  999. }
  1000. if(!"Y".equals(cart.getSelfGoodsYn())) { // 입점 상품은 TB_GOODS_IMG.COLOR_CD = TB_GOODS.MAIN_COLOR_CD
  1001. cart.setCartImgList(cartDao.selectCartDelvGoodsOptionImgList(cart));
  1002. }
  1003. }
  1004. cart.setImgPath(env.getProperty("upload.goods.view"));
  1005. return cart;
  1006. }
  1007. @Transactional("shopTxnManager")
  1008. public GagaMap updateCartOption(Cart param) {
  1009. GagaMap result = new GagaMap();
  1010. param.setJsessionId(TsfSession.getSessionId());
  1011. param.setFrontGb(TsfSession.getFrontGb());
  1012. if(TsfSession.isLogin()) {
  1013. param.setCustNo(TsfSession.getInfo().getCustNo());
  1014. param.setRegNo(param.getCustNo());
  1015. param.setUpdNo(param.getCustNo());
  1016. } else {
  1017. param.setCustNo(0);
  1018. param.setRegNo(0);
  1019. param.setUpdNo(0);
  1020. }
  1021. // 재고 체크
  1022. Goods goods = new Goods();
  1023. goods.setGoodsCd(param.getGoodsCd());
  1024. goods.setFrontGb(TsfSession.getFrontGb());
  1025. goods.setSiteCd(TscConstants.Site.STYLE24.value());
  1026. goods = goodsService.getGoodsInfo(goods);
  1027. if (goods == null) {
  1028. result.put("status", "FAIL");
  1029. result.put("message", "상품 정보가 존재하지 않습니다.");
  1030. return result;
  1031. }
  1032. if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
  1033. result.put("status", "FAIL");
  1034. result.put("message", "품절입니다.");
  1035. return result;
  1036. }
  1037. // 구성 상품 재고 확인
  1038. for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
  1039. // 상품 재고 확인
  1040. GoodsStock checkParam = new GoodsStock();
  1041. checkParam.setGoodsCd(param.getGoodsCd());
  1042. checkParam.setItemCd(param.getItemCds()[i]);
  1043. checkParam.setOptCd(param.getOptCds()[i]);
  1044. checkParam.setGoodsQty(param.getGoodsQty());
  1045. checkParam.setGoodsType(param.getGoodsType());
  1046. String stockResult = goodsService.getCheckStock(checkParam);
  1047. if (!"SUCCESS".equals(stockResult)) {
  1048. result.put("status", "FAIL");
  1049. result.put("message", stockResult);
  1050. return result;
  1051. }
  1052. }
  1053. // 각 구성상품의 품절 여부 체크 후 최소, 최대 상품 수량 체크
  1054. if (goods.getMinOrdQty() > param.getGoodsQty()) {
  1055. result.put("status", "FAIL");
  1056. result.put("message", "해당 상품의 최소 주문 수량은 " + goods.getMinOrdQty() + "개 입니다.");
  1057. return result;
  1058. } else if (goods.getMaxOrdQty() < param.getGoodsQty()) {
  1059. result.put("status", "FAIL");
  1060. result.put("message", "해당 상품의 최대 주문 수량은 " + goods.getMaxOrdQty() + "개 입니다.");
  1061. return result;
  1062. }
  1063. StringBuilder sb = new StringBuilder();
  1064. if(TscConstants.GoodsType.SET.value().equals(param.getGoodsType())) {
  1065. // 장바구니 보유 CART_SQ 쿼리
  1066. for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
  1067. 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 = ");
  1068. if (param.getCustNo() == 0) {
  1069. sb.append(param.getCustNo()).append("\n AND JSESSION_ID = '").append(param.getJsessionId()).append("'");
  1070. } else {
  1071. sb.append(param.getCustNo());
  1072. }
  1073. 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' ");
  1074. if (i < param.getCartDtlSqArr().length - 1) {
  1075. sb.append("\n UNION ALL \n");
  1076. }
  1077. }
  1078. param.setItemCdSql(sb.toString());
  1079. param.setCartGb(TscConstants.CartGb.CART.value());
  1080. // 장바구니내 같은 상품 확인
  1081. param.setNotCartSq(param.getCartSq()); // 수정 장바구니 번호 제외
  1082. Collection<Cart> cartList = cartDao.selectHasSetItemCartList(param);
  1083. // 동일 상품 존재시
  1084. if (cartList != null && cartList.size() > 0) { // 장바구니 기존재
  1085. if (cartList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
  1086. result.put("status", "FAIL");
  1087. result.put("message", "장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
  1088. return result;
  1089. } else {
  1090. // 기존 존재 장바구니 UPDATE
  1091. Cart cart = new Cart();
  1092. cart.setCartSq(cartList.iterator().next().getCartSq());
  1093. cart.setGoodsQty(param.getGoodsQty());
  1094. cart.setAfLinkCd(param.getAfLinkCd());
  1095. cart.setIthrCd(param.getIthrCd());
  1096. cart.setContentsLoc(param.getContentsLoc());
  1097. cart.setPlanDtlSq(param.getPlanDtlSq());
  1098. cart.setUpdNo(param.getUpdNo());
  1099. cart.setGoodsCd(param.getGoodsCd());
  1100. cart.setCustNo(param.getCustNo());
  1101. cart.setRegNo(param.getRegNo());
  1102. cartDao.updateCartInfo(cart); // 장바구니 정보 수정
  1103. // 장바구니 삭제
  1104. int[] cartSqArr = {param.getCartSq()};
  1105. param.setCartSqArr(cartSqArr);
  1106. cartDao.deleteCart(param);
  1107. cartDao.deleteCartDetail(param);
  1108. }
  1109. } else { // 동일 상품 없을 시 UPDATE
  1110. cartDao.updateCartGoodsQty(param); // 장바구니 마스터 정보 저장
  1111. for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
  1112. param.setItemCd(param.getItemCds()[i]);
  1113. param.setCartDtlSq(param.getCartDtlSqArr()[i]);
  1114. param.setOptCd(param.getOptCds()[i]);
  1115. cartDao.updateCartDetail(param); // 장바구니 상세 저장
  1116. }
  1117. }
  1118. } else {
  1119. param.setCartGb(TscConstants.CartGb.CART.value());
  1120. param.setNotCartSq(param.getCartSq()); // 수정 장바구니 번호 제외
  1121. param.setOptCd(param.getOptCds()[0]);
  1122. Collection<Integer> cartSqList = cartDao.selectHasNormalDealItemCartList(param);
  1123. if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
  1124. if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
  1125. result.put("status", "FAIL");
  1126. result.put("message", "장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
  1127. return result;
  1128. } else {
  1129. param.setCartSq(cartSqList.iterator().next());
  1130. cartDao.updateCartInfo(param); // 장바구니 기존 데이터에 UPDATE(수량증가)
  1131. // 이전 장바구니에 수정되었으므로 현재 수정된 장바구니 데이터 삭제
  1132. int[] delCartSq = {param.getNotCartSq()};
  1133. param.setCartSqArr(delCartSq);
  1134. cartDao.deleteCart(param); // 현재 장바구니 삭제
  1135. cartDao.deleteCartDetail(param); // 현재 장바구니 삭제
  1136. }
  1137. } else {
  1138. cartDao.updateCartGoodsQty(param); // 장바구니 마스터 정보 저장
  1139. param.setItemCd(param.getItemCds()[0]);
  1140. param.setCartDtlSq(param.getCartDtlSqArr()[0]);
  1141. param.setOptCd(param.getOptCds()[0]);
  1142. cartDao.updateCartDetail(param); // 장바구니 상세 저장
  1143. }
  1144. }
  1145. result.put("status", "SUCCESS");
  1146. return result;
  1147. }
  1148. /**
  1149. * 마이페이지 장바구니 담기 관련 정보 조회
  1150. *
  1151. * @param Cart
  1152. * @return Collection<Cart>
  1153. * @author card007
  1154. * @since 2021. 03. 26
  1155. */
  1156. public Collection<Cart> getAddCartInfoForMypage(Cart cart) {
  1157. return cartDao.getAddCartInfoForMypage(cart);
  1158. }
  1159. /**
  1160. * 장바구니 주문하기 버튼 클릭시 재고 및 상태 체크
  1161. * @param Order
  1162. * @return Collection<Order>
  1163. * @author xodud1202
  1164. * @since 2021. 04. 01
  1165. */
  1166. public Collection<Order> getOrderListConditionCheck(Order param) {
  1167. int custNo = 0;
  1168. if(TsfSession.isLogin()) {
  1169. custNo = TsfSession.getInfo().getCustNo();
  1170. } else {
  1171. param.setJsessionId(TsfSession.getSessionId());
  1172. }
  1173. if(param.getCustNo() > 0 && custNo == 0) {
  1174. return null;
  1175. }
  1176. Collection<Order> cartGoodsList = cartDao.getCartGoodsList(param);
  1177. for(Order order : cartGoodsList) {
  1178. if("Y".equals(order.getSoldoutYn())) {
  1179. if(order.getOrdCanQty() < order.getGoodsQty()) {
  1180. Collection<Order> conditionList = cartDao.getCartDetailInfo(order);
  1181. for(Order condition : conditionList) {
  1182. if("Y".equals(condition.getSoldoutYn())) {
  1183. order.setItemCd(condition.getItemCd());
  1184. order.setColorNm(condition.getColorNm());
  1185. order.setOptCd2(condition.getOptCd2());
  1186. order.setMaxOrdQty(condition.getMaxOrdQty());
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. return cartGoodsList;
  1193. }
  1194. /**
  1195. * 장바구니 최소/최대 주문 수량으로 변경
  1196. * @param Order
  1197. * @return Collection<Order>
  1198. * @author xodud1202
  1199. * @since 2021. 04. 02
  1200. */
  1201. @Transactional("shopTxnManager")
  1202. public Order updateCartGoodsQty(Cart param) {
  1203. if(TsfSession.isLogin()) {
  1204. param.setCustNo(TsfSession.getInfo().getCustNo());
  1205. param.setUpdNo(param.getCustNo());
  1206. } else {
  1207. param.setCustNo(0);
  1208. param.setUpdNo(0);
  1209. }
  1210. Order order = new Order();
  1211. order.setChgQty(cartDao.updateCartGoodsQty(param));
  1212. return order;
  1213. }
  1214. public Collection<Order> selectTmtbSalesValueList(Goods param) {
  1215. List<Integer> arr = Arrays.asList(param.getArrTmtbSq());
  1216. return cartDao.selectTmtbSectionValList(arr);
  1217. }
  1218. public Collection<Goods> selectTmtbSalesGoodsOptCd(Goods param) {
  1219. Goods goods = new Goods();
  1220. if(TsfSession.isLogin()) {
  1221. goods.setCustNo(TsfSession.getInfo().getCustNo());
  1222. } else {
  1223. goods.setCustNo(0);
  1224. }
  1225. goods.setFrontGb(TsfSession.getFrontGb());
  1226. goods.setGoodsCd(param.getGoodsCd());
  1227. return goodsDao.getDelvFeeSaveGoodsList(goods);
  1228. }
  1229. /**
  1230. * 장바구니 담긴 상품 전체 조회
  1231. * @param param
  1232. * @return
  1233. * @author xodud1202
  1234. * @since 2021. 07. 06
  1235. */
  1236. public Collection<Cart> getAllCartList(Cart param) {
  1237. return cartDao.getAllCartList(param);
  1238. }
  1239. }