zoujiajian 1 an în urmă
părinte
comite
8ca6b1365b

+ 33 - 23
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -942,7 +942,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 						.eq(GroupsRelation::getId, relation.getId())
 						.eq(GroupsRelation::getUserId, 0));
 				if (update > 0) {
-					groupsMapper.decrAvailableNum(groups.getId());
+					groupsMapper.decrAvailableNum(relation.getGroupsId());
 					return true;
 				}
 				log.error("发送用户:{} GPT镜像车票体验失败,进行重试", userId);
@@ -1346,7 +1346,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 						.eq(GroupsRelation::getId, relation.getId())
 						.eq(GroupsRelation::getUserId, 0));
 				if (update > 0) {
-					groupsMapper.decrAvailableNum(groups.getId());
+					groupsMapper.decrAvailableNum(relation.getGroupsId());
 					return relation.getId();
 				}
 				log.error("发送用户:{} GPT镜像车票体验失败,进行重试", userId);
@@ -1434,7 +1434,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 						.eq(GroupsRelation::getId, relation.getId())
 						.eq(GroupsRelation::getUserId, 0));
 				if (update > 0) {
-					groupsMapper.decrAvailableNum(groups.getId());
+					groupsMapper.decrAvailableNum(relation.getGroupsId());
 					return relation.getId();
 				}
 				log.error("发送用户:{} GPT镜像车票失败,进行重试", userId);
@@ -1582,12 +1582,14 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 						.set(NetflixUserAccountStatusRecord::getDeleted, false)
 						.eq(NetflixUserAccountStatusRecord::getId, netflixRelationView.getNfCheckId()));
 			}
+			Long ticketUserId = null;
 			//清除车票
 			GroupsRelation clearRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
 					.eq(GroupsRelation::getId, relationId)
 					.in(GroupsRelation::getUserId, userIdList)
 					.last("limit 1"));
 			if (clearRelation != null) {
+				ticketUserId = clearRelation.getUserId();
 				clearService.clearTicket(clearRelation, UserTicketClearedRecord.Source.ticket_replace);
 			}
 			OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
@@ -1597,25 +1599,29 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 					.orderByDesc(OrderDon::getId)
 					.last("limit 1"));
 			if (orderDon != null) {
-				BigDecimal orderMoney = orderDon == null ? BigDecimal.ZERO : orderDon.getMoney();
-				if (orderMoney.compareTo(BigDecimal.ZERO) > 0) {
-					//替换sku
-					GoodsDonSku replaceSku = goodsDonSkuMapper.selectById(skuId);
-					GoodsDonSku oriTicketSku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
-					//每天单价
-					BigDecimal dayPrice = oriTicketSku.getPrice().divide(BigDecimal.valueOf(oriTicketSku.getMonths() * 30), RoundingMode.DOWN);
-					//需要退款金额
-					BigDecimal refundMoney = dayPrice.multiply(BigDecimal.valueOf(betweenDay));
-					BigDecimal balance = Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO);
-					if (refundMoney.compareTo(orderMoney.add(balance)) > 0) {
-						refundMoney = orderMoney.add(balance);
-					}
-					//车票价格高于替换的规格价格 退余额
-					if (refundMoney.compareTo(replaceSku.getPrice()) > 0) {
-						BigDecimal refundBalance = refundMoney.subtract(replaceSku.getPrice());
-						if (refundBalance.compareTo(BigDecimal.ZERO) > 0) {
-							userBenefitsService.addUserBalance(clearRelation.getUserId(), refundBalance, UserBalanceSourceRecord.Source.TICKET_REPLACE, 0L, orderDon.getId(), UserBalanceSourceRecord.Source.TICKET_REPLACE.getDesc(), true);
-						}
+				if (ticketUserId == null) {
+					ticketUserId = orderDon.getUserId();
+				}
+				//替换sku
+				GoodsDonSku replaceSku = goodsDonSkuMapper.selectById(skuId);
+				GoodsDonSku oriTicketSku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
+				//每天单价
+				BigDecimal dayPrice = oriTicketSku.getPrice().divide(BigDecimal.valueOf(oriTicketSku.getMonths() * 30), RoundingMode.DOWN);
+				//需要退款金额
+				BigDecimal refundMoney = dayPrice.multiply(BigDecimal.valueOf(betweenDay));
+				BigDecimal balance = Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO);
+				BigDecimal finalOrderMoney = orderDon.getMoney().add(balance);
+				//兑换码订单
+				if (finalOrderMoney.compareTo(BigDecimal.ZERO) == 0) {
+					refundMoney = oriTicketSku.getPrice();
+				} else if (refundMoney.compareTo(finalOrderMoney) > 0) {
+					refundMoney = finalOrderMoney;
+				}
+				//车票价格高于替换的规格价格 退余额
+				if (refundMoney.compareTo(replaceSku.getPrice()) > 0) {
+					BigDecimal refundBalance = refundMoney.subtract(replaceSku.getPrice());
+					if (refundBalance.compareTo(BigDecimal.ZERO) > 0) {
+						userBenefitsService.addUserBalance(ticketUserId, refundBalance, UserBalanceSourceRecord.Source.TICKET_REPLACE, 0L, orderDon.getId(), UserBalanceSourceRecord.Source.TICKET_REPLACE.getDesc(), true);
 					}
 				}
 			}
@@ -1694,6 +1700,10 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		}
 		if (refundMoney.compareTo(orderMoney.add(balance)) > 0) {
 			refundInfoResp.setPrice(orderMoney.add(balance));
+			//兑换码订单
+			if (refundInfoResp.getPrice().compareTo(BigDecimal.ZERO) == 0) {
+				refundInfoResp.setPrice(sku.getPrice());
+			}
 		}
 		refundInfoResp.setRemainDays(betweenDay);
 		return refundInfoResp;
@@ -2062,7 +2072,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 						.eq(GroupsRelation::getId, relation.getId())
 						.eq(GroupsRelation::getUserId, 0));
 				if (update > 0) {
-					groupsMapper.decrAvailableNum(groups.getId());
+					groupsMapper.decrAvailableNum(relation.getGroupsId());
 					Long relationId = relation.getId();
 					//生成新的订单
 					OrderDon otherOrderDon = generateNewTicketOrder(relationId, userId, sku);