hyeonga_code

reProject_47_리뷰 작성, 리뷰 삭제, 별점, 리뷰 상세 보기 기능 구현 본문

Project_WEATHERWEAR

reProject_47_리뷰 작성, 리뷰 삭제, 별점, 리뷰 상세 보기 기능 구현

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

 

2024.02.19

-- 주문 상세페이지에서 주문상태가 배송중이거나 배송완료인 동시에 리뷰가 존재하지 않는 경우 리뷰 작성 버튼이 표시

-- 리뷰 등록시 주문 상태가 배송중인 경우 "배송완료"로 업데이트

-- 배송중이거나 배송완료인 동시에 리뷰가 존재하는 경우 리뷰 보기 버튼이 표시

-- 리뷰가 존재하지만 리뷰 상태가 삭제인 경우 어떠한 버튼도 표시되지 않음

---- 교환/환불/리뷰작성이 불가능하도록 reviewStatus 제약조건에 "삭제"추가

---- 추후 1:1문의하기 추가할 지 고민중이다.

 

++ 별점(구글링 참고)

<style>
@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
       .rate { display: inline-block;border: 0;margin-right: 15px;}
.rate > input {display: none;}
.rate > label {float: right;color: #ddd}
.rate > label:before {display: inline-block;font-size: 3rem;padding: .3rem .2rem;margin: 0;cursor: pointer;font-family: FontAwesome;content: "\f005 ";}
.rate .half:before {content: "\f089 "; position: absolute;padding-right: 0;}
.rate input:checked ~ label, 
.rate label:hover,.rate label:hover ~ label { color: #f73c32 !important;  } 
.rate input:checked + .rate label:hover,
.rate input input:checked ~ label:hover,
.rate input:checked ~ .rate label:hover ~ label,  
.rate label:hover ~ input:checked ~ label { color: #f73c32 !important;  } 
</style>

<body>
	<fieldset class="rate">
        <input type="radio" id="reviewStar10" name="reviewStar" value="10"><label for="reviewStar10" title="5점"></label>
        <input type="radio" id="reviewStar9" name="reviewStar" value="9"><label class="half" for="reviewStar9" title="4.5점"></label>
        <input type="radio" id="reviewStar8" name="reviewStar" value="8"><label for="reviewStar8" title="4점"></label>
        <input type="radio" id="reviewStar7" name="reviewStar" value="7"><label class="half" for="reviewStar7" title="3.5점"></label>
        <input type="radio" id="reviewStar6" name="reviewStar" value="6"><label for="reviewStar6" title="3점"></label>
        <input type="radio" id="reviewStar5" name="reviewStar" value="5"><label class="half" for="reviewStar5" title="2.5점"></label>
        <input type="radio" id="reviewStar4" name="reviewStar" value="4"><label for="reviewStar4" title="2점"></label>
        <input type="radio" id="reviewStar3" name="reviewStar" value="3"><label class="half" for="reviewStar3" title="1.5점"></label>
        <input type="radio" id="reviewStar2" name="reviewStar" value="2"><label for="reviewStar2" title="1점"></label>
        <input type="radio" id="reviewStar1" name="reviewStar" value="1"><label class="half" for="reviewStar1" title="0.5점"></label>
	</fieldset>
</body>

 

 

요약

// Controller
    @Autowired
    private ReviewService reviewService;
 
    /** 리뷰 등록 */
    @ResponseBody
    @PostMapping("insertReview.do")
    public ResponseDTO<String> insertReview(ReviewVO review, HttpSession session, 
                    HttpServletRequest request, HttpServletResponse response) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        String id = "";
 
        ClientVO client = (ClientVO)session.getAttribute("userInfo");
 
        review.setClientId(client.getClientId());
        review.setReviewId("RE" + RandomString.createFileName() 
                         + RandomString.setRandomString(5"number"));
 
        try {
            int result = reviewService.insertReview(review);
            System.err.println("누가 먼저 실행되냐고");
            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);
    }
    
    /** 리뷰 조회 */
    @ResponseBody
    @PostMapping("getReviewInfo.do")
    public ResponseDTO<HashMap<String, Object>> getReviewInfo(String reviewId, 
                                                  HttpSession session) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
 
        HashMap<String, Object> result = new HashMap<String, Object>();
        ReviewVO review = reviewService.getReviewInfo(reviewId);
        if(review != null) {
            code = 1;
            resultCode = "success";
            msg = "조회가 완료되었습니다.";
            
            result.put("review", review);
            if(review.getReviewStatus().equals("포토")) {
                result.put("reviewImage", reviewService.getReviewImage(review));
            }
            System.err.println("result : " + result);
        } else {
            code = -1;
            resultCode = "fail";
            msg = "오류가 발생했습니다.";
        }
        return new ResponseDTO<HashMap<String, Object>>(statusCode, code, 
                                                  resultCode, msg, result);
    }
    
    /** 리뷰 삭제 */
    @ResponseBody
    @PostMapping("deleteReview.do")
    public ResponseDTO<String> deleteReview(String reviewId, HttpSession session) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
 
        ClientVO client = (ClientVO)session.getAttribute("userInfo");
        ReviewVO review = reviewService.getReviewInfo(reviewId);
        if(review.getClientId().equals(client.getClientId())) {
            int result = reviewService.deleteReview(reviewId);
            if(result > 0) {
                result = imageService.deleteReviewImage(review.getOrderId() + "_" 
                                                  + review.getOptionId());
                code = 1;
                resultCode = "success";
                msg = "리뷰가 삭제되었습니다.";
            } else {
                code = -1;
                resultCode = "fail";
                msg = "오류가 발생했습니다.";
            }
        } else {
            code = -1;
            resultCode = "fail";
            msg = "오류가 발생했습니다.";
        }
        return new ResponseDTO<String>(statusCode, code, resultCode, msg, reviewId);
    }
 
 
// Service
    @Autowired
    private ReviewDAO reviewDao;
    
    @Override
    public int insertReview(ReviewVO vo) {
        return reviewDao.insertReview(vo);
    }
 
    @Override
    public ReviewVO getReviewInfo(String reviewId) {
        return reviewDao.getReviewInfo(reviewId);
    }
 
    @Override
    public List<String> getReviewImage(ReviewVO review) {
        return reviewDao.getReviewImage(review);
    }
 
    @Override
    public int deleteReview(String reviewId) {
        return reviewDao.deleteReview(reviewId);
    }
 
 
// DAO
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    
    public int insertReview(ReviewVO vo) {
        return sqlSessionTemplate.insert("ReviewDAO.insertReview", vo);
    }
 
    public ReviewVO getReviewInfo(String reviewId) {
        return sqlSessionTemplate.selectOne("ReviewDAO.getReviewInfo", reviewId);
    }
 
    public List<String> getReviewImage(ReviewVO review) {
        return sqlSessionTemplate.selectList("ReviewDAO.getReviewImage", review);
    }
 
    public int deleteReview(String reviewId) {
        return sqlSessionTemplate.delete("ReviewDAO.deleteReview", reviewId);
    }
 
 
// mapping.xml
    <insert id="insertReview" parameterType="review">
        INSERT INTO review(reviewId, clientId, orderId, optionId, reviewContent, 
                         reviewStar, reviewDate, reviewStatus, productId)
        VALUES(#{reviewId}, #{ clientId }, #{ orderId }, #{ optionId }, #{ reviewContent },
                    #{ reviewStar }, CURRENT_TIMESTAMP, #{ reviewStatus }, #{ productId })
    </insert>
 
    <select id="getReviewInfo" parameterType="String" resultType="review">
        SELECT * 
        FROM review
        WHERE reviewId = #{ reviewId }
    </select>
    
    <select id="getReviewImage" parameterType="review" resultType="String">
        SELECT CONCAT(imageDir, imageName)
        FROM client_image
        WHERE imageBy = CONCAT(#{ orderId }, '_', #{ optionId })
    </select>
    
    <update id="deleteReview" parameterType="String">
        UPDATE review
        SET reviewStatus = '삭제'
        WHERE reviewId=#{ reviewId }
    </update>
 

 

 

 

orderInfo.jsp 

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
<%@ 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="100px"/><!-- 회원번호 -->
                                                <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 }">${item.orderStatus}</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>${fn:substring(item.addressNum,0,3)}-${fn:substring(item.addressNum,3,7)}-${fn:substring(item.addressNum,7,11)}</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 - ci.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 }">
                                                        </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>

 

review.css 작성

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
@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
.rate { display: inline-block;border: 0;margin-right: 15px;}
.rate > input {display: none;}
.rate > label {float: right;color: #ddd}
.rate > label:before {display: inline-block;font-size: 3rem;padding: .3rem .2rem;margin: 0;cursor: pointer;font-family: FontAwesome;content: "\f005 ";}
.rate .half:before {content: "\f089 "; position: absolute;padding-right: 0;}
.rate input:checked ~ label, 
.rate label:hover,.rate label:hover ~ label { color: #f73c32 !important;  } 
.rate input:checked + .rate label:hover,
.rate input input:checked ~ label:hover,
.rate input:checked ~ .rate label:hover ~ label,  
.rate label:hover ~ input:checked ~ label { color: #f73c32 !important;  } 
 
 
.rated { display: inline-block;border: 0;margin-right: 15px;}
.rated > input {display: none;}
.rated > label {float: right;color: #ddd}
.rated > label:before {display: inline-block;font-size: 3rem;padding: .3rem .2rem;margin: 0;cursor: pointer;font-family: FontAwesome;content: "\f005 ";}
.rated .half:before {content: "\f089 "; position: absolute;padding-right: 0;}
.rated input:checked ~ label { color: #f73c32 !important;  } 
 
#image-container {
  position: relative;
}
 
#image-container img {
  width: 100%;
  max-width: 500px;
}
 
#image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
}
 
#image-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  padding: 20px;
  border: 1px solid black;
  display: none;
}

 

 

 

 

orderInfo.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
let orderList = [];
let orderStatus;
 
let id;                // 글 번호
let orderId;         // 주문번호
let optionId;         // 옵션번호
let reason;            // 사유
let image;             // 이미지
let email;             // 이메일
let regDate;         // 요청일자
let deliverWay;        // 수거 방식(직접발송/택배수거)
let cost;             // 택배비용
let costMtd;         // 택배에동봉, 무통장입금
let status;            // 상태(요청,진행,완료)
let bankId;            // 환불 은행
let refundBankNum;     // 환불 계좌
let requestWhat;     // 교환/환불
 
let reviewContent;
let reviewStar;
let reviewDate;
let reviewStatus = '일반';
let productId;
 
// 배송 방법 설정(배송비 설정)
    function setDeliveryMtd(id){
        if(document.querySelector("input[name='radioCheck']:checked") == null){    return;    }
        switch(id){
        case "직접발송":
            if(document.querySelector("#단순변심:checked") || document.querySelector("#사이즈변경:checked") ){    cost = 3000; 
            } else {    cost = 0;}
            break;
        case "택배수거":
            if(document.querySelector("#단순변심:checked") || document.querySelector("#사이즈변경:checked") ){    cost = 6000; 
            } else {    cost = 0;}
            break;
        }
        setCost(cost);
    }
 
// 사유 선택(배송비 설정)
    function setReason(id){
        cost = 0;
        switch(id){
        case "오배송": case "상품하자": cost = 0; break;
        case "단순변심": case "사이즈변경": 
            if(document.querySelector("#직접발송:checked")){    cost = 3000;
            }else {        cost = 6000;     }
            break;
        }    
        setCost(cost);
    }
 
// 배송비 적용
function setCost(cost){
    let costContent = "<div class='modalDiv'><label for='content'><b>배송비 지불 방법</b></label><div class='payDiv'></div>";
    costContent += "<div class='custom-control custom-radio'><div class='costMtd'></div>";
    costContent += "<div><input class='custom-control-input custom-control-input-danger' type='radio' id='택배에동봉' name='payMtd'>&nbsp;&nbsp;&nbsp;";
    costContent += "<label for='택배에동봉' class='custom-control-label'>택배에동봉</label></div>";
    costContent += "<div><input class='custom-control-input custom-control-input-danger' type='radio' id='무통장입금' name='payMtd'>&nbsp;&nbsp;&nbsp;";
    costContent += "<label for='무통장입금' class='custom-control-label'>무통장입금</label></div>";
    if(requestWhat == "refund"){
        costContent += "<div><input class='custom-control-input custom-control-input-danger' type='radio' id='결제금액차감' name='payMtd'>&nbsp;&nbsp;&nbsp;";
        costContent += "<label for='결제금액차감' class='custom-control-label'>결제 금액에서 제외하고 차감</label></div></div></div><hr>";
    }
    if (cost >0){
        document.querySelector(".payMtd").innerHTML = costContent;
    } else {
        document.querySelector(".payMtd").innerHTML = "";
    }
    document.querySelector(".costMtd").innerHTML = "<b>택배비 : " + cost + "원</b><br>";
}
 
// 주문 취소
    function cancleOrder(target){
        orderId = target.split("_")[0];
        optionId = target.split("_")[1];
        orderStatus = "취소요청";
        
        Swal.fire({
            title: "주문을 취소하시겠습니까?",
            text: "주문 취소를 철회하고 싶은 경우 문의 바랍니다.",
            icon: "question",
              showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: "취소하기",
              cancelButtonText: "닫기",
            reverseButtons: true, // 버튼 순서 거꾸로
        }).then((result) => {
            if(result.isConfirmed){    // 매개변수 list 안됨
                playAjax();
            }
        });
    }
 
// 교환 요청
    function swapOrder(target){    
        orderId = target.split("_")[0];
        optionId = target.split("_")[1];
        status = "교환요청";
        orderStatus = "교환요청";
        requestWhat = "swap";
        
        let swapContent = "<div class='modal-dialog'><div class='modal-content'><div class='modal-header'><h4 class='modal-title'>교환 요청</h4>";
        swapContent += "<button type='button' class='close form-control' style='width:10%; background-color:#dee2e6;' data-dismiss='modal' aria-label='Close' onclick='closeModal()'><span aria-hidden='true'>×</span></button></div>";
        swapContent += "<div class='modal-body'>";
        swapContent += "<div class='modalDiv'><label for='content'><b>교환 요청 사유</b></label><div class='codeDiv'></div>";
        swapContent += "<div class='custom-control custom-radio'>";
        swapContent += "<input class='custom-control-input custom-control-input-danger' type='radio' id='오배송' name='radioCheck' onclick='setReason(this.id)'>";
        swapContent += "<label for='오배송' class='custom-control-label'>오배송</label>";
        swapContent += "<input class='custom-control-input custom-control-input-danger' type='radio' id='상품하자' name='radioCheck' onclick='setReason(this.id)'>";
        swapContent += "<label for='상품하자' class='custom-control-label'>상품하자</label>";
        swapContent += "<input class='custom-control-input custom-control-input-danger' type='radio' id='단순변심' name='radioCheck' onclick='setReason(this.id)'>";
        swapContent += "<label for='단순변심' class='custom-control-label'>단순변심</label>";
        swapContent += "<input class='custom-control-input custom-control-input-danger' type='radio' id='사이즈변경' name='radioCheck' onclick='setReason(this.id)'>";
        swapContent += "<label for='사이즈변경' class='custom-control-label'>사이즈변경</label></div>";
        swapContent += "<textarea class='form-control' name='content' id='content' placeholder='입력해주세요'></textarea></div><hr>";
        swapContent += "<div class='modalDiv' id='dropzone' style='width:100%'><div id='image' class='dz-message needsclick baseImgDiv'>";
        swapContent += "<span class='text' style='display:flex; align-items:center; flex-direction:column;' onclick='playDropzone()'>";
        // key값 // imageStatus 변경하기(교환/리뷰/환불/문의)
        swapContent += "<input type='hidden' id='key' value='client'><input type='hidden' id='imageStatus' value='교환'>";
        swapContent += "<img src='resources/util/image/dropzone_camera.png' alt='Camera' />";
        swapContent += "<code>이미지를 등록하시려면 클릭하세요</code><br></span>";
        swapContent += "</div></div><hr>";
        swapContent += "<div class='modalDiv'><label for='content'><b>교환 방법</b></label><div class='wayCodeDiv'></div>";
        swapContent += "<div class='custom-control custom-radio'><div class='costMtd'></div>";
        swapContent += "<div><input class='custom-control-input custom-control-input-danger' type='radio' id='직접발송' name='deliveryMtd' onclick='setDeliveryMtd(this.id)'>&nbsp;&nbsp;&nbsp;";
        swapContent += "<label for='직접발송' class='custom-control-label'>직접발송</label></div>";
        swapContent += "<div><input class='custom-control-input custom-control-input-danger' type='radio' id='택배수거' name='deliveryMtd' onclick='setDeliveryMtd(this.id)'>&nbsp;&nbsp;&nbsp;";
        swapContent += "<label for='택배수거' class='custom-control-label'>택배수거</label></div></div><div class='payMtd'></div></div>";
        swapContent += "<div class='modalDiv'><b>이메일</b><div class='emailDiv'></div>";
        swapContent += "<div class='custom-control custom-radio'>";
        swapContent += "<label for='email'></label><input type='email' class='form-control form-control-border border-width-2' name='email' id='email' placeholder='weatherwear@email.com'style='width:80%;'></div><br>";
        swapContent += "<div class='modal-footer justify-content-between'><button type='button' class='form-control' data-dismiss='modal' onclick='closeModal()' style='width:100px;'>취소하기</button>";
        swapContent += "<button type='button' class='btn btn-primary insertBtn' onclick='submit()' style='width:100px;'>등록하기</button></div></div></div>";
        
        openModel(swapContent);
    }
 
// 환불 요청
    function refundOrder(target){    
        orderId = target.split("_")[0];
        optionId = target.split("_")[1];
        status = "환불요청";
        orderStatus = "환불요청";
        requestWhat = "refund";
        
        let refundContent = "<div class='modal-dialog'><div class='modal-content'><div class='modal-header'><h4 class='modal-title'>환불 요청</h4>";
        refundContent += "<button type='button' class='close form-control' style='width:10%; background-color:#dee2e6;' data-dismiss='modal' aria-label='Close' onclick='closeModal()'><span aria-hidden='true'>×</span></button></div>";
        refundContent += "<div class='modal-body'>";
        refundContent += "<div class='modalDiv'><label for='content'><b>환불 요청 사유</b></label><div class='codeDiv'></div>";
        refundContent += "<div class='custom-control custom-radio'>";
        refundContent += "<input class='custom-control-input custom-control-input-danger' type='radio' id='오배송' name='radioCheck' onclick='setReason(this.id)'>";
        refundContent += "<label for='오배송' class='custom-control-label'>오배송</label>";
        refundContent += "<input class='custom-control-input custom-control-input-danger' type='radio' id='상품하자' name='radioCheck' onclick='setReason(this.id)'>";
        refundContent += "<label for='상품하자' class='custom-control-label'>상품하자</label>";
        refundContent += "<input class='custom-control-input custom-control-input-danger' type='radio' id='단순변심' name='radioCheck' onclick='setReason(this.id)'>";
        refundContent += "<label for='단순변심' class='custom-control-label'>단순변심</label></div>";
        refundContent += "<textarea class='form-control' name='content' id='content' placeholder='입력해주세요'></textarea></div><hr>";
        refundContent += "<div class='modalDiv' id='dropzone' style='width:100%'><div id='image' class='dz-message needsclick baseImgDiv'>";
        refundContent += "<span class='text' style='display:flex; align-items:center; flex-direction:column;' onclick='playDropzone()'>";
        // key값 // imageStatus 변경하기(환불/리뷰/환불/문의)
        refundContent += "<input type='hidden' id='key' value='client'><input type='hidden' id='imageStatus' value='환불'>";
        refundContent += "<img src='resources/util/image/dropzone_camera.png' alt='Camera' />";
        refundContent += "<code>이미지를 등록하시려면 클릭하세요</code><br></span>";
        refundContent += "</div></div><hr>";
        refundContent += "<div class='modalDiv'><label for='content'><b>환불 방법</b></label><div class='wayCodeDiv'></div>";
        refundContent += "<div class='custom-control custom-radio'><div class='costMtd'></div>";
        refundContent += "<div><input class='custom-control-input custom-control-input-danger' type='radio' id='직접발송' name='deliveryMtd' onclick='setDeliveryMtd(this.id)'>&nbsp;&nbsp;&nbsp;";
        refundContent += "<label for='직접발송' class='custom-control-label'>직접발송</label></div>";
        refundContent += "<div><input class='custom-control-input custom-control-input-danger' type='radio' id='택배수거' name='deliveryMtd' onclick='setDeliveryMtd(this.id)'>&nbsp;&nbsp;&nbsp;";
        refundContent += "<label for='택배수거' class='custom-control-label'>택배수거</label></div></div><div class='payMtd'></div></div>";
        refundContent += "<div class='modalDiv'><b>이메일</b><div class='emailDiv'></div>";
        refundContent += "<div class='custom-control custom-radio'>";
        refundContent += "<label for='email'></label><input type='email' class='form-control form-control-border border-width-2' name='email' id='email' placeholder='weatherwear@email.com'style='width:80%;'></div><br>";    
        
        // 무통장 입금 시 
        if($("#paymentMethodInput").val() == "무통장입금"){
            refundContent += "<div class='modalDiv'><b>환불 계좌 입력</b><div class='bankDiv'></div>";
            refundContent += "<div class='custom-control custom-radio'>";
            refundContent += "<select class='select' id='bankId'><option value='001'>한국은행</option>";
            refundContent += "<option value='003'>기업은행</option><option value='004'>국민은행</option>";
            refundContent += "<option value='007'>수협은행</option><option value='011'>농협은행</option>";
            refundContent += "<option value='020'>우리은행</option><option value='023'>SC제일은행</option>";
            refundContent += "<option value='027'>씨티은행</option><option value='032'>부산은행</option>";
            refundContent += "<option value='035'>제주은행</option><option value='037'>전북은행</option>";
            refundContent += "<option value='039'>경남은행</option><option value='045'>새마을금고</option>";
            refundContent += "<option value='048'>신협은행</option><option value='050'>상호저축은행</option>";
            refundContent += "<option value='071'>우체국은행</option><option value='081'>하나은행</option>";
            refundContent += "<option value='088'>신한은행</option><option value='089'>케이뱅크</option>";
            refundContent += "<option value='090'>카카오뱅크</option><option value='092'>토스뱅크</option></select>";
            refundContent += "<label for='refundBankNum'></label><input type='text' class='form-control form-control-border border-width-2' name='refundBankNum' id='refundBankNum' style='width:80%;' placeholder='계좌번호'></div><br>";
        }
        refundContent += "<div class='modal-footer justify-content-between'><button type='button' class='form-control' data-dismiss='modal' onclick='closeModal()' style='width:100px;'>취소하기</button>";
        refundContent += "<button type='button' class='btn btn-primary insertBtn' onclick='submit()' style='width:100px;'>등록하기</button></div></div></div>";
        
        openModel(refundContent);
    }
    
// 교환/환불 등록
function submit(){
    // 사유 선택 확인
    let radioCheck = document.querySelector("input[name='radioCheck']:checked");
    if(radioCheck == null){
        document.querySelector(".codeDiv").innerHTML = "<code>사유를 체크해주세요</code><br>";
        return;
    } else {
        document.querySelector(".codeDiv").innerHTML = "";
    }
    
    // 내용 확인
    reason = $("#content").val();
    if(reason == null || reason == '' || reason.length<10){
        document.querySelector(".codeDiv").innerHTML = "<code>사유를 10자 이상 입력해주세요</code><br>";
        $("#content").focus();
        return;
    } else {
        document.querySelector(".codeDiv").innerHTML = "";
    }
    
    // 수거방법 확인
    deliverWay = document.querySelector("input[name='deliveryMtd']:checked");
    if(deliverWay == null){
        document.querySelector(".wayCodeDiv").innerHTML = "<code>수거 방법을 체크해주세요</code><br>";
        return;
    } else {
        document.querySelector(".wayCodeDiv").innerHTML = "";
    }
    
    // 이메일 확인
    email = $("#email").val();
    if(email == null || email == ''){
        document.querySelector(".emailDiv").innerHTML = "<code>이메일 주소를 입력해주세요</code><br>";
        $("#email").focus();
        return;
    } else {
        document.querySelector(".emailDiv").innerHTML = "";
    }
    
    // 배송비 지불 방법 확인
    let costMethod = document.querySelector("input[name='payMtd']:checked");
    if(costMethod == null || costMethod == ''){
        if(cost>0){
            document.querySelector(".payDiv").innerHTML = "<code>배송비 지불 방법을 선택해주세요</code><br>";
            return;
        }
        costMtd = "무통장입금";
    } else {
        costMtd = costMethod.id;
        document.querySelector(".payDiv").innerHTML = "";
    }
    
    // 계좌번호 확인
    if($("#paymentMethodInput").val() == "무통장입금"){
        bankId = $("#bankId").val();
        refundBankNum = $("#refundBankNum").val();
        if(refundBankNum == null || refundBankNum == ""){
            document.querySelector(".bankDiv").innerHTML = "<code>환불받을 계좌번호를 입력해주세요</code><br>";
            $("#refundBankNum").focus();
            return;
        } else {
            document.querySelector(".bankDiv").innerHTML = "";
        }
    }
    
    $.ajax({
        url: "insertSwapRefund.do",
        type: "POST",
        async: true,
        dataType: "json",
        data: {
            requestWhat: requestWhat,
            orderId: orderId,
            optionId: optionId,
            reason: reason,
            email: email,
            deliverWay: deliverWay.id,
            cost: parseInt(cost),
            costMtd: costMtd,
            status: status,
            bankId: bankId,
            refundBankNum: refundBankNum
        },
        success: function(res){
            if(res.code == 1){
                playAjax();
            } else {
                playToast("오류가 발생했습니다. 다시 시도해주세요.", "error");
            }
        },
        error : function(error){
            playToast("오류가 발생했습니다.", 'error');
        }
    });
}
    
// 리뷰 작성
    function reviewWrite(product_id, order_id, option_id, productName, mainImage, proCnt, optionColor, optionSize){
        productId = product_id;
        orderId = order_id;
        optionId = option_id;
        let statusName = "orderStatus_" + optionId;
        orderStatus = $("input[name='" + statusName + "'").val();
 
        let reviewContent = "<div class='modal-dialog'><div class='modal-content'><div class='modal-header'><h4 class='modal-title'>리뷰 작성</h4>";
        reviewContent += "<button type='button' class='close form-control' style='width:10%; background-color:#dee2e6;' data-dismiss='modal' aria-label='Close' onclick='closeModal()'><span aria-hidden='true'>×</span></button></div>";
        reviewContent += "<div class='modal-body'>";
        reviewContent += "<div class='modalDiv'><div class='row'><div class='col-md-4'>";
        reviewContent += "<img class='product_image' src='" + mainImage +"' style='height:150px; width:150px;'></div>";
        reviewContent += "<div class='col-md-1'></div><div class='col-md-7'><br><b>" + productName +"</b><br><span>";
        reviewContent += optionColor + " / " + optionSize + " : " + proCnt + "</span></div><br><br></div><hr>";
        reviewContent += "</div><div class='modalDiv'><b>별점</b><div class='starDiv'></div>";
        reviewContent += "<div class='custom-control custom-radio'>";
        reviewContent += "<fieldset class='rate'>";
        reviewContent += "<input type='radio' id='reviewStar10' name='reviewStar' value='10'><label for='reviewStar10' title='5점'></label>";
        reviewContent += "<input type='radio' id='reviewStar9' name='reviewStar' value='9'><label class='half' for='reviewStar9' title='4.5점'></label>";
        reviewContent += "<input type='radio' id='reviewStar8' name='reviewStar' value='8'><label for='reviewStar8' title='4점'></label>";
        reviewContent += "<input type='radio' id='reviewStar7' name='reviewStar' value='7'><label class='half' for='reviewStar7' title='3.5점'></label>";
        reviewContent += "<input type='radio' id='reviewStar6' name='reviewStar' value='6'><label for='reviewStar6' title='3점'></label>";
        reviewContent += "<input type='radio' id='reviewStar5' name='reviewStar' value='5'><label class='half' for='reviewStar5' title='2.5점'></label>";
        reviewContent += "<input type='radio' id='reviewStar4' name='reviewStar' value='4'><label for='reviewStar4' title='2점'></label>";
        reviewContent += "<input type='radio' id='reviewStar3' name='reviewStar' value='3'><label class='half' for='reviewStar3' title='1.5점'></label>";
        reviewContent += "<input type='radio' id='reviewStar2' name='reviewStar' value='2'><label for='reviewStar2' title='1점'></label>";
        reviewContent += "<input type='radio' id='reviewStar1' name='reviewStar' value='1'><label class='half' for='reviewStar1' title='0.5점'></label></fieldset>";
        reviewContent += "</div><hr><b>리뷰 내용</b><div class='contentDiv'></div><br>";
        reviewContent += "<textarea class='form-control' name='content' id='content' placeholder='최소 10자 이상 입력해주세요' style='height:150px;'></textarea></div><hr>";
        reviewContent += "<b>사진 첨부</b><div class='modalDiv' id='dropzone' style='width:100%'>";
        reviewContent += "<div id='image' class='dz-message needsclick baseImgDiv'>";
        reviewContent += "<span class='text' style='display:flex; align-items:center; flex-direction:column;' onclick='playDropzone()'>";
        reviewContent += "<input type='hidden' id='key' value='client'><input type='hidden' id='imageStatus' value='리뷰'>";
        reviewContent += "<img src='resources/util/image/dropzone_camera.png' alt='Camera' />";
        reviewContent += "<code>이미지를 등록하시려면 클릭하세요</code><br></span>";
        reviewContent += "</div></div><hr><br>";
        reviewContent += "<div class='modal-footer justify-content-between'><button type='button' class='form-control' data-dismiss='modal' onclick='closeModal()' style='width:100px;'>취소하기</button>";
        reviewContent += "<button type='button' class='btn btn-primary insertBtn' onclick='registerReview()' style='width:100px;'>등록하기</button></div></div></div>";
        
        openModel(reviewContent);
    }
 
// 리뷰 등록
function registerReview(){
    
    // 별점 선택 확인
    let reviewStarInput = document.querySelector("input[name='reviewStar']:checked");
    let reviewStar;
    if(reviewStarInput == null){
        document.querySelector(".starDiv").innerHTML = "<code>별점을 선택해주세요</code><br>";
        return;
    } else {
        reviewStar = parseInt(reviewStarInput.value)/2;
        document.querySelector(".starDiv").innerHTML = "";
    }
    
    // 내용 확인
    let content = $("#content").val();
    if(content == null || content == '' || content.length<10){
        document.querySelector(".contentDiv").innerHTML = "<code>사유를 10자 이상 입력해주세요</code><br>";
        $("#content").focus();
        return;
    } else {
        document.querySelector(".contentDiv").innerHTML = "";
    }
    
    $.ajax({
        url: "insertReview.do",
        type: "POST",
        async: true,
        dataType: "json",
        data: {
            orderId : orderId,
            optionId : optionId,
            reviewContent : content,
            reviewStar: reviewStar,
            reviewStatus: reviewStatus,
            productId: productId,
        },
        success: function(res){
            if(res.code == 1){
                if(orderStatus == "배송중"){
                    orderStatus = "배송완료";
                    playAjax();
                } else {
                    playToast("리뷰가 등록되었습니다", "success");
                    setTimeout(function(){
                        window.location.reload();
                    }, 1500);
                }
            } else {
                playToast("오류가 발생했습니다. 다시 시도해주세요.", "error");
            }
        },
        error : function(error){
            playToast("오류가 발생했습니다.", 'error');
        }
    });
}
 
// 리뷰 보기
function reviewView(reviewId, productName, mainImage, proCnt, optionColor, optionSize){
    $.ajax({
        url: "getReviewInfo.do",
        type: "POST",
        async: true,
        dataType: "json",
        data: { reviewId: reviewId },
        success: function(res){
            let star = parseInt(parseFloat(res.data.review.reviewStar) * 2);
            let reviewResult = "<div class='modal-dialog'><div class='modal-content'><div class='modal-header'><h4 class='modal-title'>리뷰 보기</h4>";
            reviewResult += "<button type='button' class='close form-control' style='width:10%; background-color:#dee2e6;' data-dismiss='modal' aria-label='Close' onclick='closeModal()'><span aria-hidden='true'>×</span></button></div>";
            reviewResult += "<div class='modal-body'>";
            reviewResult += "<div class='modalDiv'><div class='row'><div class='col-md-4'>";
            reviewResult += "<img class='product_image' src='" + mainImage +"' style='height:150px; width:150px;'></div>";
            reviewResult += "<div class='col-md-1'></div><div class='col-md-7'><br><b>" + productName +"</b><br><span>";
            reviewResult += optionColor + " / " + optionSize + " : " + proCnt + "</span></div><br><br></div><hr>";
            reviewResult += "</div><div class='modalDiv'><b>별점</b><div class='starDiv'></div>";
            reviewResult += "<div class='custom-control custom-radio'>";
            reviewResult += "<fieldset class='rated'>";
            reviewResult += "<input type='radio' id='reviewStar10' name='reviewStar' value='10' disabled";
            if(star == 10){
                reviewResult += " checked";
            }
            reviewResult += "><label for='reviewStar10' title='5점'></label>";
            reviewResult += "<input type='radio' id='reviewStar9' name='reviewStar' value='9' disabled";
            if(star == 9){
                reviewResult += " checked";
            }
            reviewResult += "><label class='half' for='reviewStar9' title='4.5점'></label>";
            reviewResult += "<input type='radio' id='reviewStar8' name='reviewStar' value='8' disabled";
            if(star == 8){
                reviewResult += " checked";
            }
            reviewResult += "><label for='reviewStar8' title='4점'></label>";
            reviewResult += "<input type='radio' id='reviewStar7' name='reviewStar' value='7' disabled";
            if(star == 7){
                reviewResult += " checked";
            }
            reviewResult += "><label class='half' for='reviewStar7' title='3.5점'></label>";
            reviewResult += "<input type='radio' id='reviewStar6' name='reviewStar' value='6' disabled";
            if(star == 6){
                reviewResult += " checked";
            }
            reviewResult += "><label for='reviewStar6' title='3점'></label>";
            reviewResult += "<input type='radio' id='reviewStar5' name='reviewStar' value='5' disabled";
            if(star == 5){
                reviewResult += " checked";
            }
            reviewResult += "><label class='half' for='reviewStar5' title='2.5점'></label>";
            reviewResult += "<input type='radio' id='reviewStar4' name='reviewStar' value='4' disabled";
            if(star == 4){
                reviewResult += " checked";
            }
            reviewResult += "><label for='reviewStar4' title='2점'></label>";
            reviewResult += "<input type='radio' id='reviewStar3' name='reviewStar' value='3' disabled";
            if(star == 3){
                reviewResult += " checked";
            }
            reviewResult += "><label class='half' for='reviewStar3' title='1.5점'></label>";
            reviewResult += "<input type='radio' id='reviewStar2' name='reviewStar' value='2' disabled";
            if(star == 2){
                reviewResult += " checked";
            }
            reviewResult += "><label for='reviewStar2' title='1점'></label>";
            reviewResult += "<input type='radio' id='reviewStar1' name='reviewStar' value='1' disabled";
            if(star == 1){
                reviewResult += " checked";
            }
            reviewResult += "><label class='half' for='reviewStar1' title='0.5점'></label></fieldset>";
            reviewResult += "</div><hr><b>리뷰 내용</b><div class='contentDiv'></div><br><span>";
            reviewResult += res.data.review.reviewContent;
            reviewResult += "</span></div><hr>";
            if(res.data.review.reviewStatus == "포토"){
                let imageList = "" + res.data.reviewImage;
                let images = imageList.split(',');
                reviewResult += "<b>첨부 사진</b><div class='modalDiv' style='width:100%'>";
                for(let i=0; i<images.length; i++){
                    reviewResult += "<img class='product_image' src='" + images[i] +"' style='height:auto; width:100%;' id='" + images[i] + "' onclick='openImage()'><br><br>";
                }
            }
            reviewResult += "</div><br>";
            reviewResult += "<div class='modal-footer justify-content-between'><button type='button' id='" + reviewId + "' class='form-control' data-dismiss='modal' onclick='deleteReview()' style='width:100px;'>삭제하기</button></div></div></div>";
            
            openModel(reviewResult);
        },
        error : function(error){
            playToast("오류가 발생했습니다.", 'error');
        }
    });
}
 
// 이미지 확대
function openImage(){
    let imageDir = event.target.id;
    Swal.fire({
        title: "<br>",
        html: "<div class='row' style='width:100%; height:100%;'><img src='" + imageDir + "' style='100%; height:auto;'></div>",
        text: "확인",
        width: "1000px",
        confirmButtonColor: "dimgrey",
        confirmButtonText: "닫기"
    }).then(function() {
        return;
    });
}
 
// 리뷰 삭제
function deleteReview(){
    let reviewId = event.target.id;
    playConfirm("리뷰를 삭제하시겠습니까?", null, "question", "삭제하기", "취소하기", "deleteReviewProc('" + reviewId + "')", "playToast('취소하셨습니다.', null)");
}
 
function deleteReviewProc(reviewId){
    console.log("reviewId : " + reviewId);
    $.ajax({
        url: "deleteReview.do",
        type: "POST",
        async: true,
        dataType: "json",
        data: {
            reviewId: reviewId
        },
        success: function(res){
            if(res.code == 1){
                playToast(res.message, "success");
                setTimeout(function(){
                    window.location.reload();
                }, 2000);
            } else {
                playToast("오류가 발생했습니다. 다시 시도해주세요.", "error");
            }
        },
        error : function(error){
            playToast("오류가 발생했습니다.", 'error');
        }
    });
}
 
// 주문 상태 변경(orders_info)
function playAjax(){
    $.ajax({
        url: "updateOrder.do",
        type: "POST",
        async: true,
        dataType: "json",
        data: {
            orderId: orderId,
            optionId: optionId,
            orderStatus: orderStatus
        },
        success: function(res){
            if(res.code == 1){
                playToast(res.message, "success");
                setTimeout(function(){
                    window.location.reload();
                }, 2000);
            } else {
                playToast("오류가 발생했습니다. 다시 시도해주세요.", "error");
            }
        },
        error : function(error){
            playToast("오류가 발생했습니다.", 'error');
        }
    });
}
 
// 이미지 업로드
function playDropzone(){
     // 서버에 전송할 파일과 관련된 추가 정보
    var hiddenkey = $('#key').val();
    var imageStatus = $('#imageStatus').val();
    
     var dropzoneError = '';
     Dropzone.autoDiscover = false;
     const dropzone = new Dropzone('div#dropzone', {
         url: 'fileUpload.mdo',    // 파일 업로드 로직 호출
         method: 'post',    
        autoProcessQueue: false,        /** 자동 업로드 */
        autoQueue: true,                /** 파일 업로드시 큐에 자동 업로드 */ 
        clickable: true,                /** 클릭 가능 여부 */
        createImageThumbnails: true,    /** 이미지 미리보기 */
        thumbnailHeight: 150,            /** 이미지 크기 조절 */
        thumbnailWidth: 150,            /** 이미지 크기 조절 */
        paramName: 'images',            /** 서버로 전송될 파일의 파라미터 이름 */
        params: {                         /** 파일과 전송될 추가 정보 */
            key: hiddenkey,
            imageStatus: imageStatus,
            imageBy: orderId + "_" + optionId
         },
        addRemoveLinkes: true,            /** 삭제 버튼 표시 여부 */
        dicRemoveFile: 'X',                /** 삭제 버튼 텍스트 */
        parallelUploads: 10,            /** 동시 업로드가능한 파일  */
        uploadMultiple: true,            /** 다중 업로드 기능 */
        acceptedFiles: '.jpeg,.jpg,.png,.gif,.JPEG,.JPG,.PNG,.GIF',
        dictInvalidFileType: '이미지 파일만 업로드 가능합니다.',
         previewTemplate: document.querySelector('#dropzone-preview').innerHTML,
 
         /** 초기 설정 */
         init: function() {
            var myDropzone = this;
            document.querySelector(".baseImgDiv").style.display="none";
            document.querySelector("#dropzone").style.justifyContent = "";
            reviewStatus = '포토';
            
            // 업로드 대기중인 파일 처리
            $('.insertBtn').on('click', function(e) {
                myDropzone.processQueue();    
            });
            
            // 업로드 대기중/업로드된 파일 모두 삭제
            $('.cancelBtn').on('click', function(e) {
                myDropzone.removeAllFiles(true);    
            });
            
            // maxfilesexceeded : 업로드 개수를 초과하는 경우
            this.on('maxfilesexceeded', function(file) {
                myDropzone.removeFile(file);
            });
 
            // sendingmultiple : 여러 파일을 동시에 업로드시,  전송 직전에 발생
            this.on('sendingmultiple', function(file, xhr, formData) {
                console.log('보내는 중');
            });
            
            // successmultiple : 다중 파일 업로드 성공한 경우
            this.on('successmultiple', function(file, responseText) {
            });
            
            this.on('error', function(file, errorMessage) {
                console.log(errorMessage);
            });
            
            // queuecomplete : 이벤트 성공 여부 확인 로그
            this.on('queuecomplete', function(e) {
                console.log('queuecomplete');
            });
            
            // 업로드된 파일 삭제
            this.on('removedfile', function(data) {
                console.log("data : " + data.name);
            });
        }
     });
}
 
 
 

 

 

ClientOrderController.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
package com.w2.client.controller;
 
import java.io.IOException;
import java.util.Arrays;
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.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.ResponseBody;
import org.springframework.web.util.WebUtils;
 
import com.w2.board.ReviewVO;
import com.w2.board.service.ReviewService;
import com.w2.cart.CartVO;
import com.w2.client.ClientVO;
import com.w2.client.service.ClientService;
import com.w2.clientAddress.service.ClientAddressService;
import com.w2.coupon.service.CouponService;
import com.w2.file.service.ImageService;
import com.w2.order.OrderInfoVO;
import com.w2.order.service.OrderService;
import com.w2.util.ClientCookie;
import com.w2.util.RandomString;
import com.w2.util.ResponseDTO;
 
@Controller
public class ClientOrderController {    
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;
    
    @Autowired
    private ClientService clientService;
    
    @Autowired
    private OrderService orderService;
    
    @Autowired
    private ClientAddressService addressService;
    
    @Autowired
    private CouponService couponService;
    
    @Autowired
    private ReviewService reviewService;
 
    @Autowired
    private ImageService imageService;
    
    @RequestMapping("noClientOrder.do")
    public String noClientOrderView() {
        return "order/noClientOrder";
    }
 
    @RequestMapping("ttt.do")
    public String ttt(@Param("ID")String id) {
        System.err.println(">>> id : " + id);
        return "test";
    }
    
    /**
     * 주문 화면 호출
     * @return
     */
    @RequestMapping("orderRegister.do")
    public String orderRegister(@Param("caIdList"String cartList, @Param("cartOk"String cartOk,HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, CartVO cartvo) {
        String userId = "";
        String[] list = cartList.split(",");
        List<String> cartIdList = Arrays.asList(list);
        
        Map<StringObject> orderMap = new HashMap<StringObject>();
        orderMap.put("cartIdList", cartIdList);
        
        if(session.getAttribute("userInfo"== null) {
            if(cartOk != null && cartOk.equals("Y")) {
                String cookieId = ClientCookie.setCookie(request, response);
                orderMap.put("cookieId", cookieId);
                session.setAttribute("cookieId", cookieId);
            }
            if(session.getAttribute("cookieId"== null) {
                return "order/orderLogin";
            }
        } else {
            ClientVO user= (ClientVO)session.getAttribute("userInfo");
            userId = user.getClientId();
            orderMap.put("clientId", user.getClientId());
            model.addAttribute("baseAddress", addressService.getBaseAddress(user.getClientId()));
            model.addAttribute("couponList", couponService.getCouponList(user.getClientId()));
        }
        
        List<CartVO> orderList = orderService.getOrderProductList(orderMap);
        if(orderList.size() <= 0) {
            return "redirect:login.do";
        }else {
            model.addAttribute("orderList", orderList);
        }
        
        return "order/orderRegister";
    }
    
    /**
     * 주문 상세 페이지 호출
     * @return
     */
    @RequestMapping("orderInfo.do")
    public String orderInfo(@Param("orderId"String orderId, HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, CartVO cartvo) {
        model.addAttribute("orderInfo", orderService.getOrderInfo(orderId));
        model.addAttribute("orderProductList", orderService.getOrderInfoList(orderId));
        return "order/orderInfo";
    }
    
    /** 주문 추가 */
    @ResponseBody
    @PostMapping("orderRegisterProc.do")
    public ResponseDTO<String> orderRegisterProc(@RequestBody Map<StringObject> data, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        String orderId = "OD" + RandomString.createFileName() + RandomString.setRandomString(8"number");
        
        Map<StringObject> addressInfo = (Map<StringObject>) data.get("addressInfo");
        
        // 배송지Id 설정
        if(addressInfo.get("addressId"== null || addressInfo.get("addressId"== "") {
            addressInfo.put("addressId""AD" + RandomString.createFileName() + RandomString.setRandomString(5"number"));
            data.put("addressInfo", addressInfo);
        }
        
        // 주문번호 설정
        data.put("orderId", orderId);
 
        if(session.getAttribute("userInfo"== null) {
            data.put("cookieId", (String)session.getAttribute("cookieId"));
        } 
        
        try {
            System.err.println("6. try 시작");
            int result = orderService.insertImsiOrder(data);
            
            System.err.println("14. insertImsiOrder : " + result);
            orderId = (String)data.get("orderId");
            if(result > 0) {
                code = 1;
                resultCode = "success";
                msg = "주문이 완료되었습니다.";
            } else {
                code = -1;
                resultCode = "fail";
                msg = "주문중 오류가 발생했습니다.";
            }
        } catch (Exception e) {
            code = -1;
            resultCode = "fail";
            msg = "오류가 발생했습니다.";
            orderId = null;
        }
        return new ResponseDTO<String>(statusCode, code, resultCode, msg, orderId);
    }
    
    /** 결제 정보 등록 */
    @ResponseBody
    @PostMapping("paymentInsert.do")
    public ResponseDTO<String> paymentInsert(@RequestBody Map<StringObject> data) throws IOException {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        String orderId = (String)data.get("orderId");
 
        try {
            System.err.println("31. try 시작");
            int result = orderService.insertPayment(data);
            System.err.println("32. insertPayment :  " + result);
            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, orderId);
    }
    
    /**
     * 비회원 로그인 프로세스
     * @param vo: 사용자 정보
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("loginOrder.do")
    public String loginOrder(ClientVO vo, HttpServletRequest request, HttpServletResponse response, Model model, @Param("cartList"String cartList) {
        HttpSession session = request.getSession();
        ClientVO client = clientService.getClient(vo);
        
        if(client != null) {
            // 아이디 존재
            if(!passwordEncoder.matches(vo.getClientPwd(), client.getClientPwd())) {
                // 비밀번호 불일치
                model.addAttribute("msg""비밀번호가 일치하지 않습니다.");
                return "order/orderLogin";
            } else {
                // 로그인 성공
                session.setAttribute("userInfo", client);
                session.setMaxInactiveInterval(10*60);
                
                // 쿠키 존재하는 경우 쿠키 삭제
                if(ClientCookie.checkCookie(request, response) == 1) {
                    clientService.changeCookieSetId(WebUtils.getCookie(request, "clientCookie").getValue(), vo.getClientId());
                    ClientCookie.removeCookie(request, response);
                }
                return "redirect:orderRegister.do?cartList="+cartList;
            }
        } else {
            // 아이디 불일치
            model.addAttribute("msg""아이디가 존재하지 않습니다.");
            return "order/orderLogin";
        }
    }
 
    /** 주문 수정 */
    @ResponseBody
    @PostMapping("updateOrder.do")
    public ResponseDTO<OrderInfoVO> updateOrder(OrderInfoVO order, String orderStatus, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        
        Map<StringObject> orderData = new HashMap<StringObject>();
        orderData.put("order", order);
        orderData.put("orderStatus", orderStatus);
        
        if(session.getAttribute("userInfo"== null) {
            orderData.put("cookieId", (String)session.getAttribute("cookieId"));
        } else {
            ClientVO client = (ClientVO) session.getAttribute("userInfo");
            orderData.put("clientId", client.getClientId());
        }
        
        System.err.println("orderData : " + orderData);
        
        try {
            int result = orderService.updateOrder(orderData);
            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<OrderInfoVO>(statusCode, code, resultCode, msg, order);
    }
 
    /** 교환, 환불 요청 */
    @ResponseBody
    @PostMapping("insertSwapRefund.do")
    public ResponseDTO<String> insertSwapRefund(String requestWhat, String orderId, String optionId, String reason, String email, 
                                                String deliverWay, int cost, String costMtd, String status, String bankId, String refundBankNum, 
                                                HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        String id = "";
        
        Map<StringObject> requestInfo = new HashMap<StringObject>();
        requestInfo.put("requestWhat", requestWhat);
        requestInfo.put("orderId", orderId);
        requestInfo.put("reason", reason);
        requestInfo.put("email", email);
        requestInfo.put("deliverWay", deliverWay);
        requestInfo.put("cost", cost);
        requestInfo.put("costMtd", costMtd);
        requestInfo.put("status", status);
 
        if(requestWhat.equals("swap")) {
            id += "SW";
        } else if(requestWhat.equals("refund")) {
            id += "RF";
            requestInfo.put("bankId", bankId);
            requestInfo.put("refundBankNum", refundBankNum);
        }
        id += RandomString.createFileName() + RandomString.setRandomString(5"number");
        requestInfo.put("id", id);
        
        if(session.getAttribute("userInfo"!= null) {
            ClientVO client = (ClientVO) session.getAttribute("userInfo");
            requestInfo.put("clientId", client.getClientId());
        }
        
        try {
            int result = orderService.insertSwapRefund(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);
    }
    
 
    /** 리뷰 등록 */
    @ResponseBody
    @PostMapping("insertReview.do")
    public ResponseDTO<String> insertReview(ReviewVO review, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
        String id = "";
 
        ClientVO client = (ClientVO)session.getAttribute("userInfo");
 
        review.setClientId(client.getClientId());
        review.setReviewId("RE" + RandomString.createFileName() + RandomString.setRandomString(5"number"));
 
        try {
            int result = reviewService.insertReview(review);
            System.err.println("누가 먼저 실행되냐고");
            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);
    }
    
    /** 리뷰 조회 */
    @ResponseBody
    @PostMapping("getReviewInfo.do")
    public ResponseDTO<HashMap<StringObject>> getReviewInfo(String reviewId, HttpSession session) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
 
        HashMap<StringObject> result = new HashMap<StringObject>();
        ReviewVO review = reviewService.getReviewInfo(reviewId);
        if(review != null) {
            code = 1;
            resultCode = "success";
            msg = "조회가 완료되었습니다.";
            
            result.put("review", review);
            if(review.getReviewStatus().equals("포토")) {
                result.put("reviewImage", reviewService.getReviewImage(review));
            }
            System.err.println("result : " + result);
        } else {
            code = -1;
            resultCode = "fail";
            msg = "오류가 발생했습니다.";
        }
        return new ResponseDTO<HashMap<StringObject>>(statusCode, code, resultCode, msg, result);
    }
    
    /** 리뷰 삭제 */
    @ResponseBody
    @PostMapping("deleteReview.do")
    public ResponseDTO<String> deleteReview(String reviewId, HttpSession session) {
        Integer statusCode = HttpStatus.OK.value();
        int code = 0;
        String resultCode;
        String msg;
 
        ClientVO client = (ClientVO)session.getAttribute("userInfo");
        ReviewVO review = reviewService.getReviewInfo(reviewId);
        if(review.getClientId().equals(client.getClientId())) {
            int result = reviewService.deleteReview(reviewId);
            if(result > 0) {
                result = imageService.deleteReviewImage(review.getOrderId() + "_" + review.getOptionId());
                code = 1;
                resultCode = "success";
                msg = "리뷰가 삭제되었습니다.";
            } else {
                code = -1;
                resultCode = "fail";
                msg = "오류가 발생했습니다.";
            }
        } else {
            code = -1;
            resultCode = "fail";
            msg = "오류가 발생했습니다.";
        }
        return new ResponseDTO<String>(statusCode, code, resultCode, msg, reviewId);
    }
}
 

 

 

ReviewService.java 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.w2.board.service;
 
import java.util.HashMap;
import java.util.List;
 
import com.w2.board.ReviewVO;
import com.w2.util.Search;
 
public interface ReviewService {
    List<ReviewVO> getReviewList(Search search);
    int getReviewListCnt(Search search);
    ReviewVO getReview(ReviewVO vo);
    int insertReview(ReviewVO vo);
    ReviewVO getReviewInfo(String reviewId);
    List<ReviewVO> getMyReviewList(HashMap<String, Object> param);
    int getMyReviewListCnt(String clientId);
    List<String> getReviewImage(ReviewVO review);
    int deleteReview(String reviewId);
}
 

 

 

ReviewServiceImpl.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
package com.w2.board.service;
 
import java.util.HashMap;
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.w2.board.ReviewDAO;
import com.w2.board.ReviewVO;
import com.w2.util.Search;
 
@Service
public class ReviewServiceImpl implements ReviewService {
 
    @Autowired
    private ReviewDAO reviewDao;
    
    @Override
    public List<ReviewVO> getReviewList(Search search) {
        return reviewDao.getReviewList(search);
    }
 
    @Override
    public int getReviewListCnt(Search search) {
        return reviewDao.getReviewListCnt(search);
    }
 
    @Override
    public ReviewVO getReview(ReviewVO vo) {
        return reviewDao.getReview(vo);
    }
    
    @Override
    public int insertReview(ReviewVO vo) {
        return reviewDao.insertReview(vo);
    }
 
    @Override
    public List<ReviewVO> getMyReviewList(HashMap<String, Object> param) {
        return reviewDao.getMyReviewList(param);
    }
 
    @Override
    public int getMyReviewListCnt(String clientId) {
        return reviewDao.getMyReviewListCnt(clientId);
    }
 
    @Override
    public ReviewVO getReviewInfo(String reviewId) {
        return reviewDao.getReviewInfo(reviewId);
    }
 
    @Override
    public List<String> getReviewImage(ReviewVO review) {
        return reviewDao.getReviewImage(review);
    }
 
    @Override
    public int deleteReview(String reviewId) {
        return reviewDao.deleteReview(reviewId);
    }
 
}
 

 

 

ReviewDAO.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
package com.w2.board;
 
import java.util.HashMap;
import java.util.List;
 
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import com.w2.util.Search;
 
@Repository
public class ReviewDAO {
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    
    public List<ReviewVO> getReviewList(Search search) {
        return sqlSessionTemplate.selectList("ReviewDAO.getReviewList", search);
    }
    
    public int getReviewListCnt(Search search) {
        return sqlSessionTemplate.selectOne("ReviewDAO.getReviewListCnt", search);
    }
    
    public ReviewVO getReview(ReviewVO vo) {
        return sqlSessionTemplate.selectOne("ReviewDAO.getReview", vo);
    }
    
    public int insertReview(ReviewVO vo) {
        return sqlSessionTemplate.insert("ReviewDAO.insertReview", vo);
    }
    
    public List<ReviewVO> getMyReviewList(HashMap<String, Object> param) {
        return sqlSessionTemplate.selectList("ReviewDAO.getMyReviewList", param);
    }
    public int getMyReviewListCnt(String clientId) {
        return sqlSessionTemplate.selectOne("ReviewDAO.getMyReviewListCnt", clientId);
    }
 
    public ReviewVO getReviewInfo(String reviewId) {
        return sqlSessionTemplate.selectOne("ReviewDAO.getReviewInfo", reviewId);
    }
 
    public List<String> getReviewImage(ReviewVO review) {
        return sqlSessionTemplate.selectList("ReviewDAO.getReviewImage", review);
    }
 
    public int deleteReview(String reviewId) {
        return sqlSessionTemplate.delete("ReviewDAO.deleteReview", reviewId);
    }
}
 

 

 

review-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
<?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="ReviewDAO">
    <select id="getReviewList" resultType="review">
        SELECT row_number() over(ORDER BY reviewDate) as reviewIdx, r.*
        FROM review r
        ORDER BY reviewIdx DESC
        LIMIT #{startList}, #{listSize};
    </select>
    
    <select id="getReviewListCnt" resultType="int">
        SELECT count(*)
        FROM review
    </select>
    
    <select id="getReview" resultType="review">
        SELECT *
        FROM review
        WHERE reviewId = #{reviewId}
    </select>
    
    <insert id="insertReview" parameterType="review">
        INSERT INTO review(reviewId, clientId, orderId, optionId, reviewContent, reviewStar, reviewDate, reviewStatus, productId)
        VALUES(#{reviewId}, #{ clientId }, #{ orderId }, #{ optionId }, #{ reviewContent }, #{ reviewStar }, CURRENT_TIMESTAMP, #{ reviewStatus }, #{ productId })
    </insert>
    
    <select id="getMyReviewList" parameterType="hashmap" resultType="review">
        SELECT *
        FROM review
        WHERE clientId = #{clientId}
        LIMIT #{search.startList}, #{search.listSize}
    </select>
    
    <select id="getMyReviewListCnt" parameterType="String" resultType="int">
        SELECT COUNT(*)
        FROM review
        WHERE clientId = #{clientId}
    </select>
    
    
    <select id="getReviewInfo" parameterType="String" resultType="review">
        SELECT * 
        FROM review
        WHERE reviewId = #{ reviewId }
    </select>
    
    <select id="getReviewImage" parameterType="review" resultType="String">
        SELECT CONCAT(imageDir, imageName)
        FROM client_image
        WHERE imageBy = CONCAT(#{ orderId }, '_', #{ optionId })
    </select>
    
    <update id="deleteReview" parameterType="String">
        UPDATE review
        SET reviewStatus = '삭제'
        WHERE reviewId=#{ reviewId }
    </update>
</mapper>

 

 

 

>> 실행

 

 

>>> 리뷰 존재하지 않는 경우 > 리뷰 작성

 

 

>>> 리뷰 작성 후 등록하기

 

 

>>> 리뷰 존재하는 경우

 

>>> 리뷰 보기

 

 

 

 

>>> 리뷰 삭제시

 

 

---- 현재 환불 작업중이라 뒤죽박죽인 부분이 있을 수 있다.

반응형