Просмотр исходного кода

奈飞车票价格高于替换的规格价格 退余额

zoujiajian 1 год назад
Родитель
Сommit
d524b2ba83

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/GroupsMapper.java

@@ -40,7 +40,7 @@ public interface GroupsMapper extends BaseMapper<GroupsTrips> {
 
 	Integer countExpiredNum(Long accountId);
 
-	GroupsTrips selectTicketGroups(@Param("skuId") Long skuId, @Param("status") GroupsTrips.Status status, @Param("maxNum") Integer maxNum, @Param("ip") String ip);
+	GroupsTrips selectTicketGroups(@Param("skuId") Long skuId, @Param("status") GroupsTrips.Status status, @Param("maxNum") Integer maxNum, @Param("ip") String ip, @Param("filterAccountTime") DateTime filterAccountTime);
 
 	GroupsTrips selectCollegeStudentUserGptTicket(Long skuId);
 

+ 1 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/UserBalanceSourceRecord.java

@@ -46,6 +46,7 @@ public class UserBalanceSourceRecord extends BaseEntity {
 		wholesale_order("批发订单"),
 		vip_order("会员下单"),
 		vip_refund("会员退款"),
+		TICKET_REPLACE("车票替换")
 		;
 		String desc;
 

+ 3 - 0
netflix-dao/src/main/resources/mapper/GroupsMapper.xml

@@ -95,6 +95,9 @@
         from groups_relation gr
         where gr.groups_id = gt.id
         and gr.user_id != 0 and gr.num &lt;= #{maxNum}))
+        <if test="filterAccountTime!=null">
+            and gt.created_time > #{filterAccountTime}
+        </if>
         order by available_num asc
         limit 1
     </select>

+ 48 - 8
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -57,6 +57,7 @@ import com.cyksj.service.relation.GroupRelationClearService;
 import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.relation.GroupsRelationChangeService;
 import com.cyksj.service.relation.GroupsRelationNetflixService;
+import com.cyksj.service.user.UserBenefitsService;
 import com.cyksj.service.user.UserBindRelationService;
 import com.cyksj.service.user.UserLoginRecordService;
 import com.ejlchina.searcher.BeanSearcher;
@@ -199,6 +200,8 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 
 	private final GroupRelationClearService clearService;
 
+	private final UserBenefitsService userBenefitsService;
+
 	@Override
 	public SearchResult<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize, String customId, String account, String orderNo, Integer cmt) {
 		User u = userMapper.selectById(userId);
@@ -584,11 +587,16 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 				relation = getSimilarExpiredGroupRelation(sku, null, ip);
 				if (relation == null) {
 					//TODO 如果没指定座位,等待逻辑确认
-					groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.validity, maxNum, ip);
+					DateTime filterAccountTime = null;
+					//奈飞过滤6月23号之前的车队
+					if (sku.getGoodsId() == Constant.NETFLIX_GID) {
+						filterAccountTime = DateUtil.parse("2025-06-23");
+					}
+					groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.validity, maxNum, ip, filterAccountTime);
 
 					if (groups == null) {
 						//待发车
-						groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.waiting, maxNum, ip);
+						groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.waiting, maxNum, ip, null);
 					}
 					//新增空车队
 					if (groups == null) {
@@ -934,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);
@@ -1338,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);
@@ -1426,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);
@@ -1574,14 +1582,46 @@ 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)
+					.eq(OrderDon::getRelationId, relationId)
+					.in(OrderDon::getUserId, userIdList)
+					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+					.orderByDesc(OrderDon::getId)
+					.last("limit 1"));
+			if (orderDon != null) {
+				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 (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);
+					}
+				}
+			}
 		} finally {
 			redisService.del(key);
 		}
@@ -1612,7 +1652,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		}
 		List<GoodsCategorySkuView> goodsCategorySkuViews = beanSearcher.searchAll(GoodsCategorySkuView.class, MapUtils.builder()
 				.field(GoodsCategorySkuView::getSkuId, errorNetflixChangeOtherSkuTicketDto.getSkuIds()).op(Operator.InList)
-				.orderBy(GoodsCategorySkuView::getPrice)
+				.orderBy(GoodsCategorySkuView::getPrice).desc()
 				.build());
 		return goodsCategorySkuViews;
 	}
@@ -1650,7 +1690,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		//需要退款金额
 		BigDecimal refundMoney = dayPrice.multiply(BigDecimal.valueOf(betweenDay));
 		refundInfoResp.setPrice(refundMoney);
-		BigDecimal balance = Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO);
+		BigDecimal balance = orderDon == null ? BigDecimal.ZERO : Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO);
 		//超过本身订单金额 不允许退款
 		if (refundMoney.compareTo(orderMoney) > 0) {
 			refundInfoResp.setIsRefund(false);
@@ -2025,7 +2065,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);