TsaWithdrawService.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. package com.style24.admin.biz.service;
  2. import java.util.Collection;
  3. import java.util.List;
  4. import com.style24.core.biz.service.TscNaverPayService;
  5. import com.style24.core.support.env.TscConstants;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import com.gagaframework.web.parameter.GagaMap;
  10. import com.style24.admin.biz.dao.TsaDeliveryDao;
  11. import com.style24.admin.biz.dao.TsaWithdrawDao;
  12. import com.style24.admin.support.security.session.TsaSession;
  13. import com.style24.admin.biz.service.TsaWmsWithdrawService;
  14. import com.style24.core.biz.dao.TscOrderChangeDao;
  15. import com.style24.core.biz.service.TscOrderChangeService;
  16. import com.style24.core.biz.service.TscOrderRefundService;
  17. import com.style24.core.support.env.TscConstants.OrderChangeGb;
  18. import com.style24.core.support.env.TscConstants.OrderChangeStat;
  19. import com.style24.core.support.message.TscMessageByLocale;
  20. import com.style24.core.support.util.CryptoUtils;
  21. import com.style24.persistence.domain.Order;
  22. import com.style24.persistence.domain.OrderChange;
  23. import com.style24.persistence.domain.Withdraw;
  24. import com.style24.persistence.domain.WithdrawExc;
  25. import com.style24.persistence.domain.WmsWithdraw;
  26. import lombok.extern.slf4j.Slf4j;
  27. /**
  28. * 회수관리 Service
  29. *
  30. * @author moon
  31. * @since 2020. 11. 16
  32. */
  33. @Service
  34. @Slf4j
  35. public class TsaWithdrawService {
  36. @Autowired
  37. private TscMessageByLocale message;
  38. @Autowired
  39. private TsaWithdrawDao withdrawDao;
  40. @Autowired
  41. private TsaDeliveryDao deliveryDao;
  42. @Autowired
  43. private TscOrderChangeDao orderChangeDao;
  44. @Autowired
  45. private TscOrderChangeService coreOrderChangeService;
  46. @Autowired
  47. private TscOrderRefundService coreOrderRefundService;
  48. @Autowired
  49. private TscOrderChangeService orderChangeService;
  50. @Autowired
  51. private TsaWmsWithdrawService wmsWithdrawService;
  52. @Autowired
  53. private TscNaverPayService coreNaverPayService;
  54. /**
  55. * 환불관리 목록 건수
  56. *
  57. * @param Delivery
  58. * @return
  59. * @author moon
  60. * @since 2021. 05. 03
  61. */
  62. public int getRefundListCount(Withdraw withdraw) {
  63. return withdrawDao.getRefundListCount(withdraw);
  64. }
  65. /**
  66. * 환불관리 목록
  67. *
  68. * @param withdraw
  69. * @return Collection<Withdraw>
  70. * @author moon
  71. * @since 2020. 11. 16
  72. */
  73. public Collection<Withdraw> getRefundList(Withdraw withdraw) {
  74. return withdrawDao.getRefundList(withdraw);
  75. }
  76. /**
  77. * 회수예외 목록 건수
  78. *
  79. * @param Delivery
  80. * @return
  81. * @author moon
  82. * @since 2021. 03. 04
  83. */
  84. public int getWithdrawExceptionListCount(WithdrawExc withdrawExc) {
  85. return withdrawDao.getWithdrawExceptionListCount(withdrawExc);
  86. }
  87. /**
  88. * 회수예외 목록
  89. *
  90. * @param Delivery
  91. * @return
  92. * @author moon
  93. * @since 2021. 03. 04
  94. */
  95. public Collection<WithdrawExc> getWithdrawExceptionList(WithdrawExc withdrawExc) {
  96. return withdrawDao.getWithdrawExceptionList(withdrawExc);
  97. }
  98. /**
  99. * 회수예외 완료처리
  100. *
  101. * @param Delivery
  102. * @return
  103. * @author moon
  104. * @since 2021. 03. 04
  105. */
  106. @Transactional("shopTxnManager")
  107. public void createWithdrawInfo(WithdrawExc withdrawExc) {
  108. withdrawExc.setRecallStat("S");
  109. withdrawDao.updateWithdrawException(withdrawExc);
  110. }
  111. /**
  112. * 회수예외 사유변경 목록
  113. *
  114. * @param Delivery
  115. * @return
  116. * @author moon
  117. * @since 2021. 05. 20
  118. */
  119. public Collection<WithdrawExc> getWithdrawExceptionChangeList(WithdrawExc withdrawExc) {
  120. return withdrawDao.getWithdrawExceptionChangeList(withdrawExc);
  121. }
  122. /**
  123. * 환불비 조회
  124. *
  125. * @param Delivery
  126. * @return
  127. * @author moon
  128. * @since 2021. 05. 21
  129. */
  130. public GagaMap getRefundAmt(Collection<WithdrawExc> list) {
  131. OrderChange orderChange = new OrderChange();
  132. int[] ordDtlNoArr = new int[list.size()];
  133. int[] cnclRtnReqQtyArr = new int[list.size()];
  134. int i=0;
  135. for(WithdrawExc data : list) {
  136. ordDtlNoArr[i] = data.getOrdDtlNo();
  137. cnclRtnReqQtyArr[i] = data.getChgQty();
  138. i++;
  139. }
  140. WithdrawExc item = list.iterator().next();
  141. orderChange.setOrdDtlNoArr(ordDtlNoArr);
  142. orderChange.setCnclRtnReqQtyArr(cnclRtnReqQtyArr);
  143. orderChange.setCustNo(item.getCustNo());
  144. orderChange.setOrdNo(item.getOrdNo());
  145. orderChange.setDelvFeeCd(item.getDelvFeeCd());
  146. orderChange.setChgGb(item.getChgGb());
  147. GagaMap refundPreInfo = coreOrderChangeService.getRefundPreInfo(orderChange);
  148. List<Order> returnReqList = (List<Order>)refundPreInfo.get("cnclReqList");
  149. GagaMap result = coreOrderRefundService.cnclRtnRefundAmt(returnReqList);
  150. return result;
  151. }
  152. /**
  153. * WMS회수목록 - 옵션정보
  154. *
  155. * @param Delivery
  156. * @return
  157. * @author moon
  158. * @since 2021. 03. 04
  159. */
  160. public Collection<WmsWithdraw> getOptionInfo(Collection<WmsWithdraw> wmsWithdrawList) {
  161. for(WmsWithdraw data : wmsWithdrawList) {
  162. WmsWithdraw optionInfo = withdrawDao.getOptionInfo(data);
  163. data.setGoodsCd(optionInfo.getGoodsCd());
  164. }
  165. return wmsWithdrawList;
  166. }
  167. /**
  168. * 회수지시목록 건수
  169. *
  170. * @param Withdraw
  171. * @return
  172. * @author moon
  173. * @since 2021. 05. 10
  174. */
  175. public int getWithdrawDirectiveListCount(Withdraw withdraw) {
  176. return withdrawDao.getWithdrawDirectiveListCount(withdraw);
  177. }
  178. /**
  179. * 회수지시 목록
  180. *
  181. * @param Withdraw
  182. * @return
  183. * @author moon
  184. * @since 2021. 05. 10
  185. */
  186. public Collection<Withdraw> getWithdrawDirectiveList(Withdraw withdraw) {
  187. return withdrawDao.getWithdrawDirectiveList(withdraw);
  188. }
  189. /**
  190. * 재회수지시
  191. *
  192. * @param Withdraw
  193. * @return void
  194. * @author moon
  195. * @since 2021. 05. 11
  196. */
  197. @Transactional("shopTxnManager")
  198. public void reRecallOrder(Withdraw withdraw) {
  199. Integer userNo = TsaSession.getInfo().getUserNo();
  200. withdraw.setUpdNo(userNo);
  201. withdrawDao.updateReRecallOrderChange(withdraw);
  202. if(OrderChangeGb.RETURN.value().equals(withdraw.getChgGb())) { // 반품요청
  203. withdraw.setChgStat(OrderChangeStat.RETURN.value()); // 반품접수
  204. } else { //교환요청
  205. withdraw.setChgStat(OrderChangeStat.EXCHANGE.value()); // 교환접수
  206. }
  207. withdrawDao.updateReRecallOrder(withdraw);
  208. // 상세목록 조회
  209. Collection<Withdraw> list = withdrawDao.getOrdChgDtlList(withdraw);
  210. for(Withdraw data : list) {
  211. // 주문상세변경 이력
  212. OrderChange ordChg = new OrderChange();
  213. ordChg.setRegNo(userNo);
  214. ordChg.setUpdNo(userNo);
  215. ordChg.setOrdChgSq(data.getOrdChgSq());
  216. ordChg.setOrdDtlNo(data.getOrdDtlNo());
  217. ordChg.setChgStat(data.getChgStat());
  218. orderChangeDao.createOrderChangeDetailHst(ordChg);
  219. }
  220. // WMS 재회수지시
  221. wmsWithdrawService.updateReRecallOrder(withdraw);
  222. }
  223. /**
  224. * 주문변경사유 변경
  225. *
  226. * @param Withdraw
  227. * @return void
  228. * @author moon
  229. * @since 2021. 05. 21
  230. */
  231. @Transactional("shopTxnManager")
  232. public void saveChangeReason(WithdrawExc withdrawExc) {
  233. Integer userNo = TsaSession.getInfo().getUserNo();
  234. if("Y".equals(withdrawExc.getChangeYn())) {
  235. // TB_ORDER_CHANGE_DETAIL 변경
  236. String[] listDtlNo = withdrawExc.getOrdDtlNoList().split(",");
  237. for(int i=0; i<listDtlNo.length; i++) {
  238. WithdrawExc item = new WithdrawExc();
  239. if("G680_30".equals(withdrawExc.getWdGb())) { // 반품요청
  240. item.setChgStat(OrderChangeStat.RETURN_WAIT.value()); // 반품대기 (추가배송비 결제 전)
  241. } else { // 교환요청
  242. item.setChgStat(OrderChangeStat.EXCHANGE_WAIT.value()); // 교환대기 (추가배송비 결제 전)
  243. }
  244. item.setOrdChgSq(withdrawExc.getOrdChgSq());
  245. item.setOrdDtlNo(Integer.parseInt(listDtlNo[i]));
  246. item.setUpdNo(userNo);
  247. withdrawDao.updateChangeStat(item);
  248. // 주문상세변경 이력
  249. OrderChange ordChg = new OrderChange();
  250. ordChg.setRegNo(userNo);
  251. ordChg.setUpdNo(userNo);
  252. ordChg.setOrdChgSq(item.getOrdChgSq());
  253. ordChg.setOrdDtlNo(item.getOrdDtlNo());
  254. ordChg.setChgStat(item.getChgStat());
  255. orderChangeDao.createOrderChangeDetailHst(ordChg);
  256. }
  257. } else if("S".equals(withdrawExc.getChangeYn())) {
  258. String[] listDtlNo = withdrawExc.getOrdDtlNoList().split(",");
  259. for(int i=0; i<listDtlNo.length; i++) {
  260. WithdrawExc item = new WithdrawExc();
  261. item.setChgStat(OrderChangeStat.WITHDRAW_GOODS_CHECK.value()); // G685_31 상품검수중
  262. item.setOrdChgSq(withdrawExc.getOrdChgSq());
  263. item.setOrdDtlNo(Integer.parseInt(listDtlNo[i]));
  264. item.setUpdNo(userNo);
  265. withdrawDao.updateChangeStat(item);
  266. // 주문상세변경 이력
  267. OrderChange ordChg = new OrderChange();
  268. ordChg.setRegNo(userNo);
  269. ordChg.setUpdNo(userNo);
  270. ordChg.setOrdChgSq(item.getOrdChgSq());
  271. ordChg.setOrdDtlNo(item.getOrdDtlNo());
  272. ordChg.setChgStat(item.getChgStat());
  273. orderChangeDao.createOrderChangeDetailHst(ordChg);
  274. }
  275. }
  276. // TB_ORDER_CHANGE 변경
  277. withdrawExc.setUpdNo(userNo);
  278. withdrawDao.updateChangeReason(withdrawExc);
  279. }
  280. /**
  281. * 환불관리 상세정보
  282. *
  283. * @param withdraw - 변경주문번호
  284. * @return
  285. * @author moon
  286. * @since 2020. 11. 16
  287. */
  288. public Collection<Withdraw> getRefundDetailList(Withdraw withdraw) {
  289. return withdrawDao.getRefundDetailList(withdraw);
  290. }
  291. /**
  292. * 회수관리 - 회수처리
  293. *
  294. * @param params
  295. * @return
  296. * @author moon
  297. * @since 2020. 11. 16
  298. */
  299. @Transactional("shopTxnManager")
  300. public void refundDetailConfirm(GagaMap params) {
  301. Integer userNo = TsaSession.getInfo().getUserNo();
  302. OrderChange change = new OrderChange();
  303. change.setOrdNo(params.getInt("ordNo"));
  304. change.setCustNo(params.getInt("custNo"));
  305. change.setOrderNm(params.getString("ordNm"));
  306. change.setPgGb(params.getString("pgGb"));
  307. change.setPayMeans(params.getString("payMeans"));
  308. change.setBankCd(params.getString("bankCd"));
  309. change.setAccountNm(params.getString("accountNm"));
  310. change.setAccountNo(CryptoUtils.decryptAES(params.getString("accountNo")));
  311. //change.getOrdDtlNoList().add(params.getOrdDtlNo());
  312. //change.getCnclRtnReqQtyList().add(params.getCnclRtnQty());
  313. change.setChgReason(params.getString("chgReason"));
  314. change.setChgReasonNm(params.getString("chgReasonNm"));
  315. change.setBatchYn("N");
  316. change.setDelvAddrSq(params.getInt("delvAddrSq"));
  317. change.setAddDeliveryFeeYn(params.getString("addDeliveryFeeYn"));
  318. change.setAddDeliveryFee(params.getInt("addDeliveryFee"));
  319. change.setRegNo(userNo);
  320. change.setUpdNo(userNo);
  321. change.setUserNo(userNo);
  322. change.setOrdChgSq(params.getInt("ordChgSq"));
  323. change.setMallGb(params.getString("mallGb"));
  324. change.setSpanRefundAmt(params.getInt("spanRefundAmt"));
  325. change.setPgStat(params.getString("pgStat"));
  326. change.setCodFeeYn(params.getString("codFeeYn"));
  327. change.setCodFee(params.getInt("codFee"));
  328. change.setEnCloseFeeYn(params.getString("enCloseFeeYn"));
  329. change.setEncloseFee(params.getInt("enCloseFee"));
  330. change.setWdInvoiceNo(params.getString("wdInvoiceNo"));
  331. String allCanYn = params.getString("allCanYn");
  332. try {
  333. if ("Y".equals(allCanYn)) {
  334. orderChangeService.allRefund(change);
  335. } else {
  336. OrderChange orderChange= new OrderChange();
  337. orderChange.setOrdChgSq(params.getInt("ordChgSq"));
  338. orderChange.setUserNo(params.getInt("custNo"));
  339. GagaMap info = orderChangeService.refundConfirmPreInfo(orderChange);
  340. info.set("chgReasonNm" , params.getString("chgReasonNm")); // 변경사유
  341. info.set("chgReason" , params.getString("chgReason")); // 변경사유코드
  342. info.set("accountNm" , params.getString("accountNm")); // 환불계좌이름
  343. info.set("accountNo" , CryptoUtils.decryptAES(params.getString("accountNo"))); // 환불계좌번호
  344. info.set("bankCd" , params.getString("bankCd")); // 환불계좌은행코드
  345. info.set("custNo" , params.getInt("custNo")); // 고객번호
  346. info.set("ordNm" , params.getString("ordNm")); // 주문자명
  347. info.set("delvAddrSq" , params.getInt("delvAddrSq")); // 배송지번호
  348. info.set("delvExpnYn" , params.getString("delvExpnYn")); // 확정후반품,불량여부
  349. info.set("addDeliveryFee" , params.getInt("addDeliveryFee")); // 추가배송비
  350. info.set("addDeliveryFeeYn" , params.getString("addDeliveryFeeYn")); // 추가배송비여부
  351. info.set("mallGb" , params.getString("mallGb")); // 몰구분
  352. info.set("ordNo" , params.getInt("ordNo")); // 주문번호
  353. info.set("ordChgSq" , params.getInt("ordChgSq")); // 변경요청번호
  354. info.set("pgStat" , params.getString("pgStat")); // PG 상태
  355. info.set("codFee" , params.getInt("codFee")); // 착불비
  356. info.set("codFeeYn" , params.getString("codFeeYn")); // 착불비여부
  357. info.set("enCloseFeeYn" , params.getString("enCloseFeeYn")); // 동봉비여부
  358. info.set("enCloseFee" , params.getInt("enCloseFee")); // 동봉비
  359. info.set("wdInvoiceNo" , params.getInt("wdInvoiceNo")); // 회수송장번호
  360. info.set("wdGb" , params.getString("wdGb")); // 회수구분
  361. info.set("addPayCost" , params.getInt("addPayCost")); // 추가배송비
  362. orderChangeService.partialRefund(info, userNo);
  363. }
  364. // 네이버페이 환불컨펌
  365. if(TscConstants.PgGb.NAVER_ORDER.value().equals(change.getPgGb())) {
  366. // PG 미전송이 아닐 경우 (Y면 미전송, N이면 전송)
  367. if("N".equals(change.getPgStat())) {
  368. // WMS 예외로 넘어온 데이터인지 확인 후 네이버페이 진행
  369. Collection<OrderChange> exceptions = orderChangeDao.getOrderRecallExceptionInfo(change); // 예외 품절 및 불량 정보 조회
  370. int i = 0;
  371. for(OrderChange exception : exceptions) {
  372. if(exception.getOrderDtlNo() > 0) { // 확정 후 품절 및 불량이 있을경우
  373. if("O".equals(exception.getOrdExchGb())) { // 원배송 확정 후 품절 및 불량
  374. // 품절 취소 송부
  375. Order param = new Order();
  376. param.setOrdDtlNo(exception.getOrdDtlNo());
  377. coreNaverPayService.sendNaverPaySoldoutCancel(param, userNo); // 품절취소
  378. } else if ("E".equals(exception.getOrdExchGb())){ // 교환 후 확정 후 품절 및 불량
  379. // 교환 반려 > 반품 접수 > 반품 완료
  380. Order param = new Order();
  381. param.setOrdDtlNo(exception.getOrdDtlNo());
  382. if(i < 1) {
  383. coreNaverPayService.sendNaverPayRejectExchange(exception, userNo); // 교환반려
  384. }
  385. coreNaverPayService.sendNaverPaySoldoutReturnReq(param, userNo); // 품절반품접수
  386. if(i < 1) {
  387. coreNaverPayService.sendNaverPayReturnComplete(exception, userNo); // 반품완료
  388. }
  389. }
  390. } else { // 정상 반품 완료
  391. if(i < 1) {
  392. coreNaverPayService.sendNaverPayReturnComplete(exception, userNo); // 반품완료
  393. }
  394. }
  395. i++;
  396. }
  397. }
  398. }
  399. } catch (Exception e) {
  400. e.printStackTrace();
  401. throw new IllegalStateException("실패");
  402. }
  403. }
  404. }