Parcourir la source

fix codex 抵扣升级订单作为新初始订单

zoujiajian il y a 1 mois
Parent
commit
a2a0e1cac0

+ 16 - 1
netflix-service/src/main/java/com/cyksj/service/codex/impl/CodexServiceImpl.java

@@ -829,7 +829,22 @@ public class CodexServiceImpl implements CodexService {
 	 * 获取车票可抵扣金额
 	 */
 	public BigDecimal getDeductMoneyFromTicket(Long relationId, List<Long> userIdList, Long skuId, DateTime now, Date relationStartTime, Date relationExpiryTime) {
-		OrderDon oriOrderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getRelationId, relationId).in(OrderDon::getUserId, userIdList).notIn(OrderDon::getStatus, Constant.noOrderAllStatus).eq(OrderDon::getOrderType, 1).orderByDesc(OrderDon::getId).last("limit 1"));
+		// 抵扣升级成功后,新订单已经承接旧车票的剩余价值,作为新的初始订单。
+		// 后续只计算该订单及之后的普通续费,避免再次累计抵扣升级前的旧订单。
+		OrderDon oriOrderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+				.eq(OrderDon::getRelationId, relationId)
+				.in(OrderDon::getUserId, userIdList)
+				.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+				.apply("exists (select 1 from codex_deduct_record d where d.order_id = order_don.id and d.status = 1)")
+				.orderByDesc(OrderDon::getId).last("limit 1"));
+		if (oriOrderDon == null) {
+			oriOrderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+					.eq(OrderDon::getRelationId, relationId)
+					.in(OrderDon::getUserId, userIdList)
+					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+					.eq(OrderDon::getOrderType, 1)
+					.orderByDesc(OrderDon::getId).last("limit 1"));
+		}
 		LambdaQueryWrapper<OrderDon> queryWrapper = Wrappers.lambdaQuery(OrderDon.class);
 		Long remainDays = DateUtil.betweenDay(now, relationExpiryTime, false) + 1;
 		int deductMonth = Math.max(1, BigDecimal.valueOf(remainDays).divide(BigDecimal.valueOf(30), 0, RoundingMode.UP).intValue());