TsfCartController.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. package com.style24.front.biz.web;
  2. import java.text.SimpleDateFormat;
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.Collections;
  6. import java.util.Comparator;
  7. import java.util.Date;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.gagaframework.web.rest.server.GagaResponse;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.core.env.Environment;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.ui.Model;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.ResponseBody;
  20. import org.springframework.web.servlet.ModelAndView;
  21. import org.thymeleaf.util.StringUtils;
  22. import com.gagaframework.web.parameter.GagaMap;
  23. import com.style24.core.biz.service.TscKcpService;
  24. import com.style24.core.biz.service.TscOrderService;
  25. import com.style24.core.support.env.TscConstants;
  26. import com.style24.core.support.message.TscMessageByLocale;
  27. import com.style24.core.support.util.CryptoUtils;
  28. import com.style24.front.biz.service.TsfCartService;
  29. import com.style24.front.biz.service.TsfCouponService;
  30. import com.style24.front.biz.service.TsfOrderService;
  31. import com.style24.front.support.controller.TsfBaseController;
  32. import com.style24.front.support.security.session.TsfSession;
  33. import com.style24.persistence.domain.Cart;
  34. import com.style24.persistence.domain.Coupon;
  35. import com.style24.persistence.domain.GiftCard;
  36. import com.style24.persistence.domain.Goods;
  37. import com.style24.persistence.domain.Login;
  38. import com.style24.persistence.domain.Order;
  39. import com.style24.persistence.domain.Payment;
  40. import com.style24.persistence.domain.WishList;
  41. import lombok.extern.slf4j.Slf4j;
  42. /**
  43. * 장바구니 Controller
  44. *
  45. * @author gagamel
  46. * @since 2020. 12. 29
  47. */
  48. @Controller
  49. @RequestMapping("/cart")
  50. @Slf4j
  51. public class TsfCartController extends TsfBaseController {
  52. @Autowired
  53. private TscMessageByLocale message;
  54. @Autowired
  55. private TsfCartService cartService;
  56. @Autowired
  57. private TsfCouponService couponService;
  58. @Autowired
  59. private TscOrderService coreOrderService;
  60. @Autowired
  61. private TscKcpService coreKcpService;
  62. @Autowired
  63. private TsfOrderService orderService;
  64. @Autowired
  65. private Environment env;
  66. /**
  67. * 장바구니 화면
  68. * @return
  69. * @author xodud1202
  70. * @since 2021. 01. 28
  71. */
  72. @GetMapping("/list/form")
  73. public ModelAndView cartListForm() {
  74. ModelAndView mav = new ModelAndView();
  75. mav.setViewName(super.getDeviceViewName("cart/CartListForm"));
  76. return mav;
  77. }
  78. /**
  79. * 장바구니 등록
  80. * @param param
  81. * goodsCd : 상품코드 (세트 : 세트상품코드, 딜상품 : 원상품코드, 일반상품 : 상품코드)
  82. * dealGoodsCd : 딜상품코드
  83. * itemCd : 구성상품코드 (세트. 세트 아닐 경우 입력X)
  84. * optCd : 옵션코드
  85. * goodsType : 상품타입 (공통코드 G026)
  86. * goodsQty : 장바구니 등록 수량
  87. * cartGb : O = 바로주문, C = 장바구니
  88. * afLinkCd : 제휴링크코드
  89. * ithr_cd : 유입경고
  90. * contents_loc : 컨텐츠 위치
  91. * planDtlSq : 기획전상세번호
  92. * dealGoodsCd : 딜상품코드 (딜상품코드)
  93. * @return ModelAndView
  94. * @author xodud1202
  95. * @since 2021. 01. 28
  96. */
  97. @ResponseBody
  98. @PostMapping("/save")
  99. public GagaMap createCart(@RequestBody Collection<Cart> params) {
  100. GagaMap result = new GagaMap();
  101. try {
  102. result = cartService.saveCartInfo(params);
  103. } catch (Exception e) {
  104. e.printStackTrace();
  105. throw new IllegalArgumentException();
  106. }
  107. return result;
  108. }
  109. // @ResponseBody
  110. @PostMapping("/goods/list")
  111. public String selectCartGoodsList(Order param, Model model) {
  112. // 총알배송 가능 여부 체크
  113. int shotCanYn = coreOrderService.getDailyDeliveryCheck(param);
  114. // 10시 이전에만 총알 배송 가능 여부 체크
  115. if(shotCanYn == 1) {
  116. SimpleDateFormat format = new SimpleDateFormat ( "MM/dd");
  117. Date time = new Date();
  118. param.setShotCanYn("Y");
  119. param.setShotDelvDt(format.format(time));
  120. } else {
  121. SimpleDateFormat format = new SimpleDateFormat ( "MM/dd");
  122. Date time = new Date();
  123. param.setShotCanYn("N");
  124. param.setShotDelvDt(format.format(time));
  125. }
  126. if(param.getShotDelvUseYn() == null) {
  127. param.setShotDelvUseYn(param.getShotCanYn());
  128. }
  129. // 장바구니 정보 조회
  130. Order order = cartService.getCartGoodsList(param);
  131. order.setShotDelvUseYn(param.getShotDelvUseYn());
  132. order.setShotCanYn(param.getShotCanYn());
  133. order.setShotDelvDt(param.getShotDelvDt());
  134. model.addAttribute("loginInfo", TsfSession.getInfo());
  135. model.addAttribute("order", order);
  136. model.addAttribute("IMG_PATH", env.getProperty("upload.goods.view"));
  137. GiftCard temp = new GiftCard();
  138. temp.setModType("STPC"); // 요청 구분 (STSQ : 조회, STSC : 전체취소, STPC : 부분취소)
  139. temp.setOrdNo(3); // 주문번호
  140. temp.setUsGfcdAmt(142); // 부분취소 요청 금액
  141. GiftCard aa = coreKcpService.kcpCashReceiptCancel(temp);
  142. return super.getDeviceViewName("cart/CartListAjaxForm");
  143. }
  144. /**
  145. * 장바구니 로그인 정보 조회
  146. * @param param
  147. * @return
  148. */
  149. @ResponseBody
  150. @PostMapping("/login/info")
  151. public Login selectLoginInfo(Order param) {
  152. Login result = new Login();
  153. if(TsfSession.isLogin()) {
  154. result = TsfSession.getInfo();
  155. } else {
  156. result.setCustNo(0);
  157. }
  158. return result;
  159. }
  160. /**
  161. * 장바구니 체크박스 change시에 계산로직 진행
  162. * @param param
  163. * @return
  164. */
  165. @ResponseBody
  166. @PostMapping("/change/goods/list")
  167. public Order selectCartGoodsJsonList(@RequestBody Order param) {
  168. Order order = cartService.getCartGoodsList(param);
  169. order.setImgPath1(env.getProperty("upload.goods.view"));
  170. return order;
  171. }
  172. /**
  173. * 프로모션 할인 쿠폰 조회
  174. * @param param
  175. * rdCpnNm : 시리얼쿠폰명
  176. * cartSqArr[] : 장바구니 번호 배열
  177. * @return GagaMap
  178. * @author xodud1202
  179. * @since 2021. 02. 17
  180. */
  181. @ResponseBody
  182. @PostMapping("/list/serialCpnApply")
  183. public GagaMap serialCpnApply(@RequestBody Coupon param) {
  184. GagaMap result = new GagaMap();
  185. // 시리얼 쿠폰 정보 조회 및 쿠폰 지급 미대상인 경우 쿠폰 지급
  186. Coupon useSerial = couponService.serialCpnApplyInfo(param);
  187. result.put("serialCpnInfo", useSerial);
  188. return result;
  189. }
  190. /**
  191. * 장바구니 삭제
  192. * @param param
  193. * @return GagaMap
  194. * @author xodud1202
  195. * @since 2021. 02. 23
  196. */
  197. @ResponseBody
  198. @PostMapping("/deleteCart")
  199. public GagaMap deleteCart(@RequestBody Cart param) {
  200. cartService.deleteCart(param);
  201. return new GagaMap();
  202. }
  203. /**
  204. * 장바구니 옵션변경 팝업
  205. * @param param
  206. * @return String
  207. * @author xodud1202
  208. * @since 2021. 02. 23
  209. */
  210. // @ResponseBody
  211. @PostMapping("/goods/info")
  212. public String getCartGoodsInfo(Cart param, Model model) {
  213. Cart cart = cartService.getCartGoodsInfo(param);
  214. model.addAttribute("cart", cart);
  215. model.addAttribute("setType", TscConstants.GoodsType.SET.value());
  216. return super.getDeviceViewName("cart/CartChangeOptionPopup");
  217. }
  218. /**
  219. * 장바구니 옵션 변경
  220. * @param param
  221. * @return GagaMap
  222. * @author xodud1202
  223. * @since 2021. 02. 23
  224. */
  225. @ResponseBody
  226. @PostMapping("/change/option")
  227. public GagaMap updateCartOption(@RequestBody Cart param) {
  228. GagaMap result = new GagaMap();
  229. result = cartService.updateCartOption(param);
  230. if("SUCCESS".equals(result.get("status"))) {
  231. result.put("message", message.getMessage("SUCC_0009"));
  232. }
  233. return result;
  234. }
  235. /**
  236. * 장바구니 주문하기 시점 재고 및 상태 체크
  237. * @param param
  238. * @return
  239. * @author xodud1202
  240. * @since 2021. 04. 02
  241. */
  242. @ResponseBody
  243. @PostMapping("/order/list/check")
  244. public Collection<Order> selectOrderListCheck(@RequestBody Order param) {
  245. return cartService.getOrderListConditionCheck(param);
  246. }
  247. /**
  248. * 장바구니 최소 주문 수량으로 변경
  249. * @param param
  250. * @return
  251. * @author xodud1202
  252. * @since 2021. 04. 02
  253. */
  254. @ResponseBody
  255. @PostMapping("/update/goodsQty")
  256. public Order updateCartGoodsQty(@RequestBody Cart param) {
  257. return cartService.updateCartGoodsQty(param);
  258. }
  259. /**
  260. * 퀵메뉴 장바구니 리스트
  261. * @return
  262. * @author sowon
  263. * @since 2021. 4. 1
  264. */
  265. @GetMapping("/quick/cart/list")
  266. @ResponseBody
  267. public Order getCartList() {
  268. Order cart = new Order();
  269. int custNo = 0;
  270. if(TsfSession.isLogin()) {
  271. custNo = TsfSession.getInfo().getCustNo();
  272. }
  273. // 장바구니 상품목록
  274. cart = cartService.getCartGoodsList(cart);
  275. cart.setImgPath1(env.getProperty("upload.goods.view"));
  276. // 현재 주문 가능 수량순으로 정렬
  277. Collections.sort((ArrayList<Order>) cart.getDelvAllCartList(), new Comparator<Order>() {
  278. @Override
  279. public int compare(Order c1, Order c2) {
  280. return c1.getOrdCanQty() - c2.getOrdCanQty();
  281. // return c2.getQtyTmtbSq() - c1.getQtyTmtbSq(); //역순 정렬
  282. }
  283. });
  284. return cart;
  285. }
  286. }