Jelajahi Sumber

상품상세 쿠폰 다운로드

eskim 4 tahun lalu
induk
melakukan
0f8061702a

+ 70 - 9
src/main/java/com/style24/front/biz/service/TsfCouponService.java

@@ -361,25 +361,84 @@ public class TsfCouponService {
 	 * @since 2021.03.12
 	 */
 	@Transactional("shopTxnManager")
-	public String createGoodsCoupon(Goods goods) {
+	public String createGoodsCoupon(Goods parmsGoods) {
 		String result = "SUCESS";
-		int downloadCnt = 1; 	// 쿠폰당 다운 받을수
+		
+		log.info("상품쿠폰 발급전 정보 goods {}", parmsGoods);
+		
+		// 쿠폰 모두 받기
+		if (parmsGoods.getArrGoodsCd() != null && parmsGoods.getArrGoodsCd().length > 0) {
+			
+			int idx = 0;
+			int couponCnt = 0; 
+			for (String goodsCd : parmsGoods.getArrGoodsCd()) {
+				Goods goods = new Goods();
+				goods.setGoodsCd(goodsCd);
+				goods.setCpnId(parmsGoods.getArrCpnId()[idx]);
+				goods.setCpnAllDownYn(parmsGoods.getCpnAllDownYn());
+				goods.setSiteCd(parmsGoods.getSiteCd());
+				goods.setCustGb(parmsGoods.getCustGb());
+				goods.setFrontGb(parmsGoods.getFrontGb());
+				goods.setPointUnit(parmsGoods.getPointUnit());
+				goods.setCustGrade(parmsGoods.getCustGrade());
+				goods.setCustNo(parmsGoods.getCustNo());
+				
+				result =  createCoupon(goods);
+				
+				if (result.indexOf("ERROR") < 0) {
+					couponCnt += Integer.parseInt(result);
+				}
+				
+				idx++;
+			}
+			
+			if (couponCnt > 0) {
+				result = Integer.toString(couponCnt);	
+			}else {
+				result = "ERROR_10";
+			}
+			
+		}else {
+			result =  createCoupon(parmsGoods);
+		
+		}
 
-		//log.info("상품쿠폰 발급전 정보 goods {}", goods);
+		return result;
+	}
 
+	private String createCoupon(Goods goods) {
+		
+		String result = "";
+		int downloadCnt = 1; 	// 쿠폰당 다운 받을수
+		int custPubLimitQty = 1;
+		int onePubQty = 1;
 		Collection<Coupon> goodsCouponList = couponDao.getGoodsCouponList(goods);
+		
 		if (goodsCouponList == null || goodsCouponList.isEmpty()) {
 			result = "ERROR_10";
 			return result;
 		}
 
 		Coupon coupon = goodsCouponList.iterator().next();
+		onePubQty = coupon.getOnePubQty();	// 1회 발급당 발행수량 설정
+
 		//log.info("상품쿠폰 쿠폰정보  coupon {}", coupon);
 
-		// 발급수 확인 -- 필요없나?
+		// 고객당 발급수량 확인
+		if (coupon.getCustPubLimitQty() > 0) {
+			int tempCustCouponCnt = coupon.getCustPubLimitQty() * onePubQty;
+			//if (coupon.getCustPubLimitQty() <= coupon.getCustCouponCnt()) {
+			if (tempCustCouponCnt <= coupon.getCustCouponCnt()) {
+				//log.info("상품쿠폰 다운  skip: 쿠폰발급수 : {}, 회원발급수 : {}", coupon.getCustPubLimitQty(), coupon.getCustCouponCnt());
+				result = "ERROR_30";
+				return result;
+			}
+		}
+		
+		// 발급수 확인
 		if (coupon.getTotPubLimitQty() > 0) {
-			if (coupon.getTotPubLimitQty() <= coupon.getCustCouponCnt()) {
-				//log.info("상품쿠폰 다운  skip: 쿠폰발급수 : {}, 회원발급수 : {}", coupon.getTotPubLimitQty(), coupon.getCustCouponCnt());
+			if (coupon.getTotPubLimitQty() <= coupon.getTotCouponCnt()) {
+				//log.info("상품쿠폰 다운  skip: 쿠폰총발급제한수 : {}, 전체발급수 : {}", coupon.getTotPubLimitQty(), coupon.getTotCouponCnt());
 				result = "ERROR_30";
 				return result;
 			}
@@ -404,6 +463,9 @@ public class TsfCouponService {
 			}
 		}
 
+		//총발급수량
+		downloadCnt = custPubLimitQty * onePubQty;
+		
 		// 신규회원 NEW_CUST_YN
 		if ("Y".equals(coupon.getNewCustYn())) {
 			Customer customer = customerService.getCustomerFindByCustNo(goods.getCustNo());
@@ -421,8 +483,6 @@ public class TsfCouponService {
 			}
 		}
 
-		// 제휴링크 나중에 확인하자!!!!!
-
 		int count = 0;
 		for (Coupon tmpCoupon : goodsCouponList) {
 
@@ -444,8 +504,9 @@ public class TsfCouponService {
 			}
 		}
 		result = Integer.toString(count);	// 다운받은 쿠폰수
-
+		
 		return result;
+		
 	}
 
 	/**

+ 28 - 28
src/main/java/com/style24/front/biz/web/TsfGoodsController.java

@@ -5,8 +5,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 
-import com.style24.front.biz.thirdparty.SearchEngineDiquest;
-import com.style24.persistence.domain.searchengine.FeedbackResponse;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -33,6 +31,7 @@ import com.style24.front.biz.service.TsfRendererService;
 import com.style24.front.biz.service.TsfReviewService;
 import com.style24.front.biz.service.TsfWishlistService;
 import com.style24.front.biz.thirdparty.EigeneaiApi;
+import com.style24.front.biz.thirdparty.SearchEngineDiquest;
 import com.style24.front.support.controller.TsfBaseController;
 import com.style24.front.support.env.TsfConstants;
 import com.style24.front.support.security.session.TsfSession;
@@ -54,6 +53,7 @@ import com.style24.persistence.domain.Review;
 import com.style24.persistence.domain.SizeInfo;
 import com.style24.persistence.domain.WishList;
 import com.style24.persistence.domain.eigene.Eigeneai.Result;
+import com.style24.persistence.domain.searchengine.FeedbackResponse;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -1071,32 +1071,32 @@ public class TsfGoodsController extends TsfBaseController {
 
 		// 상품관련 기본값 설정(회원 등급, 앱, PC/모바일 등)
 		setGoods(paramsGoods);
-		//log.info("createGoodsCoupon  paramsGoods {}", paramsGoods);
-
-		// 일반상품과 딜상품 구분
-		Goods goods = goodsService.getGoodsInfo(paramsGoods);
-		if (goods == null || StringUtils.isBlank(goods.getGoodsCd())) {
-			result.set("message", "발급가능 쿠폰이 없습니다.");
-			result.set("status", "200");
-			result.set("params", paramsGoods);
-			return result;
-		}
-
-		//log.info("createGoodsCoupon  goods {}", goods);
-		if (TscConstants.GoodsType.DEAL.value().equals(goods.getGoodsType())) {
-			Collection<Goods> goodsDealComposeList = goodsService.getGoodsDealComposeList(paramsGoods);
-			// 상품쿠폰
-			if (goodsDealComposeList != null && !goodsDealComposeList.isEmpty()) {
-
-				ArrayList<String> arrGoodsList = new ArrayList<>();
-				for (Goods goodsCompose : goodsDealComposeList) {
-					arrGoodsList.add(goodsCompose.getCompsGoodsCd());
-				}
-
-				String[] arrGoodsCd = arrGoodsList.stream().toArray(String[]::new);
-				paramsGoods.setArrGoodsCd(arrGoodsCd);
-			}
-		}
+		log.info("createGoodsCoupon  paramsGoods {}", paramsGoods);
+//
+//		// 일반상품과 딜상품 구분
+//		Goods goods = goodsService.getGoodsInfo(paramsGoods);
+//		if (goods == null || StringUtils.isBlank(goods.getGoodsCd())) {
+//			result.set("message", "발급가능 쿠폰이 없습니다.");
+//			result.set("status", "200");
+//			result.set("params", paramsGoods);
+//			return result;
+//		}
+//
+//		//log.info("createGoodsCoupon  goods {}", goods);
+//		if (TscConstants.GoodsType.DEAL.value().equals(goods.getGoodsType())) {
+//			Collection<Goods> goodsDealComposeList = goodsService.getGoodsDealComposeList(paramsGoods);
+//			// 상품쿠폰
+//			if (goodsDealComposeList != null && !goodsDealComposeList.isEmpty()) {
+//
+//				ArrayList<String> arrGoodsList = new ArrayList<>();
+//				for (Goods goodsCompose : goodsDealComposeList) {
+//					arrGoodsList.add(goodsCompose.getCompsGoodsCd());
+//				}
+//
+//				String[] arrGoodsCd = arrGoodsList.stream().toArray(String[]::new);
+//				paramsGoods.setArrGoodsCd(arrGoodsCd);
+//			}
+//		}
 
 		// 쿠폰발급
 		// ERROR_10: 발급가능 쿠폰없음, 20: 발급완료 쿠폰, 30: 발급받은 쿠폰

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

@@ -162,6 +162,7 @@ public class Goods extends TscBaseDomain {
 	private String optionSoldoutSkip; 	//품절제외 Y, N
 	private int floorUnit; // 절사단위(1:일원단위절사, 10:십원단위절사, 100:백원단위절사)
 	private Integer cpnId;			// 쿠폰ID
+	private String cpnAllDownYn;		// 쿠폰모두받기
 
 	private String skuModelNo;		// SKUModelNo(WMS)
 	private String compsGoodsCd;	// 세트 구성품 상품번호

+ 7 - 0
src/main/java/com/style24/persistence/mybatis/shop/TsfCoupon.xml

@@ -260,6 +260,7 @@
 		     , A.CUST_PUB_LIMIT_QTY
 		     , A.TOT_PUB_LIMIT_QTY
 		     , A.BUY_LIMIT_AMT
+		     , A.ONE_PUB_QTY
 		     , A.MAX_DC_AMT
 		     , A.CPN_TYPE
 		     , A.AVAIL_STDT
@@ -271,6 +272,7 @@
 		     , A.FIRST_ORD_YN
 		     , A.BUY_STDT
 		     , A.BUY_EDDT
+		     , GOODS_CD
 		    -- , A.CURR_PRICE
 		     , DATE_FORMAT(A.AVAIL_EDDT, '%Y-%m-%d') AS AVAIL_EDDT
 		     , IFNULL((SELECT COUNT(1) FROM TB_CUST_COUPON WHERE CPN_ID = A.CPN_ID AND CUST_NO = #{custNo}),0) AS CUST_COUPON_CNT
@@ -285,6 +287,7 @@
 		       , CUST_PUB_LIMIT_QTY
 		       , TOT_PUB_LIMIT_QTY
 		       , BUY_LIMIT_AMT
+		       , ONE_PUB_QTY
 		       , MAX_DC_AMT
 		       , CPN_TYPE
 		       , AVAIL_STDT
@@ -296,6 +299,7 @@
 		       , FIRST_ORD_YN
 		       , BUY_STDT
 		       , BUY_EDDT
+		       , GOODS_CD
 		      -- , CURR_PRICE
 		       , RANK() OVER(ORDER BY DC_AMT DESC)  AS RNUM   -- 할인금액순
 		FROM   (
@@ -308,6 +312,7 @@
 		             , CP.CURR_PRICE                                          -- 즉시쿠폰적용판매가
 		             , CP.CUST_PUB_LIMIT_QTY                                  -- 1인당 발급제한수량
 		             , CP.TOT_PUB_LIMIT_QTY                                   -- 총발행제한수량(0은 무제한)
+		             , CP.ONE_PUB_QTY                                         -- 1회발행수량
 		             , CP.BUY_LIMIT_AMT                                       -- 구매제한금액
 		             , CP.CPN_TYPE                                            -- 쿠폰타입
 		             , CP.AVAIL_STDT                                          -- 유효시작일시
@@ -319,6 +324,7 @@
 		             , CP.FIRST_ORD_YN                                        -- 첫구매여부
 		             , CP.BUY_STDT                                            -- 첫구매시작일시
 		             , CP.BUY_EDDT                                            -- 첫구매종료일시
+		             , CP.GOODS_CD                                            -- 상품코드
 		             <![CDATA[
 		             , (CASE WHEN CP.DC_WAY = 'G240_10' THEN
 		           --         (CASE WHEN IFNULL(CP.MAX_DC_AMT, 0) >0 AND CP.MAX_DC_AMT < CP.DC_VAL THEN CP.MAX_DC_AMT ELSE CP.DC_VAL END)
@@ -340,6 +346,7 @@
 		                     , CP.TOT_PUB_LIMIT_QTY
 		                     , CP.CPN_TYPE
 		                     , CP.NEW_CUST_YN
+		                     , CP.ONE_PUB_QTY
 		                     , DATE_FORMAT(CP.CUST_JOIN_STDT, '%Y%m%d%H%i%S') AS CUST_JOIN_STDT
 		                     , DATE_FORMAT(CP.CUST_JOIN_EDDT, '%Y%m%d%H%i%S') AS CUST_JOIN_EDDT
 		                     , CP.FIRST_ORD_YN

+ 23 - 20
src/main/webapp/WEB-INF/views/web/goods/GoodsCouponFormWeb.html

@@ -39,11 +39,11 @@
 									<span>1인 최대 <th:block th:text="${(goodsCoupon.custPubLimitQty > 0) ? #numbers.formatInteger(goodsCoupon.custPubLimitQty, 0,'COMMA') +'장' : '무제한'}"></span>
 								</p>
 							</div>
-							<th:block th:if="${goodsCoupon.custPubLimitQty > 0 and goodsCoupon.custPubLimitQty <= goodsCoupon.custCouponCnt}">
+							<th:block th:if="${goodsCoupon.custPubLimitQty > 0 and (goodsCoupon.custPubLimitQty* goodsCoupon.onePubQty) <= goodsCoupon.custCouponCnt}">
 							<button type="button" class="btn btn_dark btn_block btn_coupon_done"  disabled="disabled"><span>받기완료</span></button>
 							</th:block>
-							<th:block th:unless="${goodsCoupon.custPubLimitQty > 0 and goodsCoupon.custPubLimitQty <= goodsCoupon.custCouponCnt}">
-							<button type="button" class="btn btn_dark btn_block btn_coupon_down" th:attr="cpnId=${goodsCoupon.cpnId}" th:id="${'coupon_'+goodsCoupon.cpnId}" onclick="fnGoodsCouponDown(this);"><span>쿠폰받기</span></button>
+							<th:block th:unless="${goodsCoupon.custPubLimitQty > 0 and (goodsCoupon.custPubLimitQty* goodsCoupon.onePubQty) <= goodsCoupon.custCouponCnt}">
+							<button type="button" class="btn btn_dark btn_block btn_coupon_down" th:attr="cpnId=${goodsCoupon.cpnId},goodsCd=${goodsCoupon.goodsCd}" th:id="${'coupon_'+goodsCoupon.cpnId}" onclick="fnGoodsCouponDown(this);"><span>쿠폰받기</span></button>
 							</th:block>
 						</div>
 					</li>
@@ -70,7 +70,7 @@
 		
 		let $obj = $(obj);
 		let cpnId = $obj.attr('cpnId');
-		let goodsCd = $('#goodsCouponForm input[name=goodsCd]').val();
+		let goodsCd = $obj.attr('goodsCd');
 		
 		 gagajf.ajaxJsonSubmit(_PAGE_GOODS_CPN_DOWNLOAD, JSON.stringify({goodsCd: goodsCd, cpnId: cpnId}), fnGoodsCouponCallBack);
 		 
@@ -87,19 +87,20 @@
 			let list = result.goodsCouponList;
 
 			list.forEach(function(coupon){
-				if (coupon.cpnId == cpnId){debugger;
+				if (coupon.cpnId == cpnId){
 					if (Number(coupon.custPubLimitQty) > 0){
-						if (Number(coupon.custPubLimitQty) <= Number(coupon.custCouponCnt)){
-							$('#coupon_'+ coupon.cpnId).html('<span>받기완료</span>');
-							$('#coupon_'+ coupon.cpnId).attr('disabled', true);
-							$('#coupon_'+ coupon.cpnId).removeClass('btn_coupon_down').addClass('btn_coupon_done');
+						if ((Number(coupon.custPubLimitQty) *Number(coupon.onePubQty)) <= Number(coupon.custCouponCnt)){
+							$('#coupon_'+ coupon.cpnId + ' span').text('받기완료');
+							$('#coupon_'+ coupon.cpnId + ' span').parent().removeClass('btn_coupon_down').addClass('btn_coupon_done');
+							$('#coupon_'+ coupon.cpnId + ' span').parent().attr('disabled', true);
+							
 						}
 					}
 					if (Number(coupon.TotPubLimitQty) > 0){
 						if (Number(coupon.TotPubLimitQty) <= Number(coupon.CustCouponCnt)){
-							$('#coupon_'+ coupon.cpnId).html('<span>받기완료</span>');
-							$('#coupon_'+ coupon.cpnId).attr('disabled', true);
-							$('#coupon_'+ coupon.cpnId).removeClass('btn_coupon_down').addClass('btn_coupon_done');
+							$('#coupon_'+ coupon.cpnId + ' span').text('받기완료');
+							$('#coupon_'+ coupon.cpnId + ' span').parent().removeClass('btn_coupon_down').addClass('btn_coupon_done');
+							$('#coupon_'+ coupon.cpnId + ' span').parent().attr('disabled', true);
 						}
 					}
 				}
@@ -113,10 +114,13 @@
 	var fnGoodsCouponDownAll = function(){
 		//00개 쿠폰이 발급되었습니다.
 		let couponDownAbleYn = "N";
+		let cpnAllDownYn = "Y";
+		let arrGoodsCd = [];
 		let arrCpnId = [];
 		$('#goodsCouponForm').find('.btn_coupon_down').each(function(){
 			if (!$(this).attr('disabled')){
 				couponDownAbleYn = "Y";
+				arrGoodsCd.push($(this).attr('goodscd'));
 				arrCpnId.push($(this).attr('cpnId'));
 			}
 		});	
@@ -125,8 +129,7 @@
 			mcxDialog.alert("다운 받을 쿠폰이 없습니다.");
 			return false;
 		}
-		let goodsCd = $('#goodsCouponForm input[name=goodsCd]').val();
-		gagajf.ajaxJsonSubmit(_PAGE_GOODS_CPN_DOWNLOAD, JSON.stringify({goodsCd: goodsCd, arrCpnId: arrCpnId}), fnGoodsCouponDownAllBack);
+		gagajf.ajaxJsonSubmit(_PAGE_GOODS_CPN_DOWNLOAD, JSON.stringify({arrGoodsCd: arrGoodsCd, arrCpnId: arrCpnId, cpnAllDownYn: cpnAllDownYn}), fnGoodsCouponDownAllBack);
 		
 	}
 	
@@ -143,16 +146,16 @@
 						if (coupon.cpnId == cpnId){
 							if (Number(coupon.custPubLimitQty) > 0){
 								if (Number(coupon.custPubLimitQty) <= Number(coupon.custCouponCnt)){
-									$('#coupon_'+ coupon.cpnId).html('<span>받기완료</span>');
-									$('#coupon_'+ coupon.cpnId).attr('disabled', true);
-									$('#coupon_'+ coupon.cpnId).removeClass('btn_coupon_down').addClass('btn_coupon_done');
+									$('#coupon_'+ coupon.cpnId + ' span').text('받기완료');
+									$('#coupon_'+ coupon.cpnId + ' span').parent().removeClass('btn_coupon_down').addClass('btn_coupon_done');
+									$('#coupon_'+ coupon.cpnId + ' span').parent().attr('disabled', true);
 								}
 							}
 							if (Number(coupon.TotPubLimitQty) > 0){
 								if (Number(coupon.TotPubLimitQty) <= Number(coupon.CustCouponCnt)){
-									$('#coupon_'+ coupon.cpnId).html('<span>받기완료</span>');
-									$('#coupon_'+ coupon.cpnId).attr('disabled', true);
-									$('#coupon_'+ coupon.cpnId).removeClass('btn_coupon_down').addClass('btn_coupon_done');
+									$('#coupon_'+ coupon.cpnId + ' span').text('받기완료');
+									$('#coupon_'+ coupon.cpnId + ' span').parent().removeClass('btn_coupon_down').addClass('btn_coupon_done');
+									$('#coupon_'+ coupon.cpnId + ' span').parent().attr('disabled', true);
 								}
 							}
 						}