hyeonga_code

reProject_48_관리자 주문 페이지, 교환/환불 요청 확인, 교환/환불 처리, 아임포트 환불 처리(부분 취소/전액 취소) 본문

Project_WEATHERWEAR

reProject_48_관리자 주문 페이지, 교환/환불 요청 확인, 교환/환불 처리, 아임포트 환불 처리(부분 취소/전액 취소)

hyeonga 2024. 2. 21. 05:59
반응형

 

2024.02.20

관리자 주문 페이지

-- 교환과 환불 데이터만 모아 볼 수 있는 버튼 생성

-- 환불 요청인 데이터 주문상태를 환불진행중/환불완료 이외의 것으로 변경 불가

-- 환불 완료로 변경시, 환불 금액 입력창 생성(부분취소/전액취소)

 

정보 창을 띄우기 위해 ajax를 한 번 더 타는 방법과 처음 orderLsit를 조회할 때, 같이 정보를 조회해오는 방법이 있었는데, 데이터가 많지 않고 sweetalert2 을 사용하기 때문에 ajax()를 한 번 더 요청하는 것보다 한 번에 데이터를 불러오는 것이 좋다고 생각하여 진행했다.

 

-- 요약

//Controller
    /** 교환, 환불 처리완료 */
    @ResponseBody
    @PostMapping("updateRefundSwapStatus.mdo")
    public ResponseDTO<String> updateRefundSwapStatus(String requestWhat, String id, String status, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        
        Map<String, Object> requestInfo = new HashMap<String, Object>();
        requestInfo.put("requestWhat", requestWhat);
        requestInfo.put("id", id);
        requestInfo.put("status", status);
 
        try {
            int result = orderService.updateSwapRefund(requestInfo);
            if(result > 0) {
                code = 1;
                resultCode = "success";
                msg = "요청이 완료되었습니다.";
            } else {
                code = -1;
                resultCode = "fail";
                msg = "오류가 발생했습니다.";
            }
        } catch (Exception e) {
            code = -1;
            resultCode = "fail";
            msg = "오류가 발생했습니다.";
        }
        
        return new ResponseDTO<String>(statusCode, code, resultCode, msg, id);
    }
 
//Service
    int updateSwapRefund(Map<String, Object> requestInfo);
 
//ServiceImpl
    @Autowired
    private OrderDAO orderDAO;
 
    @Override
    public int updateSwapRefund(Map<String, Object> requestInfo) {
        return orderDAO.updateSwapRefund(requestInfo);
    }
 
//DAO
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
 
    public int updateSwapRefund(Map<String, Object> requestInfo) {
        return sqlSessionTemplate.update("OrderDAO.updateSwapRefund", requestInfo);
    }
 
//mapping.xml
    <update id="updateSwapRefund" parameterType="hashMap">
        UPDATE ${ requestWhat } 
        SET
            <if test="requestWhat == 'refund'">refundStatus = #{ status } WHERE refundId = #{ id }</if>
            <if test="requestWhat == 'swap'">swapStatus = #{ status } WHERE swapId = #{ id }</if>
    </update>
 
cs

 

 

 

orderList.jsp 수정(admin)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WeatherWear 관리자</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<!-- Font Awesome -->
<link href="resources/admin/AdminLTE/plugins/fontawesome-free/css/all.min.css" rel="stylesheet">
<!-- Theme style -->
<link href="resources/admin/AdminLTE/dist/css/adminlte.min.css" rel="stylesheet">
<style>
    .orderStatus_select {width: 130px !important;}
    .option_select {width: 100px !important;}
    .deliveryNum_select {display: none;}
    .check {width:20px; height:20px;}
</style>
</head>
<body class="hold-transition sidebar-collapse layout-top-nav">
    <div class="wrapper">
        <%@ include file="../header.jsp" %>
    
        <div class="content-header">
            <section class="content-header">
                <div class="container">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1>주문 목록</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="main.mdo">메인</a></li>
                                <li class="breadcrumb-item active">주문 목록</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </section>
            <section class="content">
                <div class="container">
                    <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-header">
                                    <div class="card-title">
                                        <div class="orderby_btn">
                                            <button id="orderDate" type="button" class="orderbyBtn btn btn-sm btn-outline-light <c:if test="${search.orderby == 'orderDate'}">active</c:if>">최신순</button>
                                            <button id="clientId" type="button" class="orderbyBtn btn btn-sm btn-outline-light <c:if test="${search.orderby == 'clientId'}">active</c:if>">아이디순</button>
                                            <button id="orderStatus" type="button" class="orderbyBtn btn btn-sm btn-outline-light <c:if test="${search.orderby == 'orderStatus'}">active</c:if>">주문상태순</button>
                                            <button id="swap" type="button" class="orderbyBtn btn btn-sm btn-outline-light <c:if test="${search.orderby == 'swap'}">active</c:if>">교환</button>
                                            <button id="refund" type="button" class="orderbyBtn btn btn-sm btn-outline-light <c:if test="${search.orderby == 'refund'}">active</c:if>">환불</button>
                                            <button class="btn btn-sm btn-secondary buttons-pdf buttons-html5 download" tabindex="0" aria-controls="example1" type="button" id="excelDownload" onclick="exportExcel('주문내역')">
                                                <span>Excel 저장</span>
                                            </button>
                                        </div>
                                    </div>
                                    <div class="card-tools">
                                        <!-- Search -->
                                        <div class="input-group input-group-sm">
                                            <select id="searchType" class="form-control">
                                                <option value="orderId">주문번호</option>
                                                <option value="clientId">아이디</option>
                                            </select>
                                            <input type="text" id="keyword" class="form-control float-right" placeholder="Search">
                                            <div class="input-group-append">
                                                <button type="button" class="btn btn-default" id="btnSearch">
                                                    <i class="fas fa-search"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <!-- End Search -->
                                    </div>
                                </div>
                                <div class="card-header">
                                    <div class="card-title">
                                        <div class="orderby_btn">
                                            <div class="input-group input-group-sm">
                                                <select class="form-control option_select" onchange="change(this)" id="modifyType">
                                                    <option value="orderStatus">주문상태</option>
                                                    <option value="deliverNum">송장번호</option>
                                                </select>&nbsp;&nbsp;&nbsp;
                                                <div class="input-group-sm orderStatus_select">
                                                    <select class="form-control orderStatus_select" id="orderStatus_value">
                                                        <option value="상품준비중">상품준비중</option>
                                                        <option value="배송준비중">배송준비중</option>
                                                        <option value="배송보류">배송보류</option>
                                                        <option value="배송대기">배송대기</option>
                                                        <option value="배송중">배송중</option>
                                                        <option value="배송완료">배송완료</option>
                                                        <option value="교환진행중">교환진행중</option>
                                                        <option value="환불진행중">환불진행중</option>
                                                        <option value="교환완료">교환완료</option>
                                                        <option value="환불완료">환불완료</option>
                                                    </select>
                                                </div>
                                                <div class="input-group-sm deliveryNum_select">
                                                    <input type="text" name="deliverNum_value" class="form-control float-right" placeholder="송장번호">
                                                </div>
                                                <div class="input-group-append">
                                                    <button id="add-new-event" type="button" class="btn btn-sm btn-outline-primary" onclick="modify()">수정하기</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="card-body table-responsive p-0">
                                    <form id="listForm" name="clientForm" method="post">
                                        <table class="table table-hover text-nowrap" style="table-layout: fixed;" id="tableData">
                                            <colgroup>
                                                <col width="80px"/><!-- # -->
                                                <col width="280px"/><!-- 주문번호 -->
                                                <col width="150px"/><!-- 주문상태 -->
                                                <col width="200px"/><!-- 주문일자 -->
                                                <col width="150px"/><!-- 회원번호 -->
                                                <col width="100px"/><!-- 구매자이름 -->
                                                <col width="150px"/><!-- 구매자연락처 -->
                                                <col width="500px"/><!-- 주문상품 -->
                                                <col width="150px"/><!-- 주문옵션 -->
                                                <col width="80px"/><!-- 주문수량 -->
                                                <col width="100px"/><!-- 상품금액 -->
                                                <col width="150px"/><!-- 수신인 이름 -->
                                                <col width="150px"/><!-- 수신인 연락처 -->
                                                <col width="250px"/><!-- 송장번호 -->
                                                <col width="100px"/><!-- 우편번호 -->
                                                <col width="250px"/><!-- 기본주소 -->
                                                <col width="250px"/><!-- 상세주소 -->
                                                <col width="250px"/><!-- 배송메모 -->
                                                <col width="100px"/><!-- 결제금액 -->
                                                <col width="150px"/><!-- 결제수단 -->
                                                <col width="100px"/><!-- 결제상태 -->
                                                <col width="200px"/><!-- 결제일자 -->
                                            </colgroup>
                                            <thead>
                                                <tr>
                                                    <th><button type="button" class="btn btn-sm btn-outline-primary checkAll" id="checkAll">전체선택</button></th>
                                                    <th>주문번호</th>
                                                    <th>주문상태</th>
                                                    <th>주문일자</th>
                                                    <th>회원번호</th>
                                                    <th>구매자 이름</th>
                                                    <th>구매자 연락처</th>
                                                    <th>주문상품</th>
                                                    <th>주문옵션</th>
                                                    <th>주문수량</th>
                                                    <th>상품금액</th>
                                                    <th>수신인 이름</th>
                                                    <th>수신인 연락처</th>
                                                    <th>송장번호</th>
                                                    <th>우편번호</th>
                                                    <th>기본주소</th>
                                                    <th>상세주소</th>
                                                    <th>배송메모</th>
                                                    <th>결제금액</th>
                                                    <th>결제수단</th>
                                                    <th>결제상태</th>
                                                    <th>결제일자</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <c:forEach var="item" items="${orderList}" varStatus="status">
                                                    <tr>
                                                        <td class="checklist"><input type="checkbox" value="${item.orderId}_${item.productId}_${item.optionName}" class="check"></td>
                                                        <td>${item.orderId}</td>
                                                        <td id="status_${ item.orderId }" onclick="checkInfo('${ item.orderId }', '${ item.refundId }', '${ item.swapId }')">
                                                            ${item.orderStatus}
                                                            <input type="hidden" id="optionId_${ item.orderId }" value="${ item.optionId }">
                                                            <input type="hidden" id="clientId_${ item.orderId }" value="${ item.clientId }">
                                                            <input type="hidden" id="clientNum_${ item.orderId }" value="${ item.clientNum }">
                                                            <c:if test="${ item.refundId != null || item.refundId == '' }">
                                                                <input type="hidden" id="refundId_${ item.orderId }" value="${ item.refundId }">
                                                                <input type="hidden" id="refundReason_${ item.refundId }" value="${ item.refundReason }">
                                                                <input type="hidden" id="refundKeyword_${ item.refundId }" value="${ item.refundKeyword }">
                                                                <input type="hidden" id="refundWay_${ item.refundId }" value="${ item.refundWay }">
                                                                <input type="hidden" id="refundCost_${ item.refundId }" value="${ item.refundCost }">
                                                                <input type="hidden" id="refundCostMtd_${ item.refundId }" value="${ item.refundCostMtd }">
                                                                <input type="hidden" id="refundBankId_${ item.refundId }" value="${ item.bankId }">
                                                                <input type="hidden" id="refundBankNum_${ item.refundId }" value="${ item.refundBankNum }">
                                                                <input type="hidden" id="refundStatus_${ item.refundId }" value="${ item.refundStatus }">
                                                                <input type="hidden" id="refundRegDate_${ item.refundId }" value="${ item.refundRegDate }">
                                                                <input type="hidden" id="refundEmail_${ item.refundId }" value="${ item.refundEmail }">
                                                            </c:if>
                                                            <c:if test="${ item.swapId != null || item.swapId == '' }">
                                                                <input type="hidden" id="swapId_${ item.orderId }" value="${ item.swapId }">
                                                                <input type="hidden" id="swapReason_${ item.swapId }" value="${ item.swapReason }">
                                                                <input type="hidden" id="swapKeyword_${ item.swapId }" value="${ item.swapKeyword }">
                                                                <input type="hidden" id="swapWay_${ item.swapId }" value="${ item.swapWay }">
                                                                <input type="hidden" id="swapCost_${ item.swapId }" value="${ item.swapCost }">
                                                                <input type="hidden" id="swapCostMtd_${ item.swapId }" value="${ item.swapCostMtd }">
                                                                <input type="hidden" id="swapStatus_${ item.swapId }" value="${ item.swapStatus }">
                                                                <input type="hidden" id="swapRegDate_${ item.swapId }" value="${ item.swapRegDate }">
                                                                <input type="hidden" id="swapEmail_${ item.swapId }" value="${ item.swapEmail }">
                                                            </c:if>
                                                        </td>
                                                        <td>${item.orderDate}</td>
                                                        <td>${item.clientId}</td>
                                                        <td>${item.clientName}</td>
                                                        <td>${fn:substring(item.clientNum,0,3)}-${fn:substring(item.clientNum,3,7)}-${fn:substring(item.clientNum,7,11)}</td>
                                                        <td>${item.productName}</td>
                                                        <td>${item.optionName}</td>
                                                        <td>${item.orderProCnt}</td>
                                                        <td><fmt:formatNumber value="${item.orderTotal}" pattern="###,###"/></td>
                                                        <td>${item.addressName}</td>
                                                        <td>${item.addressNum}</td>
                                                        <td><input type="text" value="${item.deliverNum}"></td>
                                                        <td>${item.addressPostNum}</td>
                                                        <td>${item.address1}</td>
                                                        <td>${item.address2}</td>
                                                        <td>${item.addressMemo}</td>
                                                        <td>
                                                            <fmt:formatNumber value="${item.orderPrice - item.usedPoint - item.couponPrice}" pattern="###,###"/>
                                                            <input type="hidden" id="proPrice_${ item.orderId }" value="${ item.orderTotal }">
                                                            <input type="hidden" id="orderPrice_${ item.orderId }" value="${ item.orderPrice }">
                                                            <input type="hidden" id="usedPoint_${ item.orderId }" value="${ item.usedPoint }">
                                                            <input type="hidden" id="couponPrice_${ item.orderId }" value="${ item.couponPrice }">
                                                            <input type="hidden" id="paymentId_${ item.orderId }" value="${ item.paymentId }">
                                                        </td>
                                                        <td>${item.paymentMethod}</td>
                                                        <td>${item.paymentStatus}</td>
                                                        <td>${item.paymentDate}</td>
                                                    </tr>
                                                </c:forEach>
                                            </tbody>
                                        </table>
                                    </form>
                                </div>
                                <!-- pagination -->
                                <div class="card-footer">        
                                    <div class="card-title input-group-sm">
                                        <select name="searchType" class="form-control" id="listSize" onchange="page(1)">
                                            <option value="5" <c:if test="${pagination.getListSize() == 5}">selected="selected"</c:if>>5개</option>
                                            <option value="10" <c:if test="${pagination.getListSize() == 10}">selected="selected"</c:if>>10개</option>
                                            <option value="15" <c:if test="${pagination.getListSize() == 15}">selected="selected"</c:if>>15개</option>
                                            <option value="30" <c:if test="${pagination.getListSize() == 30}">selected="selected"</c:if>>30개</option>
                                        </select>
                                    </div>
                                    <ul class="pagination pagination-sm m-0 float-right">
                                        <c:if test="${pagination.prev}">
                                            <li class="page-item">
                                                <a class="page-link" href="#" onclick="fn_prev('${pagination.page}', '${pagination.range}', '${pagination.rangeSize}', '${pagination.listSize}', '${search.searchType}', '${search.keyword}', '${search.orderby}')">&laquo;</a>
                                            </li>
                                        </c:if>
                                        <c:forEach begin="${pagination.startPage}" end="${pagination.endPage}" var="pageId">
                                            <li class="page-item <c:out value="${pagination.page == pageId ? 'active':''}"/>">
                                                <a class="page-link" href="#" onclick="fn_pagination('${pageId}', '${pagination.range}', '${pagination.rangeSize}', '${pagination.listSize}', '${search.searchType}', '${search.keyword}', '${search.orderby}')">${pageId}</a>
                                            </li>
                                        </c:forEach>                                        
                                        <c:if test="${pagination.next}">
                                            <li class="page-item">
                                                <a class="page-link" href="#" onclick="fn_next('${pagination.page}', '${pagination.range}', '${pagination.rangeSize}', '${pagination.listSize}', '${search.searchType}', '${search.keyword}', '${search.orderby}')">&raquo;</a>
                                            </li>
                                        </c:if>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>        
        <%@ include file="../footer.jsp" %>
    </div>
<!-- jQuery -->
<script src="resources/admin/AdminLTE/plugins/jquery/jquery.min.js"></script>
<script    src="resources/util/plugins/sweetalert/jquery-lates.min.js"></script>
<script src="resources/util/plugins/sweetalert/sweetalert2.js"></script>
<!-- Bootstrap 4 -->
<script src="resources/admin/AdminLTE/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Sheet JS (Excel)-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.3/xlsx.full.min.js"></script>
<!--FileSaver savaAs 이용 (Excel)-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js"></script>
<!-- sweetAlert (alert/confirm/toast) -->
<script src="resources/util/js/sweetalert.js"></script>
 
<script src="resources/util/js/paging.js"></script>
<script src="resources/util/js/checkbox.js"></script>
<script src="resources/util/js/saveExcel.js"></script>
<script src="resources/admin/js/manageOrderList.js"></script>
</body>
</html>
cs

 

 

 

manageOrderList.js 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
 * 주문 상태/송장번호 수정
 */
 function change(type){
    let value = type.value;
    switch(value){
    case 'orderStatus':
        document.querySelector(".orderStatus_select").style.display='flex';
        document.querySelector(".deliveryNum_select").style.display='none';
        break;
    case 'deliverNum':
        document.querySelector(".deliveryNum_select").style.display='flex';
        document.querySelector(".orderStatus_select").style.display='none';
        break;
    defaultreturn;
    }
}
 
function modify(){
    let checkList = [];
    let selectedList = document.querySelectorAll("input[type='checkbox']:checked");
    let modifyType = $("#modifyType").val();
    let changeValue;
    let orderId = selectedList[0].value.split("_")[0];
 
    if(modifyType == 'orderStatus'){
        changeValue = $("#orderStatus_value").val();
    } else if (modifyType == 'deliverNum'){
        changeValue = $("input[name='deliverNum_value']").val();
    }
    
    if(selectedList.length < 1){
        playToast("변경할 데이터를 선택해주세요"'warning');
        return;
    }
    
    for(let i=0; i<selectedList.length; i++){ 
        if(!checkList.includes(selectedList[i].value)){
            let order = {};
            
            order.modifyType = modifyType;
            order.changeValue = changeValue;
            order.orderId = selectedList[i].value.split("_")[0];
            order.productId = selectedList[i].value.split("_")[1];
            order.optionName = selectedList[i].value.split("_")[2];
            checkList.push(order);
        }
    }
    
    if(checkList.some(order => order.orderId !== checkList[0].orderId)){
        playToast("같은 주문번호만 일시 환불 처리가 가능합니다.""error");
        return
    }
            
    $.ajax({
        url: "/w2/orderUpdate.mdo?modifyType=" + modifyType,
        type: "POST",
        data: JSON.stringify(checkList),
        dataType: "json",
        contentType: "application/json",
        success: function(){
            if(changeValue != "환불완료"){
                let swapId = $("#swapId_" + orderId).val();
                let swapStatus = "교환완료";
                
                updateStatus("swap", swapId, swapStatus);
            } else {
                let proPrice = 0;
                let orderPrice = parseInt($("#orderPrice_" + orderId).val());
                let usedPoint = parseInt($("#usedPoint_" + orderId).val());
                let couponPrice = parseInt($("#couponPrice_" + orderId).val());
                let refundPrice = 0;
                let refundId = $("#refundId_" + orderId).val();
                let refundCost = $("#refundCost_" + refundId).val();
                let refundCostMtd = $("#refundCostMtd_" + refundId).val();
                
                checkList.forEach(order => {
                    proPrice = parseInt($("#proPrice_" + orderId).val());
                    refundPrice += proPrice;
                });
                
                let percentage = Math.floor(refundPrice/orderPrice*100)/100;
                console.log("percentage : " + percentage);
                let checkPrice = refundPrice - Math.floor((usedPoint + couponPrice)* percentage/100)*100;
                console.log("checkPrice : " + checkPrice);
                
                
                let refundInput = "<div class='row' style='border-bottom:1px solid silver; margin-bottom:10px;'></div>";
                refundInput += "<div class='confirmDiv'><div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>전체 주문 금액 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + orderPrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+"</b></div></div>";                        
                refundInput += "<div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>환불 상품 금액 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + refundPrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+"</b></div></div>";
                refundInput += "<div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>사용 포인트 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:lex-start; padding-left: 20px;'><b>" + usedPoint.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+"</b></div></div>";
                refundInput += "<div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>쿠폰 적용 금액 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + couponPrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+"</b></div></div><hr>";
                refundInput += "<div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>환불 금액 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + checkPrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+"</b></div></div>";
                if(refundCost > 0){
                    refundInput += "<div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>배송비 지불 방식 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + refundCostMtd +"</b></div></div>";
                    refundInput += "<div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>- 배송비 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + refundCost +"</b></div></div>";
                    refundInput += "<div class='refundDiv'><div class='row'><div class='refundDiv_sub' style='width:60%; display:flex; justify-content:flex-end;'>배송비 제외 금액 : </div><div class='refundDiv_sub' style='width:40%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + (checkPrice-refundCost).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+"</b></div></div>";
                    refundInput += "</div><hr><div class='refundDiv'><div class='refundDiv_sub'>환불 금액 입력하기 : <input type='text' id='checkPrice' placeholder='" + (checkPrice-refundCost).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+ "'></div></div>";
                } else {
                    refundInput += "</div><hr><div class='refundDiv'><div class='refundDiv_sub'>환불 금액 입력하기 : <input type='text' id='checkPrice' placeholder='" + checkPrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+ "'></div></div>";
                }
                let paymentId = $("#paymentId_"+orderId).val();
                
                Swal.fire({
                  title: "환불금액",
                  html: refundInput,
                  icon: "success",
                  showCancelButton: true,
                  confirmButtonColor: '#3085d6',
                  cancelButtonColor: '#d33',
                  confirmButtonText: "환불요청하기",
                  cancelButtonText: "취소하기",
                  reverseButtons: true// 버튼 순서 거꾸로
                }).then((result) => {
                    if(result.isConfirmed){    // 매개변수 list 안됨
                        let price = $("#checkPrice").val();
                        console.log("환불하기 : " + price);
                        $.ajax({
                            url: "/w2/refundPriceProc.do",
                            type: "POST",
                            data: {
                                refundPrice: price,
                                totalPrice: orderPrice,
                                paymentId: paymentId
                            },
                            dataType: "json",
                            success: function(res){
                                if(res.code == 1) {
                                    updateStatus("refund", refundId, "환불완료");
                                } else {
                                    playToast("환불 중 오류가 발생했습니다.""error");
                                    return;
                                }
                            },
                            error: function(){
                                console.log("환불 요청 실패");
                            }
                        });
                    } else {
                        console.log("환불 취소");
                    }
                });
                
            }
        },
        error: function(){
            console.log("실패");
        }
    });
}
 
function updateStatus(requestWhat, id, status){
    $.ajax({
        url: "/w2/updateRefundSwapStatus.mdo",
        type: "POST",
        data: {
            requestWhat: requestWhat,
            id: id,
            status: status
        },
        dataType: "json",
        success: function(res){
            if(res.code == 1){
                playToast(res.message, "success");
                setTimeout(function(){
                    window.location.reload();
                }, 2000);
            } else {
                playAlert(res.message, "error""오류 정보 : " + res.data, "orderList.mdo");
            }
        },
        error: function(){
            console.log("환불 요청 실패");
        }
    });
}
 
function checkInfo(orderId, refundId, swapId){
    let word;
    let tagName;
    let clientId = $("#clientId_" + orderId).val();
    let clientNum = $("#clientNum_" + orderId).val();
    
    if(refundId == '' && swapId == ''){
        console.log("교환/환불 없음");
        return;
    } 
    
    if(refundId == '' || swapId != ''){
        console.log("교환 요청");
        word = "교환";
        tagName = "#swap";
    } 
    
    if(swapId == '' || refundId != ''){
        console.log("환불 요청");
        word = "환불";
        tagName = "#refund";
    }
    
    let id = $(tagName + "Id_" + orderId).val();
    let    bankId = $(tagName + "BankId_" + id).val();
    let    bankNum = $(tagName + "BankNum_" + id).val();
    let optionId = $("#optionId_" + orderId).val();
    let reason = $(tagName + "Reason_" + id).val();
    let keyword = $(tagName + "Keyword_" + id).val();
    let way = $(tagName + "Way_" + id).val();
    let cost = $(tagName + "Cost_" + id).val();
    let costMtd = $(tagName + "CostMtd_" + id).val();
    let status = $(tagName + "Status_" + id).val();
    let regDate = $(tagName + "regDate_" + id).val();
    let email = $(tagName + "Email_" + id).val();
    
                    
    let InfoInput = "<div class='row' style='border-bottom:1px solid silver; margin-bottom:10px;'></div>";
    InfoInput += "<div class='confirmDiv'><div class='InfoDiv'><div class='row'><div class='InfoDiv_sub'><h4>" + word + " 요청</h4></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>주문 번호 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + orderId +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>옵션 번호 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + optionId +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>카테고리 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + keyword +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>" + word + " 사유 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + reason +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>수거 방법 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + way +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>추가 비용 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + cost.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","+"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>" + word + " 상태 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + status +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>신청일자 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + regDate +"</b></div></div><hr>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub'><h4> 기본 정보</h4></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>회원 아이디 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + clientId +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>연락처 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + clientNum +"</b></div></div>";
    InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>이메일 : </div>";
    InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + email +"</b></div></div>";
    InfoInput += "<input type='hidden' value='" + id + "' id='id'>";
    
    if(word == "환불"){
        InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>" + word + " 은행 : </div>";
        InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + bankId +"</b></div></div>";
        InfoInput += "<div class='InfoDiv'><div class='row'><div class='InfoDiv_sub' style='width:30%; display:flex; justify-content:flex-end;'>" + word + " 은행 계좌 : </div>";
        InfoInput += "<div class='InfoDiv_sub' style='width:70%; display:flex; justify-content:flex-start; padding-left: 20px;'><b>" + bankNum +"</b></div></div>";
    }
    
    InfoInput += "</div>";
 
    Swal.fire({
      title: word + "정보",
      html: InfoInput,
      icon: "success",
      showCancelButton: false,
      confirmButtonColor: '#3085d6',
      confirmButtonText: "닫기",
    }).then((result) => {
        if(result.isConfirmed){    // 매개변수 list 안됨
            return;    
        }
    });
    
}
cs

 

 

 

OrderController.java 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.w2.admin.controller;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.w2.order.service.OrderService;
import com.w2.util.ResponseDTO;
import com.w2.util.SearchOrderby;
 
@Controller
public class OrderController {
    @Autowired
    private OrderService orderService;
 
    /**
     * 주문 목록 가져오기
     * @param model
     * @return
     */
    @RequestMapping("orderList.mdo")
    public String orderList(Model model, @RequestParam(required = false, defaultValue = "1"int page,
            @RequestParam(required = false, defaultValue = "1"int range, @RequestParam(required = false, defaultValue = "orderName"String searchType,
            @RequestParam(required = falseString keyword, @RequestParam(required = false, defaultValue = "orderDate"String orderby, @ModelAttribute("search") SearchOrderby search) {
 
        // 검색
        search.setSearchType(searchType);
        search.setKeyword(keyword);
        search.setOrderby(orderby);
        model.addAttribute("search", search);
        
        // 전체 게시글 개수
        int listCnt = orderService.getOrderListCnt(search);
        
        // 검색 페이지 정보
        search.pageInfo(page, range, listCnt);
        // 페이징
        model.addAttribute("pagination", search);
        // 화면 출력
        model.addAttribute("orderList", orderService.getOrderList(search));
        
        return "order/orderList";
    }
 
    /**
     * 주문 수정
     * @param model
     * @return
     */
    @PostMapping("orderUpdate.mdo")
    public void orderUpdate(Model model, HttpServletResponse response, 
                    @RequestBody List<Map<StringString>> checkList, @RequestParam("modifyType")String modifyType) throws IOException {
        int code = -1;
        
        if(modifyType.equals("orderStatus")) {
            code = orderService.updateOrderStatus(checkList);
        } else if(modifyType.equals("deliverNum")) {
            code = orderService.updateDeliverNum(checkList);
        }
 
        response.setContentType("application/json");
        response.getWriter().write(String.valueOf(code));
    }
 
    /** 교환, 환불 처리완료 */
    @ResponseBody
    @PostMapping("updateRefundSwapStatus.mdo")
    public ResponseDTO<String> updateRefundSwapStatus(String requestWhat, String id, String status, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        
        Map<String, Object> requestInfo = new HashMap<String, Object>();
        requestInfo.put("requestWhat", requestWhat);
        requestInfo.put("id", id);
        requestInfo.put("status", status);
 
        try {
            int result = orderService.updateSwapRefund(requestInfo);
            if(result > 0) {
                code = 1;
                resultCode = "success";
                msg = "요청이 완료되었습니다.";
            } else {
                code = -1;
                resultCode = "fail";
                msg = "오류가 발생했습니다.";
            }
        } catch (Exception e) {
            code = -1;
            resultCode = "fail";
            msg = "오류가 발생했습니다.";
        }
        
        return new ResponseDTO<String>(statusCode, code, resultCode, msg, id);
    }
}
 
cs

 

 

 

OrderService.java 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.w2.order.service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.w2.cart.CartVO;
import com.w2.client.ClientVO;
import com.w2.util.SearchOrderby;
 
public interface OrderService {
 
    List<HashMap<String, Object>> getOrderList(SearchOrderby search);    // 주문 목록 가져오기
    int getOrderListCnt(SearchOrderby search);                            // 주문 목록 개수 가져오기
    int updateOrderStatus(List<Map<StringString>> checkList);         // 주문 상태 수정
    int updateDeliverNum(List<Map<StringString>> checkList);            // 송장번호 수정
    
    // 사용자
    List<CartVO> getOrderProductList(Map<String, Object> orderMap);
    
    ClientVO setClient(String string);    
    int insertImsiOrder(Map<String, Object> data);                        // 주문 등록
    Map<String, Object> getOrderInfo(String orderId);                    // 주문 상세
    List<Map<String, Object>> getOrderInfoList(String orderId);            // 주문 상품 목록
    int updateOrder(Map<String, Object> orderData);                        // 주문 상태 수정
    int insertSwapRefund(Map<String, Object> requestInfo);                // 교환/환불 요청
    int insertPayment(Map<String, Object> data);                        // 결제 정보 등록
    
    List<Map<String, Object>> getMyOrderList(HashMap<String, Object> param);    // 나의 주문 내역
    int getMyOrderListCnt(HashMap<String, Object> param);                // 나의 주문 내역 개수 조회
    int updateSwapRefund(Map<String, Object> requestInfo);                // 교환/환불 수정
}
 
cs

 

 

 

OrderServiceImpl.java 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.w2.order.service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.w2.cart.CartVO;
import com.w2.client.ClientVO;
import com.w2.order.OrderDAO;
import com.w2.util.SearchOrderby;
 
@Transactional(readOnly=true)
@Service("OrderService")
public class OrderServiceImpl implements OrderService {
 
    @Autowired
    private OrderDAO orderDAO;
    
    @Override
    public List<HashMap<String, Object>> getOrderList(SearchOrderby search) {
        return orderDAO.getOrderList(search);
    }
 
    @Override
    public int getOrderListCnt(SearchOrderby search) {
        return orderDAO.getOrderListCnt(search);
    }
 
    @Override
    public int updateOrderStatus(List<Map<StringString>> checkList) {
        return orderDAO.updateOrderStatus(checkList);
    }
 
    @Override
    public int updateDeliverNum(List<Map<StringString>> checkList) {
        return orderDAO.updateDeliverNum(checkList);
    }
 
    @Override
    public List<CartVO> getOrderProductList(Map<String, Object> orderMap) {
        return orderDAO.getOrderProductList(orderMap);
    }
 
    @Override
    public ClientVO setClient(String clientId) {
        return orderDAO.setClient(clientId);
    }
 
    @Override
    @Transactional
    public int insertImsiOrder(Map<String, Object> data) {
        int result = orderDAO.insertAddress(data);
        
        if(data.get("cookieId")== null) {
            if(data.get("addressBase").equals("Y")) {
                result = orderDAO.updateBaseAddress(data);
            }
            result = orderDAO.updateClientPoint(data);
        }
 
        result = orderDAO.insertOrder(data);
        result = orderDAO.insertOrderInfo(data);
        if(data.get("usedCouponInfo"!= null) {
            result = orderDAO.updateCouponList(data);
        }
        result = orderDAO.updateProductStock(data);
        result = orderDAO.deleteCart(data);
        return result;
    }
 
    @Override
    public Map<String, Object> getOrderInfo(String orderId) {
        return orderDAO.getOrderInfo(orderId);
    }
 
    @Override
    public List<Map<String, Object>> getOrderInfoList(String orderId) {
        return orderDAO.getOrderInfoList(orderId);
    }
 
    @Override
    public List<Map<String, Object>> getMyOrderList(HashMap<String, Object> param) {
        return orderDAO.getMyOrderList(param);
    }
 
    @Override
    public int getMyOrderListCnt(HashMap<String, Object> param) {
        return orderDAO.getMyOrderListCnt(param);
    }
 
    @Override
    public int updateOrder(Map<String, Object> orderData) {
        return orderDAO.updateOrderStatus(orderData);
    }
 
    @Override
    public int insertSwapRefund(Map<String, Object> requestInfo) {
        return orderDAO.insertSwapRefund(requestInfo);
    }
 
    @Override
    public int insertPayment(Map<String, Object> data) {
        return orderDAO.insertPayment(data);
    }
 
    @Override
    public int updateSwapRefund(Map<String, Object> requestInfo) {
        return orderDAO.updateSwapRefund(requestInfo);
    }
}
 
cs

 

 

 

OrderDAO.java 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.w2.order;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import com.w2.cart.CartVO;
import com.w2.client.ClientVO;
import com.w2.util.SearchOrderby;
 
@Repository
public class OrderDAO {
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
 
    public List<HashMap<String, Object>> getOrderList(SearchOrderby search) {
        return sqlSessionTemplate.selectList("OrderDAO.getOrderList", search);
    }
 
    public int getOrderListCnt(SearchOrderby search) {
        return sqlSessionTemplate.selectOne("OrderDAO.getOrderListCnt", search);
    }
 
    public int updateOrderStatus(List<Map<StringString>> checkList) {
        int result = -1;
        result = sqlSessionTemplate.update("OrderDAO.updateOrderStatus", checkList);
        return result;
    }
 
    public int updateDeliverNum(List<Map<StringString>> checkList) {
        int result = -1;
        result = sqlSessionTemplate.update("OrderDAO.updateDeliverNum", checkList);
        return result;
    }
 
    public List<CartVO> getOrderProductList(Map<String, Object> orderMap) {
        return sqlSessionTemplate.selectList("CartDAO.getOrderProductList", orderMap);
    }
 
    public ClientVO setClient(String clientId) {
        return sqlSessionTemplate.selectOne("ClientDAO.getClient", clientId);
    }
 
    public int insertAddress(Map<String, Object> data) {
        return sqlSessionTemplate.insert("OrderDAO.insertAddress", data);
    }
 
    public int updateBaseAddress(Map<String, Object> data) {
        return sqlSessionTemplate.update("OrderDAO.updateBaseAddress", data);
    }
 
    public int insertOrder(Map<String, Object> data) {
        return sqlSessionTemplate.insert("OrderDAO.insertOrder", data);
    }
 
    public int insertOrderInfo(Map<String, Object> data) {
        return sqlSessionTemplate.insert("OrderDAO.insertOrderInfo", data);
    }
 
    public int updateClientPoint(Map<String, Object> data) {
        System.err.println("updateClientPoint");
        return sqlSessionTemplate.update("OrderDAO.updateClientPoint", data);
    }
 
    public int updateCouponList(Map<String, Object> data) {
        System.err.println("updateCouponList");
        return sqlSessionTemplate.update("OrderDAO.updateCouponList", data);
    }
 
    public int insertPayment(Map<String, Object> data) {
        System.err.println("insertPayment");
        return sqlSessionTemplate.insert("OrderDAO.insertPayment", data);
    }
 
    public int deleteCart(Map<String, Object> data) {
        System.err.println("deleteCart");
        return sqlSessionTemplate.delete("OrderDAO.deleteCart", data);
    }
 
    public int updateProductStock(Map<String, Object> data) {
        return sqlSessionTemplate.update("OrderDAO.updateProductStock", data);
    }
    
    public Map<String, Object> getOrderInfo(String orderId) {
        return sqlSessionTemplate.selectOne("OrderDAO.getOrderInfo", orderId);
    }
    
    public List<Map<String, Object>> getOrderInfoList(String orderId) {
        return sqlSessionTemplate.selectList("OrderDAO.getOrderInfoList", orderId);
    }
    
    /** 나의 주문 내역 */
    public List<Map<String, Object>> getMyOrderList(HashMap<String, Object> param) {
        return sqlSessionTemplate.selectList("OrderDAO.getMyOrderList", param);
    }
    
    public int getMyOrderListCnt(HashMap<String, Object> param) {
        return sqlSessionTemplate.selectOne("OrderDAO.getMyOrderListCnt", param);
    }
    
    public int updateOrderStatus(Map<String, Object> orderData) {
        return sqlSessionTemplate.update("OrderDAO.updateOrderInfo", orderData);
    }
 
    public int insertSwapRefund(Map<String, Object> requestInfo) {
        return sqlSessionTemplate.insert("OrderDAO.insertSwapRefund", requestInfo);
    }
 
    public int updateSwapRefund(Map<String, Object> requestInfo) {
        return sqlSessionTemplate.update("OrderDAO.updateSwapRefund", requestInfo);
    }
}
 
cs

 

 

 

order-mapping.xml 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
                 
<mapper namespace="OrderDAO">
    <select id="getOrderList" resultType="hashMap">
        SELECT od.orderId, od.orderDate, od.clientId, od.couponId,
            cl.clientName, cl.clientNum, di.deliverNum,
            ad.addressName, ad.addressNum, ad.addressPostNum, ad.address1, ad.address2, ad.addressMemo,
            pr.productName, pr.productId, SUBSTRING(oi.optionId, LENGTH(pr.productId)+1) as optionName, oi.orderProCnt, oi.orderTotal, oi.orderStatus, 
            od.orderPrice, od.usedPoint, COALESCE(ci.couponPrice, 0) AS couponPrice, pi.paymentMethod, pi.paymentDate, pi.paymentStatus, pi.paymentId,
            sw.*, rf.*
        FROM orders od
        LEFT JOIN orders_info oi ON (od.orderId=oi.orderId)
        LEFT JOIN client cl ON (od.clientId=cl.clientId)
        LEFT JOIN client_address ad ON (od.clientId=ad.clientId AND od.addressId=ad.addressId)
        LEFT JOIN payment_info pi ON (od.orderId=pi.orderId)
        LEFT JOIN deliver_info di ON (od.orderId=di.orderId)
        LEFT JOIN coupon_info ci ON (od.couponId=ci.couponId)
        LEFT JOIN product pr ON (SUBSTRING(oi.optionId, 1, LENGTH(pr.productId))=pr.productId)
        LEFT JOIN swap sw ON (od.orderId = sw.orderId AND oi.optionId = sw.optionId)
        LEFT JOIN refund rf ON (od.orderId = rf.orderId AND oi.optionId = rf.optionId)
        <trim prefix="WHERE" prefixOverrides="AND|OR">
            <if test="keyword != null and keyword != ''">
                <if test="searchType == 'orderId'">
                    AND od.orderId like CONCAT('%', #{keyword}, '%')
                </if>
                <if test="searchType == 'clientId'">
                    AND od.clientId like CONCAT('%', #{keyword}, '%')
                </if>
            </if>
        </trim>
        <if test="orderby == 'swap'">
            WHERE oi.orderStatus IN ("교환진행중", "교환요청")
        </if>
        <if test="orderby == 'refund'">
            WHERE oi.orderStatus IN ("환불진행중", "환불요청")
        </if>
        ORDER BY 
            <choose>
                <when test="orderby == 'clientId'">
                    od.clientId ASC , od.orderId DESC
                </when>
                <when test="orderby == 'orderStatus'">
                    CASE WHEN oi.orderStatus = '상품준비중' THEN 1
                        WHEN oi.orderStatus = '배송준비중' THEN 2
                        WHEN oi.orderStatus = '배송보류' THEN 3
                        WHEN oi.orderStatus = '배송대기' THEN 4
                        WHEN oi.orderStatus = '배송중' THEN 5
                        WHEN oi.orderStatus = '배송완료' THEN 6
                        WHEN oi.orderStatus = '교환진행중' THEN 7
                        WHEN oi.orderStatus = '환불진행중' THEN 8
                        WHEN oi.orderStatus = '교환완료' THEN 9
                        WHEN oi.orderStatus = '환불완료' THEN 10
                    END
                </when>
                <otherwise>
                    od.orderDate DESC
                </otherwise>
            </choose>
        LIMIT #{startList}, #{listSize};
    </select>
    
    <select id="getOrderListCnt" resultType="int">
        SELECT count(*)
        FROM orders_info oi
        LEFT JOIN orders od ON (oi.orderId=od.orderId)
        <trim prefix="WHERE" prefixOverrides="AND|OR">
            <if test="keyword != null and keyword != ''">
                <if test="searchType == 'orderId'">
                    AND od.orderId like CONCAT('%', #{keyword}, '%')
                </if>
                <if test="searchType == 'clientId'">
                    AND od.clientId like CONCAT('%', #{keyword}, '%')
                </if>
            </if>
        </trim>
        ORDER BY 
            <choose>
                <when test="orderby == 'clientId'">
                    od.clientId
                </when>
                <when test="orderby == 'orderStatus'">
                    oi.orderStatus
                </when>
                <otherwise>
                    od.orderDate
                </otherwise>
            </choose>
        , od.orderId
    </select>
    
    <update id="updateOrderStatus" parameterType="java.util.List">
        <foreach collection="list" item="order" index="index">
            UPDATE orders_info SET orderStatus=#{ order.changeValue }
            WHERE orderId=#{ order.orderId } AND optionId LIKE CONCAT(#{ order.productId }, #{ order.optionName });
        </foreach>
    </update>
    
    <update id="updateDeliverNum" parameterType="java.util.List">
        <foreach collection="list" item="order" index="index">
            UPDATE deliver_info SET deliverNum=#{ order.changeValue }
            WHERE orderId=#{ order.orderId };
        </foreach>
    </update>
    
    <insert id="insertAddress" parameterType="hashMap">
        INSERT INTO client_address (addressId, clientId, addressTitle, addressName, addressNum, addressPostNum, address1, address2, addressMemo, addressBase, cookieId)
        VALUES(#{ addressInfo.addressId }, #{ addressInfo.clientId }, #{ addressInfo.addressTitle }, #{ addressInfo.addressName }, #{ addressInfo.addressNum  }, 
                #{ addressInfo.addressPostNum }, #{ addressInfo.address1 }, #{ addressInfo.address2 }, #{ addressInfo.addressMemo }, #{ addressInfo.addressBase }, #{ cookieId })
        ON DUPLICATE KEY UPDATE
            addressTitle=#{ addressInfo.addressTitle }, 
            addressName=#{ addressInfo.addressName }, 
            addressNum=#{ addressInfo.addressNum }, 
            addressPostNum=#{ addressInfo.addressPostNum }, 
            address1=#{ addressInfo.address1 }, 
            address2=#{ addressInfo.address2 }, 
            addressMemo=#{ addressInfo.addressMemo },
            addressBase=#{ addressInfo.addressBase },
            cookieId=#{ cookieId };
    </insert>
    
    <update id="updateBaseAddress" parameterType="hashMap">
        UPDATE client_address SET addressBase='N' WHERE clientId=#{ addressInfo.clientId } AND addressId != #{ addressInfo.addressId }
    </update>
    
    <insert id="insertOrder" parameterType="hashMap" useGeneratedKeys="true" keyProperty="orderId" keyColumn="orderId">                    
        INSERT INTO orders(orderId, clientId, addressId, optionIdList, orderEmail, orderPrice, usedPoint, couponId, cookieId, cookiePwd)
        VALUES(#{ orderId }, #{ orderInfo.clientId }, #{ addressInfo.addressId }, #{ orderInfo.optionIdList }, #{ orderInfo.orderEmail },
                #{ orderInfo.orderPrice }, #{ orderInfo.usedPoint }, #{ orderInfo.couponId }, #{ cookieId }, #{ orderInfo.cookiePwd });
    </insert>
    
    <delete id="deleteCart" parameterType="hashMap">
        DELETE FROM cart WHERE 
            <if test="cookieId == null">
                clientId=#{ orderInfo.clientId } 
            </if>
            <if test="cookieId != null">
                cookieId=#{ cookieId }
            </if>
        AND cartId IN 
            <foreach collection="cartIdList" item="cartId" open="(" separator="," close=")">
                #{ cartId }
            </foreach>
    </delete>
    
    <insert id="insertOrderInfo" parameterType="hashMap">
        INSERT INTO orders_info(orderId, optionId, orderProCnt, orderTotal, orderStatus)
        VALUES
            <foreach collection="orderInfoList" item="order" open="(" separator="), (" close=")">
                #{ orderId }, #{ order.optionId }, #{ order.orderProCnt }, #{ order.orderTotal }, '상품준비중'
            </foreach>
    </insert>
    
    <update id="updateClientPoint" parameterType="hashMap">
        UPDATE client
        SET clientPoint = clientPoint - #{ orderInfo.usedPoint }
        WHERE clientId = #{ orderInfo.clientId }
    </update>
    
    <update id="updateCouponList" parameterType="hashMap">
        UPDATE coupon_list 
        SET couponStatus="사용완료"
        WHERE clientId=#{ usedCouponInfo.clientId } AND couponId=#{ usedCouponInfo.couponId };
    </update>
    
    <insert id="insertPayment" parameterType="hashMap">
        INSERT INTO payment_info(paymentId, orderId, paymentMethod, paymentStatus)
        VALUES(#{ paymentId }, #{ orderId }, #{ paymentMethod }, #{ paymentStatus })
    </insert>
    
    <select id="getOrderInfo" parameterType="hashMap" resultType="hashMap">
        SELECT od.*, ad.*, pi.*, cl.*, cp.*
        FROM orders od
        LEFT JOIN client_address ad ON (ad.addressId = od.addressId )
        LEFT JOIN payment_info pi ON (od.orderId = pi.orderId)
        LEFT JOIN client cl ON (cl.clientId = od.clientId)
        LEFT JOIN coupon_info cp ON(od.couponId = cp.couponId)
        WHERE od.orderId = #{ orderId }
    </select>
    
    <select id="getOrderInfoList" parameterType="hashMap" resultType="hashMap">
        SELECT oi.*, pro.productName, pro.productId, pri.productPrice, CONCAT(pm.imageDir, pm.imageName) AS mainImage, op.*, re.reviewId, re.reviewStatus
        FROM orders_info oi
        LEFT JOIN product pro ON (SUBSTRING(oi.optionId, 1, 9)=pro.productId)
        LEFT JOIN product_price pri ON (pro.productId = pri.productId)
        LEFT JOIN product_image pm ON (pro.productId = pm.imageBy AND pm.imageStatus="대표")
        LEFT JOIN option_info op ON (oi.optionId = op.optionId)
        LEFT JOIN review re ON (oi.orderId = re.orderId AND oi.optionId = re.optionId)
        WHERE oi.orderId=#{ orderId }
    </select>
    
    <update id="updateProductStock" parameterType="hashMap">
        <foreach collection="orderInfoList" item="order" separator=";">
        UPDATE option_info
        SET stockCnt= stockCnt - #{ order.orderProCnt }
        WHERE optionId = #{ order.optionId }
        </foreach> 
    </update>
    
    <update id="updateOrderInfo" parameterType="hashMap">
        UPDATE orders_info
        SET orderStatus=#{ orderStatus }
        WHERE orderId=#{ order.orderId } AND optionId=#{ order.optionId }
    </update>
    
    <insert id="insertSwapRefund" parameterType="hashMap">
        INSERT INTO 
            <if test="requestWhat == 'refund'">refund(refundId, orderId, optionId, refundReason, refundWay, refundCost, refundCostMtd, refundStatus, refundEmail, refundRegDate, refundKeyword, bankId, refundBankNum)</if>
            <if test="requestWhat == 'swap'">swap(swapId, orderId, optionId, swapReason, swapWay, swapCost, swapCostMtd, swapStatus, swapEmail, swapRegDate, swapKeyword)</if>
        VALUES(#{ id }, #{ orderId }, #{ optionId }, #{ reason }, #{ deliverWay }, #{ cost }, #{ costMtd }, #{ status }, #{ email }, CURRENT_TIMESTAMP(), #{ keyword }
            <if test="requestWhat == 'refund'"> , #{ bankId }, #{ refundBankNum }</if>
        );
    </insert>
    
    <update id="updateSwapRefund" parameterType="hashMap">
        UPDATE ${ requestWhat } 
        SET
            <if test="requestWhat == 'refund'">refundStatus = #{ status } WHERE refundId = #{ id }</if>
            <if test="requestWhat == 'swap'">swapStatus = #{ status } WHERE swapId = #{ id }</if>
    </update>
    
<!-- 나의 주문 내역 -->
    <select id="getMyOrderList" parameterType="hashMap" resultType="hashMap">
        SELECT oi.orderId, oi.orderProCnt, oi.orderStatus, oi.orderTotal, op.optionColor, op.optionSize, oi.optionId, o.orderDate, p.productId, p.productName, CONCAT(pi.ImageDir, pi.ImageName) as image
        FROM orders_info oi 
        JOIN orders o ON oi.orderId = o.orderId
        JOIN option_info op ON oi.optionId = op.optionId
        JOIN product_image pi ON pi.ImageBy = op.productId
        JOIN product p ON p.productId = op.productId
        WHERE o.clientId = #{clientId} AND pi.ImageStatus = '대표'
        <if test="search.keyword != null and search.keyword != ''">
            <if test="search.searchType == 'orderDate'">
                AND od.orderDate like CONCAT('%', #{keyword}, '%')
            </if>
        </if>
        ORDER BY o.orderDate
        LIMIT #{search.startList}, #{search.listSize};
    </select>
    
    <select id="getMyOrderListCnt" parameterType="hashMap" resultType="int">
        SELECT count(*)
        FROM orders
        WHERE clientId = #{clientId}
        <if test="search.keyword != null and search.keyword != ''">
            <if test="search.searchType == 'orderDate'">
                AND od.orderDate like CONCAT('%', #{keyword}, '%')
            </if>
        </if>
    </select>
</mapper>
cs

 

 

 

PaymentController.java 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.w2.client.controller;
 
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
 
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import com.siot.IamportRestClient.IamportClient;
import com.siot.IamportRestClient.exception.IamportResponseException;
import com.siot.IamportRestClient.request.CancelData;
import com.siot.IamportRestClient.response.IamportResponse;
import com.siot.IamportRestClient.response.Payment;
import com.w2.order.service.OrderService;
 
import lombok.RequiredArgsConstructor;
 
@RestController
@RequiredArgsConstructor
@PropertySource("classpath:config/webserverdb.properties")
public class PaymentController {
 
    @Value("${imp.api.key}")
    private String apiKey;
    
    @Value("${imp.api.secretKey}")
    private String secretKey;
    
    private IamportClient iamportClient;
    
    @RequestMapping("sample.do")
    public String samplePayment() {
        return "test";
    }
    
    @ResponseBody
    @RequestMapping("verifyIamport.do")
    public IamportResponse<Payment> paymentByImpUid(@Param("imp_uid"String imp_uid) throws IamportResponseException, IOException {
        iamportClient = new IamportClient(apiKey, secretKey);
        IamportResponse<Payment> result = iamportClient.paymentByImpUid(imp_uid);
 
        return result;
    }
 
    /** 결제 취소 */
    @ResponseBody
    @PostMapping("refundPriceProc.do")
    public Map<String, Object> refundPriceProc(int refundPrice, int totalPrice, String paymentId) {
        Map<String, Object> result = new HashMap<String, Object>();
        
        IamportResponse<Payment> payment_response;
        iamportClient = new IamportClient(apiKey, secretKey);
        CancelData cancel_data;
        
        if(refundPrice == totalPrice) {    // merchantId 로 취소
            cancel_data = new CancelData(paymentId, true);
            result.put("cancleMethod""전액취소");
        } else {
            cancel_data = new CancelData(paymentId, true, BigDecimal.valueOf(refundPrice));
            result.put("cancleMethod""부분취소");
        }
        
        try {
            IamportResponse<Payment> cancledInfo = iamportClient.paymentByImpUid(paymentId);
            Payment paymentInfo = (Payment)cancledInfo.getResponse();
            
            if(paymentInfo.getAmount().intValue() > refundPrice) {
                payment_response = iamportClient.cancelPaymentByImpUid(cancel_data);
                
                if(payment_response != null) {
                    result.put("code"1);
                    result.put("resultCode""success");
                    result.put("msg""조회가 완료되었습니다.");
                } 
            } else {
                result.put("code"-1);
                result.put("resultCode""fail");
                result.put("msg""오류가 발생했습니다.");
            }
        } catch (IamportResponseException e) {
            System.err.println(e.getMessage());
 
            switch (e.getHttpStatusCode()) {
                case 401:
                    break;
                case 500:
                    break;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        return result;
    }
}
 
cs

 

 

 

>> 실행(주문 관리 페이지)

 

 

>>> 교환 정보 모음

 

 

 

>>> 교환 정보 확인

 

 

 

 

>>> 교환 진행중으로 변경

 

 

>>> 교환 완료로 변경

 

 

-- 교환 태그에서는 교환완료를 확인할 수 없게 작업하였는데 추후 팀원들과 의논후 확정지을 예정

 

 

>>> 환불 정보 모음

 

>>> 환불 정보 확인

 

 

 

>>> 환불 진행중으로 변경

 

 

>>> 환불 완료로 변경

 

>>> 환불금액 직접 지정 가능

 

 

 

-- 환불 태그에서는 환불완료를 확인할 수 없게 작업하였는데 추후 팀원들과 의논후 확정지을 예정

>>> portone 확인

---- 카카오페이로 결제를 진행했는데 포인트결제로 표시된다. 아마 테스트 결제로 처리되어 포인트 결제로 보여지는 것 같다.

 

 

-- 교환/환불에서 무통장으로 입금 요청시 관리자가 바로 확인할 수 있는 기능은 구현하지 못했는데, 사업자가 있는 경우 연동이 되는 건지 궁금해졌다. 차라리 다시 결제 기능을 작업하는 것이 좋지 않을까?

 

 

반응형