Przeglądaj źródła

fix 降级还原claude code套餐时间

zoujiajian 1 rok temu
rodzic
commit
6fd2eb0bf8

+ 15 - 1
netflix-service/src/main/java/com/cyksj/service/mange/impl/MirrorUserCleatServiceImpl.java

@@ -1,5 +1,6 @@
 package com.cyksj.service.mange.impl;
 
+import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
@@ -63,6 +64,8 @@ public class MirrorUserCleatServiceImpl implements MirrorUserCleatService {
 
 	private final ClaudeCodeService claudeCodeService;
 
+	private final OrderDonMapper orderDonMapper;
+
 	/**
 	 * 删除镜像User
 	 */
@@ -152,20 +155,31 @@ public class MirrorUserCleatServiceImpl implements MirrorUserCleatService {
 			ClaudeCodeUserRenewExpiryRecord renewExpiryRecord = claudeCodeUserRenewExpiryRecordMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUserRenewExpiryRecord.class).eq(ClaudeCodeUserRenewExpiryRecord::getOrderId, orderId).eq(ClaudeCodeUserRenewExpiryRecord::getIsValid, Boolean.FALSE).last("limit 1"));
 			Date renewExpiryTime = null;
 			Integer oriCodePoints = claudeCodeUser.getCodePoints();
+			Long renewOrderId = renewExpiryRecord.getOrderId();
 			claudeCodeUser.setOriCodePoints(oriCodePoints);
 			claudeCodeUser.setRenewSkuId(null);
 			claudeCodeUser.setRenewOrderId(null);
 			if (renewExpiryRecord != null) {
+				//当前续费
+				OrderDon presentRenewOrderDon = orderDonMapper.selectById(renewOrderId);
 				//是否存在其他续费升级
 				ClaudeCodeUserRenewExpiryRecord otherRenewRecord = claudeCodeUserRenewExpiryRecordMapper.getOtherRenewSku(orderDon.getId(), relation.getId(), userIdList);
 				GoodsDonSku otherRenewSku = null;
 				if (otherRenewRecord != null) {
 					otherRenewSku = skuMapper.selectById(otherRenewRecord.getRenewSkuId());
-					renewExpiryTime = otherRenewRecord.getExpiryTime();
 				}
 				//续费升级
 				if (otherRenewSku != null) {
 					finalSku = otherRenewSku;
+					if (otherRenewSku.getDays() != null && otherRenewSku.getDays() > 0) {
+						renewExpiryTime = DateUtil.offsetDay(DateTime.now(), otherRenewSku.getDays());
+					} else {
+						renewExpiryTime = DateUtil.offsetMonth(DateTime.now(), otherRenewSku.getMonths());
+					}
+					//相差多少天
+					Long betDay = DateUtil.betweenDay(otherRenewRecord.getCreatedTime(), presentRenewOrderDon.getCreatedTime(), false);
+					renewExpiryTime = DateUtil.offsetDay(renewExpiryTime, -betDay.intValue());
+
 					claudeCodeUser.setRenewOrderId(otherRenewRecord.getOrderId());
 					claudeCodeUser.setRenewSkuId(otherRenewRecord.getRenewSkuId());
 				}