Browse Source

修改新人券业务逻辑

wangxiaoming 7 years ago
parent
commit
53bb7592d2

+ 1 - 1
tooth-common-core/src/main/java/com/iamberry/wechat/core/entity/coupon/CouponItemDto.java

@@ -37,7 +37,7 @@ public class CouponItemDto implements java.io.Serializable{
 	private String couponItemRemark;			//优惠券详情备注
 	private PageBean page;						//分页
 
-	private Integer couponIsNewPeople;			//是否为新人优惠券
+	private Integer couponIsNewPeople;			//是否为新人优惠券 1:是  2:否
 
 	private Integer couponIsUse;			//判断是否可用  1:可以使用    2:不可用
 	private String couponNoUseReason;			//不可用说明

+ 1 - 1
tooth-common-tool/src/main/java/com/iamberry/wechat/tools/ResultInfo.java

@@ -268,7 +268,7 @@ public class ResultInfo {
 	public static String COUPON_OUTOFDATE="优惠券过期";
 	public static String COUPON_INVALID="优惠券无效";
 	public static String COUPON_CONSUME_NO_ENOUGH="消费额度不足,优惠券无法使用";
-	public static String COUPON_NO_MEMBER="非会员需要购买电动牙刷才能使用该优惠券";
+	public static String COUPON_NO_MEMBER="非会员需要购买电动牙刷刷头才能使用该优惠券";
 	public static String COUPON_NO_TOOTH="该现金券需要订单中有电动牙刷才能使用";
 
 	public static String COUPONITEMSTATUS_NORMAL = "normal";

+ 1 - 0
tooth-wechat-service/src/main/java/com/iamberry/wechat/service/mapper/productInfoMapper.xml

@@ -154,6 +154,7 @@
 		TB_IAMBERRY_PRODUCT_COLOR
 		WHERE
 		COLOR_PRODUCT_ID = #{colorProductId}
+		and color_status = 1
 		ORDER BY COLOR_DISCOUNT ASC
 	</select>
 

+ 23 - 3
tooth-wechat-web/src/main/java/com/iamberry/wechat/handles/coupon/CouponTypeHandler.java

@@ -523,17 +523,29 @@ public class CouponTypeHandler {
 	public ResultMsg getIsReceive(HttpServletRequest request){
 		ResultMsg resultMsg = new ResultMsg();
 		Member memberInfo = WechatUtils.getUserBySession(request);
+
+		memberInfo = memberService.getMemberByUserOpenId(memberInfo.getUserOpenid());
+
 		Integer msg = couponItemService.getIsReceive(memberInfo.getUserOpenid());
+
 		if(msg > 0){
 			resultMsg.setResultCode(ResultInfo.ERRORCODE);
 			resultMsg.setStatus(false);
 			resultMsg.setMessage("已领取优惠券");
 			return resultMsg;
 		}else{
-			resultMsg.setResultCode(ResultInfo.SUCCESSCODE);
-			resultMsg.setStatus(true);
+			/*未领取优惠券*/
+			if(memberInfo != null && memberInfo.getUserIdentity() == 1){
+				resultMsg.setResultCode(ResultInfo.SUCCESSCODE);
+				resultMsg.setStatus(true);
+				return resultMsg;
+			}else{
+				resultMsg.setResultCode("505");
+				resultMsg.setStatus(false);
+				resultMsg.setMessage("需要成为会员才能领取该优惠券");
+				return resultMsg;
+			}
 		}
-		return resultMsg;
 	}
 
 	/**
@@ -558,12 +570,20 @@ public class CouponTypeHandler {
 		}
 
 		Integer msg = couponItemService.getIsReceive(memberInfo.getUserOpenid());
+		memberInfo = memberService.getMemberByUserOpenId(memberInfo.getUserOpenid());
 		if(msg > 0){
 			resultMsg.setResultCode(ResultInfo.ERRORCODE);
 			resultMsg.setStatus(false);
 			resultMsg.setMessage("领取失败,该用户已领取过优惠券");
 			return resultMsg;
 		}else{
+			if(memberInfo.getUserIdentity() != 1){
+				resultMsg.setResultCode("505");
+				resultMsg.setStatus(false);
+				resultMsg.setMessage("需要成为会员才能领取");
+				return resultMsg;
+			}
+
 			CouponItem couponItem = new CouponItem();
 			couponItem.setCouponId(couponTypeList.get(0).getCouponId());
 			Calendar calendar = Calendar.getInstance();

+ 48 - 13
tooth-wechat-web/src/main/java/com/iamberry/wechat/handles/order/OrderHandler.java

@@ -164,8 +164,10 @@ public class OrderHandler {
 		// 判断当前提交的购物车ID,有多少产品在售
 		int total = 0; // 支付金额
 		int sum = 0; // 产品数量
-		boolean disable = false;	//标识,是否可以使用(新人券)优惠券,当购买商品需要有牙刷时才能使用优惠券
+		boolean disable = false;	//标识,是否可以使用(新人券)优惠券,当购买商品需要有牙刷时才能使用优惠券 - 20180316 以前
+		boolean brushFlag = false;	//标识,是否可以使用(新人券)优惠券,只能购买刷头的时候才能使用 - 20180316 以后
 		String element = systemService.selectOneShopRuleById(249).getRuleDesc();
+		String brushelEment = systemService.selectOneShopRuleById(253).getRuleDesc();
 
 		List<CartDto> tempCarts = new ArrayList<CartDto>();
 		for (CartDto cartDto : cartDtos) {
@@ -183,6 +185,13 @@ public class OrderHandler {
 					disable = true;
 				}
 			}
+
+			String[] brushelEls = brushelEment.split("-");
+			for(String brushelEl : brushelEls){
+				if(cartDto.getProductType() == Integer.valueOf(brushelEl)){		//判断订单中是否有刷头,有刷头 brushFlag 为true;
+					brushFlag = true;
+				}
+			}
 		}
 		if (sum <= 0) {
 			msg.setMessage(ResultInfo.cartEmptyError);
@@ -205,8 +214,8 @@ public class OrderHandler {
 			if(total >= couponItemDto.getCouponConsumeEnough()){
 
 				/*新人卷没有其他限制*/
-				if(couponItemDto.getCouponIsNewPeople() == 1 && member.getUserIdentity() != 1){  //当券为新人券,用户为非会员时,需要有牙刷,结算才可以使用该券
-					if(!disable){		//订单中没有牙刷
+				if(couponItemDto.getCouponIsNewPeople() == 1){  //当券为新人券
+					if(member.getUserIdentity() != 1 || !brushFlag){  //不为会员,或者没有牙刷刷头都无法使用
 						flag = false;
 					}
 				}else if(couponItemDto.getCouponIsPurchase() == 1){  ///*控制是否需要购买的有牙刷*/
@@ -332,6 +341,11 @@ public class OrderHandler {
 
 		/*是否含有电动牙刷*/
 		boolean isContainProduct = false;
+		boolean brushFlag = false;	//标识,是否可以使用(新人券)优惠券,只能购买刷头的时候才能使用 - 20180316 以后
+//		String element = systemService.selectOneShopRuleById(249).getRuleDesc();
+		String brushelEment = systemService.selectOneShopRuleById(253).getRuleDesc();
+
+		int brushelTotal = 0; // 牙刷总金额
 
 		int total = 0; // 需要支付的总额, 单位为分
 		/** 提前准备订单项数据 */
@@ -358,13 +372,24 @@ public class OrderHandler {
 				item.setItemProductPrice(cartDto.getProductDiscount());
 				item.setItemColorId(cartDto.getCartColorId());
 				list.add(item);
+
+
+				if(cartDto.getProductType() == 100){		//当订单中有电动牙刷时,isContainProduct为true
+					isContainProduct = true;
+				}
+
+				String[] brushelEls = brushelEment.split("-");
+				for(String brushelEl : brushelEls){
+					if(cartDto.getProductType() == Integer.valueOf(brushelEl)){		//判断订单中是否有刷头,有刷头 brushFlag 为true;
+						brushFlag = true;
+						brushelTotal += subTotal;
+					}
+				}
+
 			}else if(cartDto.getProductStatus().intValue() != 1){
 				msg.setMessage(ResultInfo.cartNoStatusError);
 				return msg;
 			}
-			if(cartDto.getProductType() == 100){		//当订单中有电动牙刷时,isContainProduct为true
-				isContainProduct = true;
-			}
 		}
 
 		// 准备订单对象
@@ -404,22 +429,32 @@ public class OrderHandler {
 				msg.setMessage(ResultInfo.COUPON_CONSUME_NO_ENOUGH); //消费额度不足
 				return msg;
 			}
-			if(member.getUserIdentity() != 1){  //判断该用户是否为会员
-				if(couponItem.getCouponIsNewPeople() == 1 && !isContainProduct){
+
+				/*新人卷没有其他限制*/
+			if(couponItemDto.getCouponIsNewPeople() == 1){  //当券为新人券
+				if(member.getUserIdentity() != 1 || !brushFlag){  //不为会员,或者没有牙刷刷头都无法使用
 					msg.setMessage(ResultInfo.COUPON_NO_MEMBER); //非会员需要购买电动牙刷才能使用该优惠券
 					return msg;
 				}
-			}
-			/*判断优惠券是否购买牙刷必须优惠券,与新人卷 分开*/
-			if(couponType.getCouponIsPurchase() == 1){
+			}else if(couponType.getCouponIsPurchase() == 1){/*判断优惠券是否购买牙刷必须优惠券,与新人卷 分开*/
 				if(!isContainProduct){
-					msg.setMessage(ResultInfo.COUPON_NO_TOOTH); //非会员需要购买电动牙刷才能使用该优惠
+					msg.setMessage(ResultInfo.COUPON_NO_TOOTH);  //100元现金券
 					return msg;
 				}
 			}
+			int br = 0;
 			//优惠券的类型,是直接减免额度 还是折扣价
 			if(couponType.getCouponType()==1){
-				total=total-couponType.getCouponReduce();
+				if(couponItemDto.getCouponIsNewPeople() == 1){  //当券为新人券
+					br = brushelTotal - couponType.getCouponReduce();
+					if(br <= 0){
+						total=total-brushelTotal;
+					}else{
+						total=total-couponType.getCouponReduce();
+					}
+				}else{
+					total=total-couponType.getCouponReduce();
+				}
 			}else if(couponType.getCouponType()==2){
 				Integer all =  new Integer(total);
 				total=total*couponType.getCouponReduce()/100;