TsfCartService.java 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  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. cartDao.insertCartHst(cart); // 장바구니 수정 이력 저장
  353. }
  354. } else {
  355. cartDao.insertCartInfo(cart); // 장바구니 마스터 정보 저장
  356. cartDao.insertCartHst(cart); // 장바구니 이력 정보 저장
  357. cartSqs.add(cart.getCartSq());
  358. sendCartSqList.add(cart.getCartSq() + "");
  359. for (Cart param : cartInfos) {
  360. param.setCartSq(cart.getCartSq());
  361. param.setRegNo(cart.getRegNo());
  362. param.setCustNo(cart.getCustNo());
  363. param.setUpdNo(cart.getUpdNo());
  364. cartDao.insertCartDetailInfo(param); // 장바구니 상세 저장
  365. cartDao.insertCartDetailHst(param); // 장바구니 상세 이력 저장
  366. }
  367. }
  368. }
  369. // 상품상세 > 바로구매 로그인 후 구매 클릭시 주문서로 송부할 장바구니번호
  370. StringBuilder cartSqComma = new StringBuilder();
  371. int i = 0;
  372. for(String cartSq : sendCartSqList) {
  373. if(i > 0) {
  374. cartSqComma.append(",");
  375. }
  376. cartSqComma.append(cartSq);
  377. i++;
  378. }
  379. if(chkGoOrderForm) {
  380. TsfSession.setAttribute("cartSqArr", cartSqComma.toString());
  381. }
  382. }
  383. @Transactional("shopTxnManager")
  384. public void saveNormalDealCartInfo(Collection<Cart> params, List<Integer> cartSqs) {
  385. Cart cart = new Cart();
  386. // 로그인 정보
  387. if(TsfSession.isLogin()) {
  388. Login login = TsfSession.getInfo();
  389. cart.setCustNo(login.getCustNo());
  390. } else {
  391. cart.setCustNo(0);
  392. }
  393. cart.setJsessionId(TscSession.getSessionId());
  394. if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "C".equals(params.iterator().next().getCartGb())) {
  395. cart.setCartGb(TscConstants.CartGb.CART.value());
  396. } else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && ("N".equals(params.iterator().next().getCartGb()) || "O".equals(params.iterator().next().getCartGb()))) {
  397. if ("P".equals(TsfSession.getFrontGb())) {
  398. cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
  399. } else {
  400. cart.setCartGb(TscConstants.CartGb.MOB_ORDER.value());
  401. }
  402. } else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "G".equals(params.iterator().next().getCartGb())) {
  403. cart.setCartGb(TscConstants.CartGb.GIFT.value());
  404. } else {
  405. cart.setCartGb(TscConstants.CartGb.CREATE_ORDER.value());
  406. }
  407. // 세션 추가용 변수
  408. String cartGb = params.iterator().next().getCartGb();
  409. List<String> sendCartSqList = new ArrayList<String>();
  410. for(Cart item : params) {
  411. item.setCartGb(cart.getCartGb());
  412. item.setCustNo(cart.getCustNo());
  413. item.setRegNo(cart.getCustNo());
  414. item.setUpdNo(cart.getCustNo());
  415. item.setJsessionId(cart.getJsessionId());
  416. // 같은 장바구니 상품 확인
  417. Collection<Integer> cartSqList = null;
  418. if(TscConstants.CartGb.CART.value().equals(cart.getCartGb())) {
  419. cartSqList = cartDao.selectHasNormalDealItemCartList(item);
  420. }
  421. if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
  422. if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
  423. throw new IllegalStateException("장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
  424. } else {
  425. item.setCartSq(cartSqList.iterator().next());
  426. cartSqs.add(item.getCartSq());
  427. cartDao.updateCartInfo(item);
  428. cartDao.insertCartHst(item); // 장바구니 수정 이력 저장
  429. }
  430. } else {
  431. cartDao.insertCartInfo(item); // 장바구니 마스터 정보 저장
  432. cartDao.insertCartHst(item); // 장바구니 수정 이력 저장
  433. cartDao.insertCartDetailInfo(item); // 장바구니 상세 저장
  434. cartDao.insertCartDetailHst(item); // 장바구니 수정 이력 저장
  435. cartSqs.add(item.getCartSq());
  436. sendCartSqList.add(item.getCartSq() + "");
  437. }
  438. }
  439. StringBuilder cartSqComma = new StringBuilder();
  440. int i = 0;
  441. for(String cartSq : sendCartSqList) {
  442. if(i > 0) {
  443. cartSqComma.append(",");
  444. }
  445. cartSqComma.append(cartSq);
  446. i++;
  447. }
  448. if (!StringUtils.isEmpty(cartGb) && ("O".equals(cartGb) || "G".equals(cartGb))) {
  449. TsfSession.setAttribute("cartSqArr", cartSqComma.toString());
  450. }
  451. }
  452. // 장바구니 상품 리스트 조회 서비스
  453. @SuppressWarnings("unchecked")
  454. public Order getCartGoodsList(Order order) {
  455. //ModelAndView result = new ModelAndView();
  456. GagaMap result = new GagaMap(); // return
  457. List<Integer> cartSqs = new ArrayList<Integer>(); // 품절 제외 장바구니 리스트
  458. // 로그인 체크
  459. if(TsfSession.isLogin()) {
  460. order.setCustNo(TsfSession.getInfo().getCustNo());
  461. } else {
  462. order.setCustNo(0);
  463. }
  464. order.setFrontGb(TsfSession.getFrontGb());
  465. order.setJsessionId(TscSession.getSessionId());
  466. // 장바구니 상품 조회
  467. Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);
  468. // 품절 아닌 상품만 체크
  469. for (Order goods : cartGoodsList) {
  470. if ("N".equals(goods.getSoldoutYn()) && "Y".equals(goods.getOrdCanYn()) && "Y".equals(goods.getNewCustCanYn()) && goods.getGoodsQty() >= goods.getMinOrdQty() && goods.getGoodsQty() <= goods.getMaxOrdQty()) {
  471. cartSqs.add(goods.getCartSq());
  472. }
  473. goods.setOrgSavePntAmt((int) (goods.getCurrPrice() * goods.getPntRate() / 100.0));
  474. }
  475. order.setCartSqArr(cartSqs.stream().mapToInt(Integer::intValue).toArray());
  476. if(cartSqs.size() > 0) {
  477. // 다다익선 할인 상품 조회 (품절 상품 제외)
  478. Collection<Order> moreBetterAmtList = new ArrayList<Order>();
  479. //if(order.getCustNo() > 0) { // 비회원도 다다익선 적용 여부 및 금액 노출되도록 수정. (한수인리더 요청) :: 20210517
  480. order.setCartYn("Y");
  481. moreBetterAmtList = getMoreBetterAmtList(order);
  482. //}
  483. // 다다익선 할인 정보 및 상품 정보 장바구니에 등록
  484. for (Order cart : cartGoodsList) {
  485. for (Order info : moreBetterAmtList) {
  486. if (cart.getCartSq().equals(info.getCartSq())) {
  487. cart.setTmtbDcAmt(info.getTmtbDcAmt());
  488. cart.setApplyAmtSectionYn(info.getApplyAmtSectionYn());
  489. cart.setApplyQtySectionYn(info.getApplyQtySectionYn());
  490. cart.setQtyTmtbNm(info.getQtyTmtbNm());
  491. cart.setAmtTmtbNm(info.getAmtTmtbNm());
  492. cart.setQtyTmtbSq(info.getQtyTmtbSq());
  493. cart.setAmtTmtbSq(info.getAmtTmtbSq());
  494. }
  495. }
  496. if (cart.getTmtbDcAmt() == 0) {
  497. cart.setTmtbDcAmt(cart.getCurrPrice());
  498. }
  499. if(cart.getPntRate() > 0) {
  500. cart.setSavePntAmt((int) (cart.getTmtbDcAmt() * cart.getPntRate() / 100.0));
  501. } else {
  502. cart.setSavePntAmt(0);
  503. }
  504. }
  505. }
  506. // 자사 / 입점업체 리스트 분리
  507. order = getCartDelvGoodsCntList(cartGoodsList, order);
  508. // 장바구니 업체별 배송비 계산
  509. setCartListDelvFeeInfo(cartGoodsList, order);
  510. // 총계 금액 계산
  511. setCartListTotAmtInfo(cartGoodsList, order);
  512. // 전체 장바구니 정보
  513. order.setDelvAllCartList(cartGoodsList);
  514. order.setAllCartCnt(cartGoodsList.size());
  515. return order;
  516. }
  517. // 장바구니 수량 계산(품절제거)
  518. @SuppressWarnings("unchecked")
  519. public Order getCartNotSoldoutCnt() {
  520. Order order = new Order();
  521. //ModelAndView result = new ModelAndView();
  522. GagaMap result = new GagaMap(); // return
  523. List<Integer> cartSqs = new ArrayList<Integer>(); // 품절 제외 장바구니 리스트
  524. // 로그인 체크
  525. if(TsfSession.isLogin()) {
  526. order.setCustNo(TsfSession.getInfo().getCustNo());
  527. } else {
  528. order.setCustNo(0);
  529. }
  530. order.setFrontGb(TsfSession.getFrontGb());
  531. order.setJsessionId(TscSession.getSessionId());
  532. // 장바구니 상품 조회
  533. Collection<Order> cartGoodsList = cartDao.getCartGoodsList(order);
  534. // 총계 금액 계산 (수량 계산 내부에 존재)
  535. setCartListTotAmtInfo(cartGoodsList, order);
  536. return order;
  537. }
  538. /**
  539. * 다다익선 할인 금액 조회
  540. * @param param
  541. * param.cartSqArr[] : 필수
  542. * @return String
  543. * @author xodud1202
  544. * @since 2021. 01. 28
  545. */
  546. public Collection<Order> getMoreBetterAmtList(Order param) {
  547. // 장바구니 상품 조회
  548. param.setFrontGb(TsfSession.getFrontGb());
  549. Collection<Order> cartGoodsList = coreOrderService.getCartGoodsList(param);
  550. String cartYn = "N";
  551. if(!StringUtils.isEmpty(param.getCartYn())) {
  552. cartYn = param.getCartYn();
  553. }
  554. if(param.getCustNo() > 0 || "Y".equals(cartYn)) {
  555. // 장바구니 내 수량 다다익선 적용 가능 리스트 조회 (등록된 기본,적용 상품 정보 전체 조회)
  556. Collection<Order> tmtbApplyList = cartDao.selectMoreBetterApplyCartList(param);
  557. // 장바구니 등록 다다익선 일련번호 지정
  558. List<Integer> applySq = new ArrayList<Integer>();
  559. for(Order tmtbApply : tmtbApplyList) {
  560. if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb()) || TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
  561. if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getQtyGoodsGb())) {
  562. applySq.add(tmtbApply.getQtyTmtbSq());
  563. }
  564. if(TscConstants.GoodsGb.BASE.value().equals(tmtbApply.getAmtGoodsGb())) {
  565. applySq.add(tmtbApply.getAmtTmtbSq());
  566. }
  567. }
  568. }
  569. param.setTmtbSqs(applySq.stream().mapToInt(Integer::intValue).toArray());
  570. // 섹션 정보 조회 후 할인 여부 판단
  571. Collection<Order> tmtbSectionList = cartDao.selectTmtbSectionValList(applySq);
  572. for(Order applyInfo : tmtbApplyList) { // 기준 상품 및 다다익선 정보 조회
  573. // 다다익선 할인 조건 조회
  574. for(Order section : tmtbSectionList) {
  575. if(applyInfo.getQtyTmtbSq() == section.getTmtbSq()) {
  576. // 수량 적용 다다익선
  577. if (section.getSectionVal() <= applyInfo.getQtyTmtbSumQty()) { // 장바구니 수량 할인 기준 달성시
  578. if (applyInfo.getQtySectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
  579. applyInfo.setQtySectionVal(section.getSectionVal());
  580. applyInfo.setApplyQtySectionYn("Y");
  581. applyInfo.setQtyDcWay(section.getDcWay());
  582. applyInfo.setQtyDcVal(section.getDcVal());
  583. }
  584. } else {
  585. if (applyInfo.getQtySectionVal() < 1 && applyInfo.getQtyGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
  586. applyInfo.setApplyQtySectionYn("N");
  587. }
  588. }
  589. }
  590. if (applyInfo.getAmtTmtbSq() == section.getTmtbSq()) {
  591. // 금액 적용 다다익선
  592. if(section.getSectionVal() <= applyInfo.getAmtTmtbSumAmt()) { // 장바구니 수량 할인 기준 달성시
  593. if(applyInfo.getAmtSectionVal() <= section.getSectionVal()) { // 기존 달성된 기준치보다 할인폭이 클 경우 기준할인 수정
  594. applyInfo.setAmtSectionVal(section.getSectionVal());
  595. applyInfo.setApplyAmtSectionYn("Y");
  596. applyInfo.setAmtDcWay(section.getDcWay());
  597. applyInfo.setAmtDcVal(section.getDcVal());
  598. }
  599. } else {
  600. if(applyInfo.getAmtSectionVal() < 1 && applyInfo.getAmtGoodsGb().equals(TscConstants.GoodsGb.BASE.value())) {
  601. applyInfo.setApplyAmtSectionYn("N");
  602. }
  603. }
  604. }
  605. }
  606. }
  607. // 수량 다다익선에 맞춰 정렬
  608. Collections.sort((ArrayList<Order>) tmtbApplyList, new Comparator<Order>() {
  609. @Override
  610. public int compare(Order c1, Order c2) {
  611. return c1.getQtyTmtbSq() - c2.getQtyTmtbSq();
  612. }
  613. });
  614. // 수량 다다익선 적용 상품 할인 금액 계산
  615. int leftAmt = 0;
  616. int i = 0;
  617. for(Order resultAmt : tmtbApplyList) {
  618. int tempAmt = 0;
  619. if("Y".equals(resultAmt.getApplyQtySectionYn()) && resultAmt.getQtyTmtbSq() > 0) {
  620. if (TscConstants.DcWay.AMT.value().equals(resultAmt.getQtyDcWay())) { // 할인 방식 금액일경우
  621. i++;
  622. tempAmt = resultAmt.getCurrPrice();
  623. if (i == 1) {
  624. leftAmt = resultAmt.getQtyDcVal();
  625. }
  626. if (i == resultAmt.getQtyTmtbCnt()) {
  627. resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
  628. resultAmt.setTmtb1DcAmt(leftAmt); // tmtb1 할인금액
  629. leftAmt = 0;
  630. i = 0;
  631. } else {
  632. double tempDcAmt = resultAmt.getQtyDcVal() * ((tempAmt) / (double)resultAmt.getQtyTmtbSumAmt());
  633. leftAmt -= (int)tempDcAmt;
  634. resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
  635. resultAmt.setTmtb1DcAmt((int)tempDcAmt); // tmtb1 할인금액
  636. }
  637. } else { // 할인 방식 할인율일 경우
  638. tempAmt = resultAmt.getCurrPrice();
  639. tempAmt = (tempAmt - (int) (tempAmt * (resultAmt.getQtyDcVal() / 100.0)));
  640. resultAmt.setTmtbDcAmt(tempAmt);
  641. // 2021.04.29 다다익선할인금액수정
  642. resultAmt.setTmtb1DcAmt((int) (resultAmt.getCurrPrice() * (resultAmt.getQtyDcVal() / 100.0))); // tmtb1 할인금액
  643. }
  644. }
  645. if (resultAmt.getTmtbDcAmt() > 0) {
  646. resultAmt.setCurrPrice(resultAmt.getTmtbDcAmt());
  647. }
  648. }
  649. // 금액 다다익선에 맞춰 정렬
  650. Collections.sort((ArrayList<Order>) tmtbApplyList, new Comparator<Order>() {
  651. @Override
  652. public int compare(Order c1, Order c2) {
  653. return c1.getAmtTmtbSq() - c2.getAmtTmtbSq();
  654. }
  655. });
  656. // 금액 다다익선 할인 계산
  657. leftAmt = 0;
  658. i = 0;
  659. for(Order resultAmt : tmtbApplyList) {
  660. int tempAmt = 0;
  661. if("Y".equals(resultAmt.getApplyAmtSectionYn()) && resultAmt.getAmtTmtbSq() > 0) {
  662. if (TscConstants.DcWay.AMT.value().equals(resultAmt.getAmtDcWay())) { // 할인 방식 금액일경우
  663. i++;
  664. tempAmt = resultAmt.getCurrPrice();
  665. if (i == 1) {
  666. leftAmt = resultAmt.getAmtDcVal();
  667. }
  668. if (i == resultAmt.getAmtTmtbCnt()) {
  669. resultAmt.setTmtbDcAmt(tempAmt - leftAmt);
  670. resultAmt.setTmtb2DcAmt(leftAmt); // tmtb1 할인금액
  671. leftAmt = 0;
  672. i = 0;
  673. } else {
  674. double tempDcAmt = resultAmt.getAmtDcVal() * ((tempAmt) / (double)resultAmt.getAmtTmtbSumAmt());
  675. leftAmt -= (int)tempDcAmt;
  676. resultAmt.setTmtbDcAmt(tempAmt - (int)tempDcAmt);
  677. resultAmt.setTmtb2DcAmt((int)tempDcAmt); // tmtb1 할인금액
  678. }
  679. } else { // 할인 방식 할인율일 경우
  680. tempAmt = resultAmt.getCurrPrice();
  681. tempAmt = (tempAmt - (int) (tempAmt * (resultAmt.getAmtDcVal() / 100.0)));
  682. resultAmt.setTmtbDcAmt(tempAmt);
  683. // 2021.04.29 다다익선할인금액수정
  684. resultAmt.setTmtb2DcAmt((int) (resultAmt.getCurrPrice() * (resultAmt.getAmtDcVal() / 100.0))); // tmtb2 할인금액
  685. }
  686. }
  687. }
  688. // 장바구니 정보에 수량 다다익선 정보 입력
  689. for (Order cart : cartGoodsList) {
  690. for (Order apply : tmtbApplyList) {
  691. if (cart.getCartSq().equals(apply.getCartSq())) {
  692. // 2021.02.24 jsh77b
  693. cart.setTmtb1DcAmt(apply.getTmtb1DcAmt());
  694. cart.setTmtb2DcAmt(apply.getTmtb2DcAmt());
  695. cart.setTmtbDcAmt(apply.getTmtbDcAmt());
  696. log.info("cart.getTmtb1DcAmt() ::: {}", cart.getTmtb1DcAmt());
  697. log.info("cart.getTmtb2DcAmt() ::: {}", cart.getTmtb2DcAmt());
  698. log.info("cart.getTmtbDcAmt() ::: {}", cart.getTmtbDcAmt());
  699. cart.setApplyQtySectionYn(apply.getApplyQtySectionYn());
  700. cart.setQtyTmtbNm(apply.getQtyTmtbNm());
  701. cart.setQtyTmtbSq(apply.getQtyTmtbSq());
  702. cart.setApplyAmtSectionYn(apply.getApplyAmtSectionYn());
  703. cart.setAmtTmtbNm(apply.getAmtTmtbNm());
  704. cart.setAmtTmtbSq(apply.getAmtTmtbSq());
  705. }
  706. }
  707. }
  708. }
  709. //return result;
  710. return cartGoodsList;
  711. }
  712. /**
  713. * 장바구니 배송단위별 상품 정보 조회
  714. *
  715. * @param cartGoodsList
  716. * @author xodud1202
  717. * @since 2021. 02. 02
  718. */
  719. public Order getCartDelvGoodsCntList(Collection<Order> cartGoodsList, Order paramOrder) {
  720. // 1. 장바구니 상품 배송단위별 건수 체크 로직 (자사:총알배송, 자사:일반배송, 입점업체, 예약배송)
  721. Order delvOrder = new Order();
  722. Collection<Order> shotCartList = new ArrayList<Order>();
  723. Collection<Order> wmsCartList = new ArrayList<Order>();
  724. Collection<Order> delvCartList = new ArrayList<Order>();
  725. for (Order order : cartGoodsList) {
  726. // 1.1 세트상품 옵션별 배열로 담기
  727. if (order.getItemNm().contains("!@!")) {
  728. order.setItemNmArr(order.getItemNm().split("!@!"));
  729. order.setOptCdArr(order.getOptCd().split(","));
  730. order.setItemQtyArr(order.getItemQtyr().split(","));
  731. order.setOptCd1Arr(order.getOptCd1().split(","));
  732. order.setOptCd2Arr(order.getOptCd2().split(","));
  733. order.setColorNmArr(order.getColorNm().split(","));
  734. } else {
  735. String[] arr = {order.getItemNm()}, arr2 = {order.getOptCd1()}, arr3 = {order.getOptCd2()}, arr4 = {order.getItemQtyr()}, arr5 = {order.getColorNm()};
  736. order.setItemNmArr(arr);
  737. order.setOptCd1Arr(arr2);
  738. order.setOptCd2Arr(arr3);
  739. order.setItemQtyArr(arr4);
  740. order.setColorNmArr(arr5);
  741. }
  742. // 1.3 배송정책별 상품 구분
  743. if ("SHOT".equals(order.getCartDelvFeeCd())) {
  744. if(paramOrder.getShotDelvUseYn() != null && "N".equals(paramOrder.getShotDelvUseYn())) {
  745. wmsCartList.add(order);
  746. } else {
  747. shotCartList.add(order);
  748. }
  749. } else if ("WMS".equals(order.getCartDelvFeeCd())) {
  750. wmsCartList.add(order);
  751. } else {
  752. delvCartList.add(order);
  753. }
  754. }
  755. delvOrder.setShotCartList(shotCartList); // 자사 총알배송 상품 목록
  756. delvOrder.setWmsCartList(wmsCartList); // 자사 일반상품 목록
  757. delvOrder.setDelvCartList(delvCartList); // 입점 업체 상품 목록
  758. return delvOrder;
  759. }
  760. /**
  761. * 장바구니 배송단위별 배송비 계산
  762. *
  763. * @param params
  764. * @author xodud1202
  765. * @since 2021. 02. 02
  766. */
  767. public void setCartListDelvFeeInfo(Collection<Order> params, Order order) {
  768. Order delvInfo = new Order();
  769. List<Integer> cartSqArr = new ArrayList<Integer>();
  770. // 장바구니 일련번호 세팅
  771. for (Order param : params) {
  772. cartSqArr.add(param.getCartSq());
  773. }
  774. delvInfo.setCartSqArr(cartSqArr.stream().mapToInt(Integer::intValue).toArray());
  775. // 장바구니 업체별 배송비 정보 조회
  776. Collection<Order> delvFeeInfo = new ArrayList<Order>();
  777. if(delvInfo.getCartSqArr() != null && delvInfo.getCartSqArr().length > 0) {
  778. delvFeeInfo = cartDao.getCartListDelvFeeInfoList(delvInfo);
  779. }
  780. // 업체별 상품 합계 금액 저장
  781. int compCnt = 0;
  782. String delvYn;
  783. Order lastCompCheck = new Order();
  784. for (Order delv : delvFeeInfo) {
  785. lastCompCheck = null;
  786. compCnt = 0;
  787. delvYn = "N";
  788. for (Order param : params) {
  789. if (param.getDelvFeeCd().equals(delv.getDelvFeeCd())) {
  790. compCnt++;
  791. if("N".equals(param.getSoldoutYn()) && "Y".equals(param.getOrdCanYn()) && "Y".equals(param.getNewCustCanYn()) && param.getGoodsQty() >= param.getMinOrdQty() && param.getGoodsQty() <= param.getMaxOrdQty()) {
  792. delv.setCompSumPrice(delv.getCompSumPrice() + param.getCurrPrice());
  793. delvYn = "Y";
  794. }
  795. if (compCnt == 1) {
  796. param.setFirstCompYn("Y");
  797. }
  798. // 한 업체의 마지막 params를 확인
  799. lastCompCheck = param;
  800. }
  801. }
  802. if(lastCompCheck != null) {
  803. // 한 업체의 마지막 상품 체크
  804. lastCompCheck.setAddDelvFeeYn("Y");
  805. // 배송 상품 존재 여부
  806. lastCompCheck.setDelvYn(delvYn);
  807. // 배송상품 금액차이
  808. }
  809. }
  810. int wmsSumPrice = 0, wmsMinOrdAmt = 0, wmsDelvFee = 0;
  811. // 장바구니 업체별 합계 금액으로 무료배송 여부 저장
  812. for (Order param : params) {
  813. // 입점업체 배송비
  814. for (Order delv : delvFeeInfo) {
  815. if (param.getDelvFeeCd().equals(delv.getDelvFeeCd()) && !"WMS".equals(param.getDelvFeeCd())) {
  816. param.setCompCnt(delv.getCompCnt());
  817. param.setDelvFeeCrite(delv.getDelvFeeCrite());
  818. if (TscConstants.DelvFeeCrite.FREE.value().equals(delv.getDelvFeeCrite())) {
  819. param.setDelvFee(0);
  820. } else if (TscConstants.DelvFeeCrite.NORMAL.value().equals(delv.getDelvFeeCrite()) && delv.getCompSumPrice() > delv.getMinOrdAmt()) {
  821. param.setDelvFee(0);
  822. } else {
  823. param.setCompSumPrice(delv.getCompSumPrice());
  824. param.setMinOrdAmt(delv.getMinOrdAmt());
  825. param.setDelvFee(delv.getDelvFee());
  826. }
  827. }
  828. }
  829. // 자사 상품 가격 계산
  830. if("WMS".equals(param.getDelvFeeCd())) {
  831. if("N".equals(param.getSoldoutYn()) && "Y".equals(param.getOrdCanYn())&& "Y".equals(param.getNewCustCanYn()) && param.getGoodsQty() >= param.getMinOrdQty() && param.getGoodsQty() <= param.getMaxOrdQty()) {
  832. wmsSumPrice = wmsSumPrice + param.getCurrPrice();
  833. wmsMinOrdAmt = param.getMinOrdAmt();
  834. wmsDelvFee = param.getDelvFee();
  835. }
  836. }
  837. }
  838. // 자사 배송비 등록
  839. if(params.size() > 0) {
  840. if (wmsSumPrice > wmsMinOrdAmt) {
  841. order.setWmsDelvFee(0);
  842. } else {
  843. order.setWmsDelvFee(wmsDelvFee);
  844. order.setCompSumPrice(wmsSumPrice);
  845. order.setMinOrdAmt(wmsMinOrdAmt);
  846. }
  847. // 배송 상품 존재 여부
  848. if(wmsSumPrice > 0) {
  849. order.setDelvYn("Y");
  850. }
  851. }
  852. }
  853. /**
  854. * 장바구니 배송비 합계금액 계산
  855. * @param cartGoodsList
  856. * @param order
  857. * @author xodud1202
  858. * @since 2021. 02. 02
  859. */
  860. public void setCartListTotAmtInfo(Collection<Order> cartGoodsList, Order order) {
  861. // 장바구니 합계 금액 계산
  862. int notSoldoutCnt = 0;
  863. for(Order cart : cartGoodsList) {
  864. if("N".equals(cart.getSoldoutYn()) && "Y".equals(cart.getOrdCanYn()) && "Y".equals(cart.getNewCustCanYn()) && cart.getGoodsQty() >= cart.getMinOrdQty() && cart.getGoodsQty() <= cart.getMaxOrdQty()) {
  865. notSoldoutCnt++;
  866. // 상품 금액 합계
  867. order.setSumOrdAmt(order.getSumOrdAmt() + cart.getCurrPrice());
  868. order.setSumRealPayAmt(order.getSumRealPayAmt() + cart.getTmtbDcAmt());
  869. order.setSumListPrice(order.getSumListPrice() + cart.getListPrice());
  870. // 배송비 합계
  871. if ("Y".equals(cart.getFirstCompYn())) {
  872. order.setTotDelvFee(order.getTotDelvFee() + cart.getDelvFee());
  873. }
  874. }
  875. }
  876. // 자사 배송비 추가
  877. order.setTotDelvFee(order.getTotDelvFee() + order.getWmsDelvFee());
  878. // 상품 할인금액 총계
  879. // order.setTotDcAmt(order.getSumRealPayAmt() - order.getSumOrdAmt()); /* 다다익선 금액이 상품금액일 경우 해당 주석 제거 */
  880. order.setTotDcAmt(order.getSumRealPayAmt() - order.getSumListPrice());
  881. // 장바구니 총액 계산 상품 총 수량
  882. order.setTotCartCnt(notSoldoutCnt);
  883. order.setCartGoodsList(cartGoodsList);
  884. }
  885. @Transactional("shopTxnManager")
  886. public void deleteCart(Cart param) {
  887. cartDao.deleteCart(param);
  888. }
  889. /**
  890. * 로그인 후 장바구니 Update
  891. * 회원 로그인 후 호출됨으로 세션 정보 있음
  892. * @param custNo - 고객번호
  893. * @author gagamel
  894. * @since 2021. 2. 24
  895. */
  896. @Transactional("shopTxnManager")
  897. public void updateCartToAfterLogin(Integer custNo) {
  898. Cart cart = new Cart();
  899. cart.setJsessionId(TsfSession.getSessionId());
  900. cart.setCustNo(custNo);
  901. cart.setUpdNo(custNo);
  902. log.info("cart: {}", cart);
  903. // 로그인 후 고객번호 Update
  904. int procCnt = cartDao.updateCartOfCustNo(cart);
  905. if (procCnt > 0) {
  906. // 로그인 후 처리할 장바구니 목록
  907. Collection<Cart> cartList = cartDao.getCartListAfterLogin(cart);
  908. for (Cart updCart : cartList) {
  909. updCart.setCustNo(custNo);
  910. updCart.setRegNo(custNo);
  911. // 로그인 후 장바구니 수정
  912. cartDao.updateCartAfterLogin(updCart);
  913. // 로그인 후 장바구니단품 삭제
  914. cartDao.deleteCartItemAfterLogin(updCart);
  915. // 로그인 후 장바구니 삭제
  916. cartDao.deleteCartAfterLogin(updCart);
  917. // 로그인 후 장바구니 이력 생성(삭제할 장바구니번호가 있을 때만)
  918. if (updCart.getDelCartSq() > 0) {
  919. cartDao.createCartHistoryAfterLogin(updCart);
  920. }
  921. }
  922. }
  923. }
  924. public Collection<Goods> getDelvFeeSaveGoodsList(Order param) {
  925. Goods goods = new Goods();
  926. if(StringUtils.isEmpty(param.getDelvFeeCd())) {
  927. return null;
  928. }
  929. if("WMS".equals(param.getDelvFeeCd())) {
  930. goods.setSelfGoodsYn("Y");
  931. } else {
  932. goods.setDelvFeeCd(param.getDelvFeeCd());
  933. }
  934. goods.setPrice(param.getDelvFeeSaveGoodsAmt());
  935. goods.setFrontGb(TsfSession.getFrontGb());
  936. if(TsfSession.isLogin()) {
  937. goods.setCustNo(TsfSession.getInfo().getCustNo());
  938. } else {
  939. goods.setCustNo(0);
  940. }
  941. return goodsDao.getDelvFeeSaveGoodsList(goods);
  942. }
  943. public Cart getCartGoodsInfo(Cart param) {
  944. // 장바구니 상품 마스터 정보 조회
  945. param.setFrontGb(TsfSession.getFrontGb());
  946. Cart cart = cartDao.selectCartGoodsInfo(param);
  947. if(cart == null) {
  948. throw new IllegalStateException("장바구니 상품 정보가 없습니다.\n새로고침 후 다시 시도해주세요.");
  949. }
  950. if(TscConstants.GoodsStat.SOLDOUT.value().equals(cart.getGoodsStat())) {
  951. cart.setSoldoutYn("Y");
  952. } else {
  953. cart.setSoldoutYn("N");
  954. }
  955. // 세트 상품일 경우
  956. if(TscConstants.GoodsType.SET.value().equals(cart.getGoodsType())) {
  957. cart.setCartCompsList(cartDao.selectCartSetGoodsInfo(cart));
  958. for(Cart comp : cart.getCartCompsList()) {
  959. comp.setCartSq(cart.getCartSq());
  960. comp.setCartColorList(cartDao.selectCartGoodsColorList(comp));
  961. if("Y".equals(cart.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(comp.getGoodsStat())) {
  962. comp.setSoldoutYn("Y");
  963. } else {
  964. comp.setSoldoutYn("N");
  965. }
  966. for(Cart color : comp.getCartColorList()) {
  967. if("Y".equals(comp.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(color.getGoodsStat())) {
  968. color.setSoldoutYn("Y");
  969. } else {
  970. color.setSoldoutYn("N");
  971. }
  972. color.setCartSq(comp.getCartSq());
  973. color.setCartSizeList(cartDao.selectCartGoodsSizeList(color));
  974. }
  975. }
  976. cart.setCartImgList(cartDao.selectCartDelvGoodsOptionImgList(cart)); // TB_GOODS.MAIN_COLOR_CD의 이미지를 가져옴.
  977. } else { // 일반, DEAL 상품일 경우
  978. cart.setCartCompsList(new ArrayList<Cart>());
  979. cart.getCartCompsList().add(new Cart());
  980. for(Cart comp : cart.getCartCompsList()) {
  981. comp.setSoldoutYn(cart.getSoldoutYn());
  982. comp.setCartColorList(cartDao.selectCartGoodsColorList(cart));
  983. for(Cart color : comp.getCartColorList()) {
  984. if("Y".equals(comp.getSoldoutYn()) || TscConstants.GoodsStat.SOLDOUT.value().equals(color.getGoodsStat())) {
  985. color.setSoldoutYn("Y");
  986. } else {
  987. color.setSoldoutYn("N");
  988. }
  989. if(color.getCartDtlSq() > 0) {
  990. comp.setCartDtlSq(color.getCartDtlSq());
  991. comp.setColorNm(color.getCartColorNm());
  992. comp.setOptCd1(color.getOptCd1());
  993. comp.setGoodsCd(cart.getGoodsCd());
  994. }
  995. color.setCartSq(cart.getCartSq());
  996. color.setCartImgList(cartDao.selectCartSelfGoodsOptionImgList(color));
  997. color.setCartSizeList(cartDao.selectCartGoodsSizeList(color));
  998. for(Cart size : color.getCartSizeList()) {
  999. if(size.getCartDtlSq() > 0) {
  1000. comp.setOptCd(size.getCartOptCd());
  1001. comp.setOptCd2(size.getCartOptCd2());
  1002. }
  1003. }
  1004. }
  1005. }
  1006. if(!"Y".equals(cart.getSelfGoodsYn())) { // 입점 상품은 TB_GOODS_IMG.COLOR_CD = TB_GOODS.MAIN_COLOR_CD
  1007. cart.setCartImgList(cartDao.selectCartDelvGoodsOptionImgList(cart));
  1008. }
  1009. }
  1010. cart.setImgPath(env.getProperty("upload.goods.view"));
  1011. return cart;
  1012. }
  1013. @Transactional("shopTxnManager")
  1014. public GagaMap updateCartOption(Cart param) {
  1015. GagaMap result = new GagaMap();
  1016. param.setJsessionId(TsfSession.getSessionId());
  1017. param.setFrontGb(TsfSession.getFrontGb());
  1018. if(TsfSession.isLogin()) {
  1019. param.setCustNo(TsfSession.getInfo().getCustNo());
  1020. param.setRegNo(param.getCustNo());
  1021. param.setUpdNo(param.getCustNo());
  1022. } else {
  1023. param.setCustNo(0);
  1024. param.setRegNo(0);
  1025. param.setUpdNo(0);
  1026. }
  1027. // 재고 체크
  1028. Goods goods = new Goods();
  1029. goods.setGoodsCd(param.getGoodsCd());
  1030. goods.setFrontGb(TsfSession.getFrontGb());
  1031. goods.setSiteCd(TscConstants.Site.STYLE24.value());
  1032. goods = goodsService.getGoodsInfo(goods);
  1033. if (goods == null) {
  1034. result.put("status", "FAIL");
  1035. result.put("message", "상품 정보가 존재하지 않습니다.");
  1036. return result;
  1037. }
  1038. if (TscConstants.GoodsStat.SOLDOUT.value().equals(goods.getGoodsStat())) {
  1039. result.put("status", "FAIL");
  1040. result.put("message", "품절입니다.");
  1041. return result;
  1042. }
  1043. // 구성 상품 재고 확인
  1044. for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
  1045. // 상품 재고 확인
  1046. GoodsStock checkParam = new GoodsStock();
  1047. checkParam.setGoodsCd(param.getGoodsCd());
  1048. checkParam.setItemCd(param.getItemCds()[i]);
  1049. checkParam.setOptCd(param.getOptCds()[i]);
  1050. checkParam.setGoodsQty(param.getGoodsQty());
  1051. checkParam.setGoodsType(param.getGoodsType());
  1052. String stockResult = goodsService.getCheckStock(checkParam);
  1053. if (!"SUCCESS".equals(stockResult)) {
  1054. result.put("status", "FAIL");
  1055. result.put("message", stockResult);
  1056. return result;
  1057. }
  1058. }
  1059. // 각 구성상품의 품절 여부 체크 후 최소, 최대 상품 수량 체크
  1060. if (goods.getMinOrdQty() > param.getGoodsQty()) {
  1061. result.put("status", "FAIL");
  1062. result.put("message", "해당 상품의 최소 주문 수량은 " + goods.getMinOrdQty() + "개 입니다.");
  1063. return result;
  1064. } else if (goods.getMaxOrdQty() < param.getGoodsQty()) {
  1065. result.put("status", "FAIL");
  1066. result.put("message", "해당 상품의 최대 주문 수량은 " + goods.getMaxOrdQty() + "개 입니다.");
  1067. return result;
  1068. }
  1069. StringBuilder sb = new StringBuilder();
  1070. if(TscConstants.GoodsType.SET.value().equals(param.getGoodsType())) {
  1071. // 장바구니 보유 CART_SQ 쿼리
  1072. for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
  1073. 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 = ");
  1074. if (param.getCustNo() == 0) {
  1075. sb.append(param.getCustNo()).append("\n AND JSESSION_ID = '").append(param.getJsessionId()).append("'");
  1076. } else {
  1077. sb.append(param.getCustNo());
  1078. }
  1079. 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' ");
  1080. if (i < param.getCartDtlSqArr().length - 1) {
  1081. sb.append("\n UNION ALL \n");
  1082. }
  1083. }
  1084. param.setItemCdSql(sb.toString());
  1085. param.setCartGb(TscConstants.CartGb.CART.value());
  1086. // 장바구니내 같은 상품 확인
  1087. param.setNotCartSq(param.getCartSq()); // 수정 장바구니 번호 제외
  1088. Collection<Cart> cartList = cartDao.selectHasSetItemCartList(param);
  1089. // 동일 상품 존재시
  1090. if (cartList != null && cartList.size() > 0) { // 장바구니 기존재
  1091. if (cartList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
  1092. result.put("status", "FAIL");
  1093. result.put("message", "장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
  1094. return result;
  1095. } else {
  1096. // 기존 존재 장바구니 UPDATE
  1097. Cart cart = new Cart();
  1098. cart.setCartSq(cartList.iterator().next().getCartSq());
  1099. cart.setGoodsQty(param.getGoodsQty());
  1100. cart.setAfLinkCd(param.getAfLinkCd());
  1101. cart.setIthrCd(param.getIthrCd());
  1102. cart.setContentsLoc(param.getContentsLoc());
  1103. cart.setPlanDtlSq(param.getPlanDtlSq());
  1104. cart.setUpdNo(param.getUpdNo());
  1105. cart.setGoodsCd(param.getGoodsCd());
  1106. cart.setCustNo(param.getCustNo());
  1107. cart.setRegNo(param.getRegNo());
  1108. cartDao.updateCartInfo(cart); // 장바구니 정보 수정
  1109. cartDao.insertCartHst(cart); // 장바구니 수정 이력 저장
  1110. // 장바구니 삭제
  1111. int[] cartSqArr = {param.getCartSq()};
  1112. param.setCartSqArr(cartSqArr);
  1113. cartDao.deleteCart(param);
  1114. cartDao.deleteCartDetail(param);
  1115. }
  1116. } else { // 동일 상품 없을 시 UPDATE
  1117. cartDao.updateCartGoodsQty(param); // 장바구니 마스터 정보 저장
  1118. cartDao.insertCartHst(param); // 장바구니 이력 정보 저장
  1119. for(int i = 0 ; i < param.getCartDtlSqArr().length ; i++) {
  1120. param.setItemCd(param.getItemCds()[i]);
  1121. param.setCartDtlSq(param.getCartDtlSqArr()[i]);
  1122. param.setOptCd(param.getOptCds()[i]);
  1123. cartDao.updateCartDetail(param); // 장바구니 상세 저장
  1124. cartDao.insertCartDetailHst(param); // 장바구니 상세 이력 저장
  1125. }
  1126. }
  1127. } else {
  1128. param.setCartGb(TscConstants.CartGb.CART.value());
  1129. param.setNotCartSq(param.getCartSq()); // 수정 장바구니 번호 제외
  1130. param.setOptCd(param.getOptCds()[0]);
  1131. Collection<Integer> cartSqList = cartDao.selectHasNormalDealItemCartList(param);
  1132. if (cartSqList != null && cartSqList.size() > 0) { // 장바구니 기존재
  1133. if (cartSqList.size() > 1) { // 장바구니 조회 결과 이상시 insert or select 수정 필요
  1134. result.put("status", "FAIL");
  1135. result.put("message", "장바구니 조회에 실패하였습니다. 관리자에게 문의해주세요.");
  1136. return result;
  1137. } else {
  1138. param.setCartSq(cartSqList.iterator().next());
  1139. cartDao.updateCartInfo(param); // 장바구니 기존 데이터에 UPDATE(수량증가)
  1140. cartDao.insertCartHst(param); // 장바구니 수정 이력 저장
  1141. // 이전 장바구니에 수정되었으므로 현재 수정된 장바구니 데이터 삭제
  1142. int[] delCartSq = {param.getNotCartSq()};
  1143. param.setCartSqArr(delCartSq);
  1144. cartDao.deleteCart(param); // 현재 장바구니 삭제
  1145. cartDao.deleteCartDetail(param); // 현재 장바구니 삭제
  1146. }
  1147. } else {
  1148. cartDao.updateCartGoodsQty(param); // 장바구니 마스터 정보 저장
  1149. cartDao.insertCartHst(param); // 장바구니 수정 이력 저장
  1150. param.setItemCd(param.getItemCds()[0]);
  1151. param.setCartDtlSq(param.getCartDtlSqArr()[0]);
  1152. param.setOptCd(param.getOptCds()[0]);
  1153. cartDao.updateCartDetail(param); // 장바구니 상세 저장
  1154. cartDao.insertCartDetailHst(param); // 장바구니 수정 이력 저장
  1155. }
  1156. }
  1157. result.put("status", "SUCCESS");
  1158. return result;
  1159. }
  1160. /**
  1161. * 마이페이지 장바구니 담기 관련 정보 조회
  1162. *
  1163. * @param Cart
  1164. * @return Collection<Cart>
  1165. * @author card007
  1166. * @since 2021. 03. 26
  1167. */
  1168. public Collection<Cart> getAddCartInfoForMypage(Cart cart) {
  1169. return cartDao.getAddCartInfoForMypage(cart);
  1170. }
  1171. /**
  1172. * 장바구니 주문하기 버튼 클릭시 재고 및 상태 체크
  1173. * @param Order
  1174. * @return Collection<Order>
  1175. * @author xodud1202
  1176. * @since 2021. 04. 01
  1177. */
  1178. public Collection<Order> getOrderListConditionCheck(Order param) {
  1179. int custNo = 0;
  1180. if(TsfSession.isLogin()) {
  1181. custNo = TsfSession.getInfo().getCustNo();
  1182. } else {
  1183. param.setJsessionId(TsfSession.getSessionId());
  1184. }
  1185. if(param.getCustNo() > 0 && custNo == 0) {
  1186. return null;
  1187. }
  1188. Collection<Order> cartGoodsList = cartDao.getCartGoodsList(param);
  1189. for(Order order : cartGoodsList) {
  1190. if("Y".equals(order.getSoldoutYn())) {
  1191. if(order.getOrdCanQty() < order.getGoodsQty()) {
  1192. Collection<Order> conditionList = cartDao.getCartDetailInfo(order);
  1193. for(Order condition : conditionList) {
  1194. if("Y".equals(condition.getSoldoutYn())) {
  1195. order.setItemCd(condition.getItemCd());
  1196. order.setColorNm(condition.getColorNm());
  1197. order.setOptCd2(condition.getOptCd2());
  1198. order.setMaxOrdQty(condition.getMaxOrdQty());
  1199. }
  1200. }
  1201. }
  1202. }
  1203. }
  1204. return cartGoodsList;
  1205. }
  1206. /**
  1207. * 장바구니 최소/최대 주문 수량으로 변경
  1208. * @param Order
  1209. * @return Collection<Order>
  1210. * @author xodud1202
  1211. * @since 2021. 04. 02
  1212. */
  1213. @Transactional("shopTxnManager")
  1214. public Order updateCartGoodsQty(Cart param) {
  1215. if(TsfSession.isLogin()) {
  1216. param.setCustNo(TsfSession.getInfo().getCustNo());
  1217. param.setUpdNo(param.getCustNo());
  1218. } else {
  1219. param.setCustNo(0);
  1220. param.setUpdNo(0);
  1221. }
  1222. Order order = new Order();
  1223. order.setChgQty(cartDao.updateCartGoodsQty(param));
  1224. return order;
  1225. }
  1226. public Collection<Order> selectTmtbSalesValueList(Goods param) {
  1227. List<Integer> arr = Arrays.asList(param.getArrTmtbSq());
  1228. return cartDao.selectTmtbSectionValList(arr);
  1229. }
  1230. public Collection<Goods> selectTmtbSalesGoodsOptCd(Goods param) {
  1231. Goods goods = new Goods();
  1232. if(TsfSession.isLogin()) {
  1233. goods.setCustNo(TsfSession.getInfo().getCustNo());
  1234. } else {
  1235. goods.setCustNo(0);
  1236. }
  1237. goods.setFrontGb(TsfSession.getFrontGb());
  1238. goods.setGoodsCd(param.getGoodsCd());
  1239. return goodsDao.getDelvFeeSaveGoodsList(goods);
  1240. }
  1241. /**
  1242. * 장바구니 담긴 상품 전체 조회
  1243. * @param param
  1244. * @return
  1245. * @author xodud1202
  1246. * @since 2021. 07. 06
  1247. */
  1248. public Collection<Cart> getAllCartList(Cart param) {
  1249. return cartDao.getAllCartList(param);
  1250. }
  1251. }