Pārlūkot izejas kodu

Merge branch 'mail_code' into pre

# Conflicts:
#	netflix-service/src/main/java/com/cyksj/service/codex/impl/CodexServiceImpl.java
zoujiajian 1 mēnesi atpakaļ
vecāks
revīzija
c3c6752e56

+ 21 - 6
netflix-service/src/main/java/com/cyksj/service/codex/impl/CodexServiceImpl.java

@@ -418,11 +418,10 @@ public class CodexServiceImpl implements CodexService {
 					relationExpiryTime = DateUtil.offsetMonth(relationExpiryTime, -presentSku.getMonths());
 				}
 			} else {
-				// 续费天数追加在车票尾部,不能按“下单时间 + 规格天数”从购买当天开始折旧。
-				// 总到期时间覆盖完整续费周期时,该笔续费应按完整价值抵扣;只有进入该周期后才按剩余天数折算。
 				long skuDays = presentSku.getDays() != null ? presentSku.getDays() : presentSku.getMonths() * 30L;
-				long relationRemainDays = DateUtil.betweenDay(now, relationExpiryTime, false) + 1;
-				long renewRemainDays = Math.min(skuDays, relationRemainDays);
+				// renewSkuId 存在即为续费升级:升级套餐立即优先使用,原套餐剩余时间暂停。
+				// 只按续费升级自身的 renewExpiryTime 计算剩余价值。
+				long renewRemainDays = Math.max(0L, Math.min(skuDays, DateUtil.betweenDay(now, renewExpiryTime, false)));
 				//此次续费规格单价
 				BigDecimal single = getPayOrderSingle(orderMoney, presentSku);
 				//该车票抵扣金额
@@ -830,14 +829,30 @@ 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());
 		Date deductStartTime = DateUtil.offsetMonth(now, -deductMonth);
 		Date cutoffTime = deductStartTime;
 		if (oriOrderDon != null) {
-			cutoffTime = DateUtil.compare(oriOrderDon.getCreatedTime(), deductStartTime) > 0 ? oriOrderDon.getCreatedTime() : deductStartTime;
+			// 原套餐可能在续费升级期间暂停,订单虽早但剩余价值仍有效。
+			cutoffTime = oriOrderDon.getCreatedTime();
 			queryWrapper.ge(OrderDon::getCreatedTime, cutoffTime);
 		} else {
 			queryWrapper.ge(OrderDon::getCreatedTime, deductStartTime);

+ 1 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsAccountController.java

@@ -183,6 +183,7 @@ public class CmsAccountController {
             goods = "Disney";
         }
         credential.put("goods", goods);
+        credential.put("relateEmail", netflixAccount.getRelateEmail());
         return GatewayResponse.SUCCESS.newBuilder().toResult(credential);
     }