| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- package com.style24.admin.biz.service;
- import java.util.Collection;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.gagaframework.web.parameter.GagaMap;
- import com.style24.admin.biz.dao.TsaDeliveryDao;
- import com.style24.admin.biz.dao.TsaWithdrawDao;
- import com.style24.admin.support.security.session.TsaSession;
- import com.style24.core.biz.dao.TscOrderChangeDao;
- import com.style24.core.biz.service.TscKakaotalkService;
- import com.style24.core.biz.service.TscNaverPayService;
- import com.style24.core.biz.service.TscOrderChangeService;
- import com.style24.core.biz.service.TscOrderRefundService;
- import com.style24.core.support.env.TscConstants;
- import com.style24.core.support.env.TscConstants.OrderChangeGb;
- import com.style24.core.support.env.TscConstants.OrderChangeStat;
- import com.style24.core.support.message.TscMessageByLocale;
- import com.style24.core.support.util.CryptoUtils;
- import com.style24.persistence.domain.Order;
- import com.style24.persistence.domain.OrderChange;
- import com.style24.persistence.domain.Withdraw;
- import com.style24.persistence.domain.WithdrawExc;
- import com.style24.persistence.domain.WmsWithdraw;
- import lombok.extern.slf4j.Slf4j;
- /**
- * 회수관리 Service
- *
- * @author moon
- * @since 2020. 11. 16
- */
- @Service
- @Slf4j
- public class TsaWithdrawService {
- @Autowired
- private TscMessageByLocale message;
- @Autowired
- private TsaWithdrawDao withdrawDao;
- @Autowired
- private TsaDeliveryDao deliveryDao;
- @Autowired
- private TscOrderChangeDao orderChangeDao;
-
- @Autowired
- private TscOrderChangeService coreOrderChangeService;
-
- @Autowired
- private TscOrderRefundService coreOrderRefundService;
-
- @Autowired
- private TscOrderChangeService orderChangeService;
-
- @Autowired
- private TsaWmsWithdrawService wmsWithdrawService;
- @Autowired
- private TscNaverPayService coreNaverPayService;
- @Autowired
- private TscKakaotalkService kakaotalkService;
-
-
- /**
- * 환불관리 목록 건수
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 05. 03
- */
- public int getRefundListCount(Withdraw withdraw) {
- return withdrawDao.getRefundListCount(withdraw);
- }
-
-
-
- /**
- * 환불관리 목록
- *
- * @param withdraw
- * @return Collection<Withdraw>
- * @author moon
- * @since 2020. 11. 16
- */
- public Collection<Withdraw> getRefundList(Withdraw withdraw) {
- return withdrawDao.getRefundList(withdraw);
- }
-
-
-
- /**
- * 회수예외 목록 건수
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 03. 04
- */
- public int getWithdrawExceptionListCount(WithdrawExc withdrawExc) {
- return withdrawDao.getWithdrawExceptionListCount(withdrawExc);
- }
-
- /**
- * 회수예외 목록
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 03. 04
- */
- public Collection<WithdrawExc> getWithdrawExceptionList(WithdrawExc withdrawExc) {
- return withdrawDao.getWithdrawExceptionList(withdrawExc);
- }
-
- /**
- * 회수예외 완료처리
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 03. 04
- */
- @Transactional("shopTxnManager")
- public void createWithdrawInfo(WithdrawExc withdrawExc) {
- withdrawExc.setRecallStat("S");
- withdrawDao.updateWithdrawException(withdrawExc);
-
- wmsWithdrawService.updateTbIfRecallExceptionRslt(withdrawExc);
-
-
- }
-
- /**
- * 회수예외 사유변경 목록
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 05. 20
- */
- public Collection<WithdrawExc> getWithdrawExceptionChangeList(WithdrawExc withdrawExc) {
- return withdrawDao.getWithdrawExceptionChangeList(withdrawExc);
- }
-
- /**
- * 환불비 조회
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 05. 21
- */
- public GagaMap getRefundAmt(Collection<WithdrawExc> list) {
-
- OrderChange orderChange = new OrderChange();
-
-
- int[] ordDtlNoArr = new int[list.size()];
- int[] cnclRtnReqQtyArr = new int[list.size()];
-
- int i=0;
- for(WithdrawExc data : list) {
- ordDtlNoArr[i] = data.getOrdDtlNo();
- cnclRtnReqQtyArr[i] = data.getChgQty();
- i++;
- }
-
- WithdrawExc item = list.iterator().next();
-
- orderChange.setOrdDtlNoArr(ordDtlNoArr);
- orderChange.setCnclRtnReqQtyArr(cnclRtnReqQtyArr);
- orderChange.setCustNo(item.getCustNo());
- orderChange.setOrdNo(item.getOrdNo());
- orderChange.setDelvFeeCd(item.getDelvFeeCd());
- orderChange.setChgGb(item.getChgGb());
-
- GagaMap refundPreInfo = coreOrderChangeService.getRefundPreInfo(orderChange);
- List<Order> returnReqList = (List<Order>)refundPreInfo.get("cnclReqList");
- GagaMap result = coreOrderRefundService.cnclRtnRefundAmt(returnReqList);
- return result;
- }
-
- /**
- * WMS회수목록 - 옵션정보
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 03. 04
- */
- public Collection<WmsWithdraw> getOptionInfo(Collection<WmsWithdraw> wmsWithdrawList) {
-
- for(WmsWithdraw data : wmsWithdrawList) {
-
- WmsWithdraw optionInfo = withdrawDao.getOptionInfo(data);
- data.setGoodsCd(optionInfo.getGoodsCd());
- }
- return wmsWithdrawList;
- }
-
-
- /**
- * 회수지시목록 건수
- *
- * @param Withdraw
- * @return
- * @author moon
- * @since 2021. 05. 10
- */
- public int getWithdrawDirectiveListCount(Withdraw withdraw) {
- return withdrawDao.getWithdrawDirectiveListCount(withdraw);
- }
-
- /**
- * 회수지시 목록
- *
- * @param Withdraw
- * @return
- * @author moon
- * @since 2021. 05. 10
- */
- public Collection<Withdraw> getWithdrawDirectiveList(Withdraw withdraw) {
- return withdrawDao.getWithdrawDirectiveList(withdraw);
- }
-
- /**
- * 재회수지시
- *
- * @param Withdraw
- * @return void
- * @author moon
- * @since 2021. 05. 11
- */
- @Transactional("shopTxnManager")
- public void reRecallOrder(Withdraw withdraw) {
- Integer userNo = TsaSession.getInfo().getUserNo();
- withdraw.setUpdNo(userNo);
-
- withdrawDao.updateReRecallOrderChange(withdraw);
-
-
- if(OrderChangeGb.RETURN.value().equals(withdraw.getChgGb())) { // 반품요청
- withdraw.setChgStat(OrderChangeStat.RETURN.value()); // 반품접수
- } else { //교환요청
- withdraw.setChgStat(OrderChangeStat.EXCHANGE.value()); // 교환접수
- }
- withdrawDao.updateReRecallOrder(withdraw);
-
- // 상세목록 조회
- Collection<Withdraw> list = withdrawDao.getOrdChgDtlList(withdraw);
-
- for(Withdraw data : list) {
- // 주문상세변경 이력
- OrderChange ordChg = new OrderChange();
- ordChg.setRegNo(userNo);
- ordChg.setUpdNo(userNo);
- ordChg.setOrdChgSq(data.getOrdChgSq());
- ordChg.setOrdDtlNo(data.getOrdDtlNo());
- ordChg.setChgStat(data.getChgStat());
- orderChangeDao.createOrderChangeDetailHst(ordChg);
- }
-
- // WMS 재회수지시
- wmsWithdrawService.updateReRecallOrder(withdraw);
-
- }
-
- /**
- * 주문변경사유 변경
- *
- * @param Withdraw
- * @return void
- * @author moon
- * @since 2021. 05. 21
- */
- @Transactional("shopTxnManager")
- public void saveChangeReason(WithdrawExc withdrawExc) {
- Integer userNo = TsaSession.getInfo().getUserNo();
- if("Y".equals(withdrawExc.getChangeYn())) {
- // TB_ORDER_CHANGE_DETAIL 변경
- String[] listDtlNo = withdrawExc.getOrdDtlNoList().split(",");
- for(int i=0; i<listDtlNo.length; i++) {
- WithdrawExc item = new WithdrawExc();
- if("G680_30".equals(withdrawExc.getWdGb())) { // 반품요청
- item.setChgStat(OrderChangeStat.WITHDRAW_WAIT.value()); // 반품대기 (추가배송비 결제 전)
- } else { // 교환요청
- item.setChgStat(OrderChangeStat.WITHDRAW_WAIT.value()); // 교환대기 (추가배송비 결제 전)
- }
- item.setOrdChgSq(withdrawExc.getOrdChgSq());
- item.setOrdDtlNo(Integer.parseInt(listDtlNo[i]));
- item.setUpdNo(userNo);
- withdrawDao.updateChangeStat(item);
-
- // 주문상세변경 이력
- OrderChange ordChg = new OrderChange();
- ordChg.setRegNo(userNo);
- ordChg.setUpdNo(userNo);
- ordChg.setOrdChgSq(item.getOrdChgSq());
- ordChg.setOrdDtlNo(item.getOrdDtlNo());
- ordChg.setChgStat(item.getChgStat());
- orderChangeDao.createOrderChangeDetailHst(ordChg);
-
- }
- } else if("S".equals(withdrawExc.getChangeYn())) {
- String[] listDtlNo = withdrawExc.getOrdDtlNoList().split(",");
- for(int i=0; i<listDtlNo.length; i++) {
- WithdrawExc item = new WithdrawExc();
- item.setChgStat(OrderChangeStat.WITHDRAW_GOODS_CHECK.value()); // G685_31 상품검수중
- item.setOrdChgSq(withdrawExc.getOrdChgSq());
- item.setOrdDtlNo(Integer.parseInt(listDtlNo[i]));
- item.setUpdNo(userNo);
- withdrawDao.updateChangeStat(item);
-
- // 주문상세변경 이력
- OrderChange ordChg = new OrderChange();
- ordChg.setRegNo(userNo);
- ordChg.setUpdNo(userNo);
- ordChg.setOrdChgSq(item.getOrdChgSq());
- ordChg.setOrdDtlNo(item.getOrdDtlNo());
- ordChg.setChgStat(item.getChgStat());
- orderChangeDao.createOrderChangeDetailHst(ordChg);
-
- }
- }
-
- // TB_ORDER_CHANGE 변경
- withdrawExc.setUpdNo(userNo);
- withdrawDao.updateChangeReason(withdrawExc);
- }
- /**
- * 환불관리 상세정보
- *
- * @param withdraw - 변경주문번호
- * @return
- * @author moon
- * @since 2020. 11. 16
- */
- public Collection<Withdraw> getRefundDetailList(Withdraw withdraw) {
- return withdrawDao.getRefundDetailList(withdraw);
- }
- /**
- * 회수관리 > 환불컨펌 > 환불처리
- *
- * @param params
- * @return
- * @author moon
- * @since 2020. 11. 16
- */
- @Transactional("shopTxnManager")
- public void refundDetailConfirm(GagaMap params) {
- Integer userNo = params.getInt("userNo"); // 사용자번호
- String allCanYn = params.getString("allCanYn"); // 전체반품여부
- Integer ordNo = params.getInt("ordNo"); // 주문번호
- Integer custNo = params.getInt("custNo"); // 고객번호
- String chgReasonNm = params.getString("chgReasonNm"); // 변경사유
- String chgReason = params.getString("chgReason"); // 변경사유코드
- String accountNm = params.getString("accountNm"); // 환불계좌이름
- String accountNo = CryptoUtils.decryptAES(params.getString("accountNo")); // 환불계좌번호
- String bankCd = params.getString("bankCd"); // 환불계좌은행코드
- String ordNm = params.getString("ordNm"); // 주문자명
- Integer delvAddrSq = params.getInt("delvAddrSq"); // 배송지번호
- int addDeliveryFee = params.getInt("addDeliveryFee"); // 추가배송비
- String addDeliveryFeeYn = params.getString("addDeliveryFeeYn"); // 추가배송비여부
- String mallGb = params.getString("mallGb"); // 몰구분
- Integer ordChgSq = params.getInt("ordChgSq"); // 변경요청번호
- String pgStat = params.getString("pgStat"); // PG점프
- int depositAmt = params.getInt("depositAmt"); // PG점프 임금액
- int codFee = params.getInt("codFee"); // 착불비
- String codFeeYn = params.getString("codFeeYn"); // 착불비여부
- String enCloseFeeYn = params.getString("enCloseFeeYn"); // 동봉비여부
- int enCloseFee = params.getInt("enCloseFee"); // 동봉비
- String wdInvoiceNo = params.getString("wdInvoiceNo"); // 회수송장번호
- String wdGb = params.getString("wdGb"); // 회수구분
- int addPayCost = params.getInt("addPayCost"); // 추가배송비
- String delvExpnYn = params.getString("delvExpnYn"); // 확정후 품절,불량 여부
- String delvFeeCd = params.getString("delvFeeCd"); // 배송비정책코드
- String pgGb = params.getString("pgGb"); // PG 구분
- String payMeans = params.getString("payMeans");
- String batchYn = "N";
- // OrderChange change = new OrderChange();
- // change.setOrdNo(params.getInt("ordNo"));
- // change.setCustNo(params.getInt("custNo"));
- // change.setOrderNm(params.getString("ordNm"));
- // change.setPgGb(params.getString("pgGb"));
- // change.setPayMeans(params.getString("payMeans"));
- // change.setBankCd(params.getString("bankCd"));
- // change.setAccountNm(params.getString("accountNm"));
- // change.setAccountNo(CryptoUtils.decryptAES(params.getString("accountNo")));
- // //change.getOrdDtlNoList().add(params.getOrdDtlNo());
- // //change.getCnclRtnReqQtyList().add(params.getCnclRtnQty());
- // change.setChgReason(params.getString("chgReason"));
- // change.setChgReasonNm(params.getString("chgReasonNm"));
- // change.setBatchYn("N");
- // change.setDelvAddrSq(params.getInt("delvAddrSq"));
- // change.setAddDeliveryFeeYn(params.getString("addDeliveryFeeYn"));
- // change.setAddDeliveryFee(params.getInt("addDeliveryFee"));
- // change.setRegNo(userNo);
- // change.setUpdNo(userNo);
- // change.setUserNo(userNo);
- // change.setOrdChgSq(params.getInt("ordChgSq"));
- // change.setMallGb(params.getString("mallGb"));
- // change.setSpanRefundAmt(params.getInt("spanRefundAmt"));
- // change.setPgStat(params.getString("pgStat"));
- // change.setCodFeeYn(params.getString("codFeeYn"));
- // change.setCodFee(params.getInt("codFee"));
- // change.setEnCloseFeeYn(params.getString("enCloseFeeYn"));
- // change.setEncloseFee(params.getInt("enCloseFee"));
- // change.setWdInvoiceNo(params.getString("wdInvoiceNo"));
- try {
- OrderChange orderChange = new OrderChange();
- orderChange.setOrdChgSq(ordChgSq);
- orderChange.setUserNo(userNo);
- GagaMap info = orderChangeService.refundConfirmPreInfo(orderChange);
- info.set("chgReasonNm" , chgReasonNm); // 변경사유
- info.set("chgReason" , chgReason); // 변경사유코드
- info.set("accountNm" , accountNm); // 환불계좌이름
- info.set("accountNo" , accountNo); // 환불계좌번호
- info.set("bankCd" , bankCd); // 환불계좌은행코드
- info.set("custNo" , custNo); // 고객번호
- info.set("ordNm" , ordNm); // 주문자명
- info.set("delvAddrSq" , delvAddrSq); // 배송지번호
- info.set("delvExpnYn" , delvExpnYn); // 확정후반품,불량여부
- info.set("addDeliveryFee" , addDeliveryFee); // 추가배송비
- info.set("addDeliveryFeeYn" , addDeliveryFeeYn); // 추가배송비여부
- info.set("mallGb" , mallGb); // 몰구분
- info.set("ordNo" , ordNo); // 주문번호
- info.set("ordChgSq" , ordChgSq); // 변경요청번호
- info.set("pgStat" , pgStat); // PG점프
- info.set("depositAmt" , depositAmt); // PG점프 입금액
- info.set("codFee" , codFee); // 착불비
- info.set("codFeeYn" , codFeeYn); // 착불비여부
- info.set("enCloseFeeYn" , enCloseFeeYn); // 동봉비여부
- info.set("enCloseFee" , enCloseFee); // 동봉비
- info.set("wdInvoiceNo" , wdInvoiceNo); // 회수송장번호
- info.set("wdGb" , wdGb); // 회수구분
- info.set("addPayCost" , addPayCost); // 추가배송비
- info.set("allCanYn" , allCanYn); // 전체반품여부
- info.set("delvExpnYn" , delvExpnYn); // 확정후 품절,불량 여부
- info.set("delvFeeCd" , delvFeeCd); // 배송비정책코드
- if ("Y".equals(allCanYn)) {
- // orderChangeService.allRefund(change);
- orderChangeService.allRefund(info, userNo);
- } else {
- orderChangeService.partialRefund(info, userNo);
- }
- // 네이버페이 환불컨펌
- if(TscConstants.PgGb.NAVER_ORDER.value().equals(pgGb)) {
- // PG 미전송이 아닐 경우 (Y면 미전송, N이면 전송)
- if("N".equals(pgStat)) {
- // WMS 예외로 넘어온 데이터인지 확인 후 네이버페이 진행
- Collection<OrderChange> exceptions = orderChangeDao.getOrderRecallExceptionInfo(orderChange); // 예외 품절 및 불량 정보 조회
- int i = 0;
- for(OrderChange exception : exceptions) {
- if(exception.getOrderDtlNo() > 0) { // 확정 후 품절 및 불량이 있을경우
- if("O".equals(exception.getOrdExchGb())) { // 원배송 확정 후 품절 및 불량
- // 품절 취소 송부
- Order param = new Order();
- param.setOrdDtlNo(exception.getOrdDtlNo());
- // coreNaverPayService.sendNaverPaySoldoutCancel(param, userNo); // 품절취소
- String addUrl = "/naverpay/send/soldout/cancel?ordDtlNo=" + exception.getOrdDtlNo() + "&userNo=" + userNo;
- coreNaverPayService.sendScmServerForNaverpay(addUrl); // 품절취소
- } else if ("E".equals(exception.getOrdExchGb())){ // 교환 후 확정 후 품절 및 불량
- // 교환 반려 > 반품 접수 > 반품 완료
- String addUrl = "";
- // 네이버페이는 SCM을 통해서 송부
- // coreNaverPayService.sendNaverPayRejectExchange(exception, userNo); // 교환반려
- addUrl = "/naverpay/send/reject/exchange?ordDtlNo=" + exception.getOrdDtlNo() + "&userNo=" + userNo;
- coreNaverPayService.sendScmServerForNaverpay(addUrl); // 교환 반려
- // coreNaverPayService.sendNaverPaySoldoutReturnReq(param, userNo); // 품절반품접수
- addUrl = "/naverpay/send/soldout/return/req?ordDtlNo=" + exception.getOrdDtlNo() + "&userNo=" + userNo;
- coreNaverPayService.sendScmServerForNaverpay(addUrl); // 품절반품접수
- // coreNaverPayService.sendNaverPayReturnComplete(exception, userNo); // 반품완료
- addUrl = "/naverpay/send/return/complete?ordDtlNo=" + exception.getOrdDtlNo() + "&userNo=" + userNo;
- coreNaverPayService.sendScmServerForNaverpay(addUrl); // 반품완료
- }
- } else { // 정상 반품 완료
- // coreNaverPayService.sendNaverPayReturnComplete(exception, userNo); // 반품완료
- String addUrl = "/naverpay/send/return/complete?ordDtlNo=" + exception.getOrdDtlNo() + "&userNo=" + userNo;
- coreNaverPayService.sendScmServerForNaverpay(addUrl); // 반품완료
- }
- i++;
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- throw new IllegalStateException("실패");
- }
- }
- /**
- * 회수 철회 알림톡(KAKAO)
- *
- * @param Withdraw
- * @return void
- * @author moon
- * @since 2021. 07. 21
- */
- @Transactional("shopTxnManager")
- public void sendRecallCancel(Withdraw withdraw) {
- Integer userNo = TsaSession.getInfo().getUserNo();
- String gubun = withdraw.getGubun();
-
- Withdraw refundOrdchgSq = new Withdraw();
- refundOrdchgSq.setOrdChgSq(withdraw.getOrdChgSq());
- Withdraw info = withdrawDao.getWithdrawInfo(refundOrdchgSq);
-
- Order order = new Order();
- order.setOrdNo(info.getOrdNo());
- order.setCustNo(info.getCustNo());
- order.setOrdNm(info.getOrdNm());
- order.setGoodsNm(info.getGoodsNm());
- order.setGoodsCnt(info.getGoodsCnt()+"");
- order.setOrdPhnno(info.getOrdPhnno());
- order.setChgerBaseAddr(info.getChgerBaseAddr());
-
- try {
- kakaotalkService.sendRecallCancel(order, userNo, gubun);
- } catch(Exception e) {
- log.debug("kakaotalkService Exception OrdNo:"+withdraw.getOrdNo());
- }
- }
-
- public Withdraw getRefundInfo(Withdraw withdraw) {
- return withdrawDao.getRefundInfo(withdraw);
- }
- /**
- * 회수예외 CS메모저장
- *
- * @param Delivery
- * @return
- * @author moon
- * @since 2021. 08. 20
- */
- @Transactional("shopTxnManager")
- public void updateCsMemo(WithdrawExc withdrawExc) {
- withdrawDao.updateCsMemo(withdrawExc);
- }
- }
|