zoujiajian 9 ماه پیش
والد
کامیت
1c3dea4a27
1فایلهای تغییر یافته به همراه155 افزوده شده و 155 حذف شده
  1. 155 155
      netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

+ 155 - 155
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -694,7 +694,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 		if (sku != null) {
 			//扣除使用优惠券、余额的订单金额
-			deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce(), subsidyId, sku, payRequest.getGalaxyCoin());
+			deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce(), subsidyId, sku, payRequest.getGalaxyCoin(), null);
 		}
 
 		if (isSpecificPrice && (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0 || orderDon.getMoney().compareTo(specificPrice) != 0)) {
@@ -1369,11 +1369,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			BigDecimal discount = renewUpgradeIndependentPackage.getDiscount();
 			orderDon.setMoney(sku.getPrice().multiply(discount));
 		}
-		//续费价格不存在时 可使用优惠
-		if (renewPrice == null) {
-			//扣除使用优惠券、余额的订单金额
-			deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), false, null, sku, payRequest.getGalaxyCoin());
-		}
+		//扣除使用优惠券、余额的订单金额
+		deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), false, null, sku, payRequest.getGalaxyCoin(), renewPrice);
 		this.saveOrUpdate(orderDon);
 
 		Long orderId = orderDon.getId();
@@ -2703,168 +2700,170 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 	/**
 	 * 使用优惠营销 订单金额抵扣
 	 */
-	public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, GoodsDon goodsDon, BigDecimal gcCash, List<Long> gcpIds, Boolean isAcReduce, Long subsidyId, GoodsDonSku sku, BigDecimal galaxyCoin) throws Exception {
-		Integer goodsType = goodsDon.getType();
-		if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0 && couponUser != null && (balance != null && balance.compareTo(BigDecimal.ZERO) > 0)) {
-			throw BusinessRuntimeException.getInstance("现金卡不能与其他优惠叠加使用");
-		}
-		BigDecimal first_money = orderDon.getMoney();
-		//礼品卡现金支付 不参与其他优惠
-		if (subsidyId == null && gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0) {
-			List<Long> userIdList = userBindRelationService.getRelationUserIdList(user.getId(), user);
-			if (CollUtil.isEmpty(gcpIds)) {
-				throw BusinessRuntimeException.getInstance("礼品卡现金支付参数异常");
-			}
-			BigDecimal money = orderDon.getMoney();
-			if (gcCash.compareTo(money) > 0) {
-				gcCash = money;
-			}
-			List<GiftCardUserRecord> availableGiftCards = giftCardUserRecordService.list(Wrappers.lambdaQuery(GiftCardUserRecord.class)
-					.in(GiftCardUserRecord::getToUserId, userIdList)
-					.in(GiftCardUserRecord::getId, gcpIds)
-					.eq(GiftCardUserRecord::getIsPay, true)
-					.eq(GiftCardUserRecord::getGcType, 1)
-					.gt(GiftCardUserRecord::getRemainCash, 0));
-			if (availableGiftCards.size() != gcpIds.size()) {
-				throw BusinessRuntimeException.getInstance("礼品卡使用异常,请刷新页面重试");
-			}
-			//需要扣除的礼品卡现金
-			BigDecimal deductCash = gcCash;
-			List<GiftCardOrderUseRecord> gcUseRecords = new ArrayList<>();
-			for (GiftCardUserRecord giftCard : availableGiftCards) {
-				if (deductCash.compareTo(BigDecimal.ZERO) <= 0) {
-					break;
-				}
-				BigDecimal remainCash = giftCard.getRemainCash();
-				//扣完
-				if (remainCash.compareTo(deductCash) == 0) {
-					deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords, true);
-					deductCash = BigDecimal.ZERO;
-				} else if (remainCash.compareTo(deductCash) < 0) {
-					deductGiftCardCash(user.getId(), giftCard.getId(), remainCash, remainCash, gcUseRecords, true);
-					deductCash = deductCash.subtract(remainCash);
-				} else if (remainCash.compareTo(deductCash) > 0) {
-					deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords, false);
-					deductCash = BigDecimal.ZERO;
-				}
-			}
-			orderDon.setMoney(orderDon.getMoney().subtract(gcCash));
-			orderDon.setGcCash(gcCash);
-			if (!gcUseRecords.isEmpty()) {
-				orderDon.setGcUseRecords(gcUseRecords);
-			}
-			return;
-		}
-		//针对设备 满减活动优惠 不支持使用优惠券等优惠
-		if (isAcReduce != null && isAcReduce && orderDon.getGoodsId() == 15) {
-			epOrderDonActivityReduce(orderDon);
-			//存在余额
-			deductBalancePayOrderMoney(orderDon, balance, user);
-			return;
-		}
-		//存在优惠券
-		if (couponUser != null && subsidyId == null) {
-			Long couponId = couponUser.getCouponId();
-			Coupon coupon = couponMapper.getCouponById(couponId);
-			BigDecimal couponMoney = null;
-			BigDecimal payMoney = orderDon.getMoney();
-			BigDecimal needDeductMoney = payMoney;
-			if (orderDon.getOriMoney() == null) {
-				orderDon.setOriMoney(payMoney);
-			}
-			if (orderDon.getIsDp() != null && orderDon.getIsDp()) {
-				needDeductMoney = needDeductMoney.subtract(orderDon.getDpMoney());
-			}
-			if (coupon.getType() == Coupon.Type.discount) {
-				couponMoney = needDeductMoney.multiply(BigDecimal.valueOf(1).subtract(coupon.getDiscount()));
-				//需支付金额
-				orderDon.setMoney(payMoney.subtract(couponMoney));
-
-				orderDon.setOriMoney(orderDon.getOriMoney().multiply(coupon.getDiscount()));
-				//记录折扣 用于分销
-				couponUser.setDiscount(coupon.getDiscount());
-				couponUserMapper.updateById(couponUser);
-			} else if (coupon.getType() == Coupon.Type.reduce) {
-				if (goodsType == 2) {
-					if (skuMoney.compareTo(coupon.getReduceCondition()) < 0) {
-						throw BusinessRuntimeException.getInstance(String.format("满%s可用", coupon.getReduceCondition().divide(BigDecimal.valueOf(100))));
+	public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, GoodsDon goodsDon, BigDecimal gcCash, List<Long> gcpIds, Boolean isAcReduce, Long subsidyId, GoodsDonSku sku, BigDecimal galaxyCoin, BigDecimal renewPrice) throws Exception {
+		//续费规格价格 不允许其他优惠
+		if (renewPrice == null) {
+			Integer goodsType = goodsDon.getType();
+			if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0 && couponUser != null && (balance != null && balance.compareTo(BigDecimal.ZERO) > 0)) {
+				throw BusinessRuntimeException.getInstance("现金卡不能与其他优惠叠加使用");
+			}
+			BigDecimal first_money = orderDon.getMoney();
+			//礼品卡现金支付 不参与其他优惠
+			if (subsidyId == null && gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0) {
+				List<Long> userIdList = userBindRelationService.getRelationUserIdList(user.getId(), user);
+				if (CollUtil.isEmpty(gcpIds)) {
+					throw BusinessRuntimeException.getInstance("礼品卡现金支付参数异常");
+				}
+				BigDecimal money = orderDon.getMoney();
+				if (gcCash.compareTo(money) > 0) {
+					gcCash = money;
+				}
+				List<GiftCardUserRecord> availableGiftCards = giftCardUserRecordService.list(Wrappers.lambdaQuery(GiftCardUserRecord.class)
+						.in(GiftCardUserRecord::getToUserId, userIdList)
+						.in(GiftCardUserRecord::getId, gcpIds)
+						.eq(GiftCardUserRecord::getIsPay, true)
+						.eq(GiftCardUserRecord::getGcType, 1)
+						.gt(GiftCardUserRecord::getRemainCash, 0));
+				if (availableGiftCards.size() != gcpIds.size()) {
+					throw BusinessRuntimeException.getInstance("礼品卡使用异常,请刷新页面重试");
+				}
+				//需要扣除的礼品卡现金
+				BigDecimal deductCash = gcCash;
+				List<GiftCardOrderUseRecord> gcUseRecords = new ArrayList<>();
+				for (GiftCardUserRecord giftCard : availableGiftCards) {
+					if (deductCash.compareTo(BigDecimal.ZERO) <= 0) {
+						break;
+					}
+					BigDecimal remainCash = giftCard.getRemainCash();
+					//扣完
+					if (remainCash.compareTo(deductCash) == 0) {
+						deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords, true);
+						deductCash = BigDecimal.ZERO;
+					} else if (remainCash.compareTo(deductCash) < 0) {
+						deductGiftCardCash(user.getId(), giftCard.getId(), remainCash, remainCash, gcUseRecords, true);
+						deductCash = deductCash.subtract(remainCash);
+					} else if (remainCash.compareTo(deductCash) > 0) {
+						deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords, false);
+						deductCash = BigDecimal.ZERO;
 					}
 				}
-				BigDecimal subtractMoney = payMoney.subtract(coupon.getReduceMoney());
-				orderDon.setMoney(subtractMoney);
-				couponMoney = coupon.getReduceMoney();
-
-				orderDon.setOriMoney(orderDon.getOriMoney().subtract(coupon.getReduceMoney()));
+				orderDon.setMoney(orderDon.getMoney().subtract(gcCash));
+				orderDon.setGcCash(gcCash);
+				if (!gcUseRecords.isEmpty()) {
+					orderDon.setGcUseRecords(gcUseRecords);
+				}
+				return;
 			}
-			if (couponMoney != null && couponMoney.compareTo(first_money) >= 0) {
-				throw BusinessRuntimeException.getInstance("支付金额不能小于优惠金额");
+			//针对设备 满减活动优惠 不支持使用优惠券等优惠
+			if (isAcReduce != null && isAcReduce && orderDon.getGoodsId() == 15) {
+				epOrderDonActivityReduce(orderDon);
+				//存在余额
+				deductBalancePayOrderMoney(orderDon, balance, user);
+				return;
 			}
-			orderDon.setCouponMoney(couponMoney);
-			orderDon.setCouponUserId(couponUser.getId());
-			orderDon.setCouponId(couponUser.getCouponId());
-		}
-		//特殊渠道推广优惠. 360
-		if (subsidyId == null && orderDon.getPopularizeId() != null && orderDon.getPopularizeId() != 0L) {
-			String name = channelPopularizeMapper.selectChannelByPid(orderDon.getPopularizeId());
-			if (StrUtil.isNotBlank(name)) {
-				//使用了优惠券 不再使用360渠道 折扣
-				if (couponUser == null && goodsType == 1) {
-					if (name.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(0)) || name.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(1))) {
-						String key;
-						if (name.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(0))) {
-							//百度渠道 专门优惠链接
-							key = Constant.CHANNEL_BAIDU_DISCOUNT_KEY;
-						} else {
-							//抖音
-							key = Constant.CHANNEL_DY_DISCOUNT_KEY;
+			//存在优惠券
+			if (couponUser != null && subsidyId == null) {
+				Long couponId = couponUser.getCouponId();
+				Coupon coupon = couponMapper.getCouponById(couponId);
+				BigDecimal couponMoney = null;
+				BigDecimal payMoney = orderDon.getMoney();
+				BigDecimal needDeductMoney = payMoney;
+				if (orderDon.getOriMoney() == null) {
+					orderDon.setOriMoney(payMoney);
+				}
+				if (orderDon.getIsDp() != null && orderDon.getIsDp()) {
+					needDeductMoney = needDeductMoney.subtract(orderDon.getDpMoney());
+				}
+				if (coupon.getType() == Coupon.Type.discount) {
+					couponMoney = needDeductMoney.multiply(BigDecimal.valueOf(1).subtract(coupon.getDiscount()));
+					//需支付金额
+					orderDon.setMoney(payMoney.subtract(couponMoney));
+
+					orderDon.setOriMoney(orderDon.getOriMoney().multiply(coupon.getDiscount()));
+					//记录折扣 用于分销
+					couponUser.setDiscount(coupon.getDiscount());
+					couponUserMapper.updateById(couponUser);
+				} else if (coupon.getType() == Coupon.Type.reduce) {
+					if (goodsType == 2) {
+						if (skuMoney.compareTo(coupon.getReduceCondition()) < 0) {
+							throw BusinessRuntimeException.getInstance(String.format("满%s可用", coupon.getReduceCondition().divide(BigDecimal.valueOf(100))));
 						}
-						SysConfig channelNoSignConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
-								.eq(SysConfig::getSysKey, key).last("limit 1"));
-						if (channelNoSignConfig != null) {
-							String sysValue = channelNoSignConfig.getSysValue();
-							if (StrUtil.isNotBlank(sysValue)) {
-								try {
-									ChannelBaiDuDiscountDto baiDuDiscountDto = Jsons.parseObject(sysValue, ChannelBaiDuDiscountDto.class);
-									List<Long> baiduPopularizeIds = baiDuDiscountDto.getPopularizeIds();
-									BigDecimal discount = baiDuDiscountDto.getDiscount();
-									if (CollUtil.isNotEmpty(baiduPopularizeIds) && discount != null && discount.compareTo(BigDecimal.ZERO) > 0) {
-										if (baiduPopularizeIds.contains(orderDon.getPopularizeId())) {
-											BigDecimal discountMoney = orderDon.getMoney().multiply(discount);
-											orderDon.setMoney(discountMoney);
+					}
+					BigDecimal subtractMoney = payMoney.subtract(coupon.getReduceMoney());
+					orderDon.setMoney(subtractMoney);
+					couponMoney = coupon.getReduceMoney();
+
+					orderDon.setOriMoney(orderDon.getOriMoney().subtract(coupon.getReduceMoney()));
+				}
+				if (couponMoney != null && couponMoney.compareTo(first_money) >= 0) {
+					throw BusinessRuntimeException.getInstance("支付金额不能小于优惠金额");
+				}
+				orderDon.setCouponMoney(couponMoney);
+				orderDon.setCouponUserId(couponUser.getId());
+				orderDon.setCouponId(couponUser.getCouponId());
+			}
+			//特殊渠道推广优惠. 360
+			if (subsidyId == null && orderDon.getPopularizeId() != null && orderDon.getPopularizeId() != 0L) {
+				String name = channelPopularizeMapper.selectChannelByPid(orderDon.getPopularizeId());
+				if (StrUtil.isNotBlank(name)) {
+					//使用了优惠券 不再使用360渠道 折扣
+					if (couponUser == null && goodsType == 1) {
+						if (name.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(0)) || name.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(1))) {
+							String key;
+							if (name.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(0))) {
+								//百度渠道 专门优惠链接
+								key = Constant.CHANNEL_BAIDU_DISCOUNT_KEY;
+							} else {
+								//抖音
+								key = Constant.CHANNEL_DY_DISCOUNT_KEY;
+							}
+							SysConfig channelNoSignConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
+									.eq(SysConfig::getSysKey, key).last("limit 1"));
+							if (channelNoSignConfig != null) {
+								String sysValue = channelNoSignConfig.getSysValue();
+								if (StrUtil.isNotBlank(sysValue)) {
+									try {
+										ChannelBaiDuDiscountDto baiDuDiscountDto = Jsons.parseObject(sysValue, ChannelBaiDuDiscountDto.class);
+										List<Long> baiduPopularizeIds = baiDuDiscountDto.getPopularizeIds();
+										BigDecimal discount = baiDuDiscountDto.getDiscount();
+										if (CollUtil.isNotEmpty(baiduPopularizeIds) && discount != null && discount.compareTo(BigDecimal.ZERO) > 0) {
+											if (baiduPopularizeIds.contains(orderDon.getPopularizeId())) {
+												BigDecimal discountMoney = orderDon.getMoney().multiply(discount);
+												orderDon.setMoney(discountMoney);
+											}
 										}
+									} catch (Exception e) {
 									}
-								} catch (Exception e) {
 								}
 							}
-						}
-					} else {
-						SysConfig discountPopularizeConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
-								.eq(SysConfig::getSysKey, Constant.DISCOUNT_POPULARIZE_KEY).last("limit 1"));
-						if (discountPopularizeConfig != null) {
-							String sysValue = discountPopularizeConfig.getSysValue();
-							if (StrUtil.isNotBlank(sysValue)) {
-								if (user == null) {
-									throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
-								}
-								DiscountPopularizeDto discountPopularizeDto = Jsons.parseObject(sysValue, DiscountPopularizeDto.class);
-								List<Long> popularizeIds = discountPopularizeDto.getPopularizeIds();
-								if (CollUtil.isNotEmpty(popularizeIds) && popularizeIds.contains(orderDon.getPopularizeId())) {
-									List<Long> userIdList = userBindRelationService.getRelationUserIdList(user.getId(), user);
-									Integer count = orderDonUserDiscountPopularizeRecordMapper.selectUserPopularzieDiscountRecordByUidAndPid(userIdList, orderDon.getPopularizeId());
-									if (count == 0) {
-										log.info("用户:{}首次使用折扣特殊链接:{} 折扣:{},修改支付金额", user.getId(), orderDon.getPopularizeId(), discountPopularizeDto.getDiscount());
-										BigDecimal discountMoney = orderDon.getMoney().multiply(discountPopularizeDto.getDiscount());
-										orderDon.setMoney(discountMoney);
-
-										//记录用户使用折扣链接
-										orderDon.setDiscountPopularizeRecord(createPopularizeDiscountRecord(orderDon, discountPopularizeDto.getDiscount()));
+						} else {
+							SysConfig discountPopularizeConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
+									.eq(SysConfig::getSysKey, Constant.DISCOUNT_POPULARIZE_KEY).last("limit 1"));
+							if (discountPopularizeConfig != null) {
+								String sysValue = discountPopularizeConfig.getSysValue();
+								if (StrUtil.isNotBlank(sysValue)) {
+									if (user == null) {
+										throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
+									}
+									DiscountPopularizeDto discountPopularizeDto = Jsons.parseObject(sysValue, DiscountPopularizeDto.class);
+									List<Long> popularizeIds = discountPopularizeDto.getPopularizeIds();
+									if (CollUtil.isNotEmpty(popularizeIds) && popularizeIds.contains(orderDon.getPopularizeId())) {
+										List<Long> userIdList = userBindRelationService.getRelationUserIdList(user.getId(), user);
+										Integer count = orderDonUserDiscountPopularizeRecordMapper.selectUserPopularzieDiscountRecordByUidAndPid(userIdList, orderDon.getPopularizeId());
+										if (count == 0) {
+											log.info("用户:{}首次使用折扣特殊链接:{} 折扣:{},修改支付金额", user.getId(), orderDon.getPopularizeId(), discountPopularizeDto.getDiscount());
+											BigDecimal discountMoney = orderDon.getMoney().multiply(discountPopularizeDto.getDiscount());
+											orderDon.setMoney(discountMoney);
+
+											//记录用户使用折扣链接
+											orderDon.setDiscountPopularizeRecord(createPopularizeDiscountRecord(orderDon, discountPopularizeDto.getDiscount()));
+										}
 									}
 								}
 							}
 						}
-					}
-				} else {
-					//360
+					} else {
+						//360
 //					if (Constant.CHANNEL_NAME_360.equals(name)) {
 //						SysConfig sysConfig = sysConfigService.getBaseMapper().selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.CHANNEL_360_DISCOUNT));
 //						if (sysConfig != null) {
@@ -2872,6 +2871,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 //							orderDon.setMoney(discountMoney);
 //						}
 //					}
+					}
 				}
 			}
 		}