jsh77b 5 years ago
parent
commit
6a63445494

+ 81 - 14
src/main/java/com/style24/core/biz/service/TscOrderService.java

@@ -702,37 +702,106 @@ public class TscOrderService {
 	}
 	
 	public Collection<Order> getGoodsCpnApplyList(Collection<Order> tmtbGoodsApplyList, Collection<Order> goodsCpnAllList) {
-		Collection<Order> goodsCpnApplyList = new ArrayList<Order>();
+		Collection<Order> goodsApplyCpnList = new ArrayList<Order>();
 		
 		Boolean temp = true;
+		int cpnDcAmt = 0;
 		
-		// 쿠폰대상이 있는 상품만 정리
+		// 1. 쿠폰대상이 있는 상품만 정리
 		for (Order tmtbGoods : tmtbGoodsApplyList) {
-			Collection<Order> goodsCpnList = new ArrayList<Order>();
+			List<Order> goodsCpnList = new ArrayList<Order>();
 			
 			for (Order goodsCpn : goodsCpnAllList) {
-				// 상품코드비교후 담기
+				
+				// 2. 적용상풒 전체(A) or 상품코드 같을때 담기
 				if ("A".equals(goodsCpn.getApplyScope()) || tmtbGoods.getGoodsCd().equals(goodsCpn.getGoodsCd())) {
 					temp = true;
 					
-					// 이미 담긴 상풐은 제외
+					// 3. 상품쿠폰목록에 담긴 상풐은 제외
 					for (Order goodsCpnApply : goodsCpnList) {
 						if (tmtbGoods.getGoodsCd().equals(goodsCpnApply.getGoodsCd())) {
 							temp = false;
 						}
 					}
 					
+					// 4. 상품쿠폰목록에 담기 가능 상품 담기
 					if (temp) {
-						goodsCpnList.add(goodsCpn);
+						// 5. 할인방식 금액, 율 판단 
+						// 할인금액 (G240_10)
+						if ("G240_10".equals(goodsCpn.getDcWay())) {
+							goodsCpn.setCpnDcAmt(goodsCpn.getDcVal());
+						}
+						// 할인율 (G240_11)
+						else {
+							// 6. 할인율 일때 최대금액 판단으로 할인금액 등록
+							if (tmtbGoods.getTmtbDcAmt() > 0) {
+								cpnDcAmt = (tmtbGoods.getTmtbDcAmt() * goodsCpn.getDcVal()) / 100;
+							} else {
+								cpnDcAmt = (tmtbGoods.getCurrPrice() * goodsCpn.getDcVal()) / 100;
+							}
+							
+							// 7. 할인금액 최대값보다 작으면 적용 or getMaxDcAmt( == 0 이면 무제한
+							if (goodsCpn.getMaxDcAmt() > cpnDcAmt || goodsCpn.getMaxDcAmt() == 0) {
+								goodsCpn.setCpnDcAmt(cpnDcAmt);
+							} else {
+								goodsCpn.setCpnDcAmt(goodsCpn.getMaxDcAmt());
+							}
+						}
+						
+						// 8. 주문최소주문금액 보다 크면 쿠폰 적용
+						if (tmtbGoods.getCurrPrice() > goodsCpn.getBuyLimitAmt()) {
+							goodsCpnList.add(goodsCpn);
+						}
 					}
 				}
 			}
 			
-			tmtbGoods.setGoodsCpnList(goodsCpnList);
-			goodsCpnApplyList.add(tmtbGoods);
+			// 쿠폰할인금액이 높은순으로 정렬 함수 
+			List<Order> goodsCpnSortList = getListSort(goodsCpnList);
+			
+			tmtbGoods.setGoodsCpnList(goodsCpnSortList);
+			goodsApplyCpnList.add(tmtbGoods);
 		}
 		
-		return goodsCpnApplyList;
+		return goodsApplyCpnList;
+	}
+	
+	// 쿠폰할인금액이 높은순으로 정렬 함수
+	private List<Order> getListSort(List<Order> goodsCpnList) {
+		List<Order> goodsCpnSortList = new ArrayList<Order>();
+		
+		Order tempOrder1 = null;
+		Order tempOrder2 = null;
+		int cnt 	= 0;
+		int sameCnt = 0;
+		
+		// 1. 쿠폰할인금액 순으로 정렬
+		for (int i=0 ; i<goodsCpnList.size() ; i++) {
+			tempOrder1 = goodsCpnList.get(i);
+			cnt 	= 0;
+			sameCnt = 0;
+			
+			// 2. 몇번째로 큰 할인금액 인지 판단
+			for (int j=0 ; j<goodsCpnList.size() ; j++) {
+				tempOrder2 = goodsCpnList.get(j);
+				
+				if (tempOrder1.getCpnDcAmt() == tempOrder2.getCpnDcAmt() && i <= j) {
+					sameCnt++;
+				}
+				
+				if (tempOrder1.getCpnDcAmt() > tempOrder2.getCpnDcAmt()) {
+					cnt++;
+				}
+			}
+			
+			if (sameCnt > 0) {
+				cnt = cnt + (sameCnt -1);
+			}
+			
+			goodsCpnSortList.add(cnt, tempOrder1);
+		}
+		
+		return goodsCpnSortList;
 	}
 	
 	/**
@@ -786,14 +855,12 @@ public class TscOrderService {
 			// 1.2 즉시할인 적용가 * 주문수량(장바구니수량)
 			order.setCurrPrice(order.getCurrPrice() * order.getGoodsQty());
 			
-			log.info("order.getResDelvFeeCd() ::: {} ::: order.getGoodsCd() ::: {}", order.getResDelvFeeCd(), order.getGoodsCd());
-			
 			// 1.3 배송정책별 상품 구분
-			if (order.getResDelvFeeCd().equals("WMS")) {
+			if ("WMS".equals(order.getResDelvFeeCd())) {
 				wmsCartList.add(order);
 				wmsCnt++;
 			} 
-			else if (order.getResDelvFeeCd().equals("RES")) {
+			else if ("RES".equals(order.getResDelvFeeCd())) {
 				resCartList.add(order);
 				resCnt++;
 			} 
@@ -844,7 +911,7 @@ public class TscOrderService {
 		// 1. 총알배송 가능 시간 체크
 		if (orderDao.getDailyDeliveryTimeInfo() > 0) {
 			// 2. 총알배송 가능 지역 제크
-			if(StringUtils.isEmpty(order.getRecipZipcode())) {
+			if (StringUtils.isEmpty(order.getRecipZipcode())) {
 				rtn = 1;
 			} else {
 				if (orderDao.getDailyDeliveryZoneInfo(order) > 0) {

+ 1 - 1
src/main/java/com/style24/persistence/domain/Order.java

@@ -412,7 +412,7 @@ public class Order extends TscBaseDomain {
 	Collection<Order> wmsCartList;
 	Collection<Order> resCartList;
 	Collection<Order> delvCartList;
-	Collection<Order> goodsCpnList;
+	List<Order> goodsCpnList;
 	
 	@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
 	private int[] freegiftSqArr;

+ 2 - 1
src/main/java/com/style24/persistence/mybatis/shop/TscOrder.xml

@@ -1825,7 +1825,7 @@
 		</if>
 	</select>
 	
-		<!-- 총알배송 가능시간 조회 -->
+	<!-- 총알배송 가능시간 조회 -->
 	<select id="getDailyDeliveryTimeInfo" resultType="int">
 		/* order.getDailyDeliveryTimeInfo */
 		SELECT CASE WHEN TIME_FORMAT(NOW(), '%H%i%S') > 100000
@@ -1842,6 +1842,7 @@
 		  FROM TB_DAILY_DELIVERY_ZONE DC
 	 	 WHERE 1=1
 		   AND ZIP_NO = #{recipZipcode}
+		   AND ISUSE = 'Y'
 	</select>
 	
 	<!-- 상품쿠폰, 장바구니쿠폰 적용 상품 조회 -->