|
|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.claude.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
@@ -13,6 +14,7 @@ import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.ClaudeCodeUserMapper;
|
|
|
import com.cyksj.mapper.ClaudeCodeUserRenewExpiryRecordMapper;
|
|
|
+import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
import com.cyksj.model.entity.ClaudeCodeUser;
|
|
|
import com.cyksj.model.entity.ClaudeCodeUserRenewExpiryRecord;
|
|
|
@@ -27,7 +29,6 @@ import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserApiKeysView;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserInfoView;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserPackageView;
|
|
|
-import com.cyksj.model.views.RenewalView;
|
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -63,6 +64,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
private final ClaudeCodeUserMapper claudeCodeUserMapper;
|
|
|
|
|
|
+ private final GoodsDonSkuMapper skuMapper;
|
|
|
+
|
|
|
private final static String CLAUDE_CODE_API_PREFIX = "https://relay01.yhlxj.com/";
|
|
|
|
|
|
public static final String CLAUDE_CODE_API_ADMIN_KEY = "claudecodeyhlxjclaude";
|
|
|
@@ -81,9 +84,15 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
//生成claude code用户套餐
|
|
|
try {
|
|
|
Boolean isUpgrade = false;
|
|
|
+ Date renewExpiryTime = null;
|
|
|
//若是续费升级 记录此时续费升级的过期时间
|
|
|
if (relationCodePoints != null && relationCodePoints <= codePoints && !ObjectUtil.equal(relationCodeSkuId, skuId)) {
|
|
|
saveClaudeCodeRenewExpiryRecord(orderId, relationUserId, relationId, expiryTime, skuId);
|
|
|
+ if (sku.getDays() != null) {
|
|
|
+ renewExpiryTime = DateUtil.offsetDay(DateTime.now(), sku.getDays());
|
|
|
+ }else {
|
|
|
+ renewExpiryTime = DateUtil.offsetMonth(DateTime.now(), sku.getMonths());
|
|
|
+ }
|
|
|
isUpgrade = true;
|
|
|
}
|
|
|
ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(relation.getUserId(), sku.getSpecVal(), codePoints, codeCreditRecovery, expiryTime);
|
|
|
@@ -96,14 +105,14 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
if (orderType == 2) {
|
|
|
invalidateUserCache(relationUserId);
|
|
|
}
|
|
|
- generateOrUpdateClaudeCodeUser(relationUserId, relationId, codePoints, codeCreditRecovery, expiryTime, isUpgrade, skuId);
|
|
|
+ generateOrUpdateClaudeCodeUser(relationUserId, relationId, codePoints, codeCreditRecovery, expiryTime, isUpgrade, skuId, renewExpiryTime);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("生成或更新claude code用户:{}套餐skuId:{} 失败,error_info:{}", userId, skuId, StringUtil.getErrorText(e));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void generateOrUpdateClaudeCodeUser(Long relationUserId, Long relationId, Integer codePoints, Integer codeCreditRecovery, Date expiryTime, Boolean isUpgrade, Long renewSkuId) {
|
|
|
+ private void generateOrUpdateClaudeCodeUser(Long relationUserId, Long relationId, Integer codePoints, Integer codeCreditRecovery, Date expiryTime, Boolean isUpgrade, Long renewSkuId, Date renewExpiryTime) {
|
|
|
ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
if (claudeCodeUser == null) {
|
|
|
claudeCodeUser = new ClaudeCodeUser();
|
|
|
@@ -115,7 +124,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
if (isUpgrade) {
|
|
|
claudeCodeUser.setRenewSkuId(renewSkuId);
|
|
|
- claudeCodeUser.setRenewExpiryTime(expiryTime);
|
|
|
+ claudeCodeUser.setRenewExpiryTime(renewExpiryTime);
|
|
|
}
|
|
|
if (claudeCodeUser.getId() == null) {
|
|
|
try {
|
|
|
@@ -307,6 +316,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
if (groupsRelationView == null) {
|
|
|
return null;
|
|
|
}
|
|
|
+ String specVal = groupsRelationView.getSpecVal();
|
|
|
ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList).last("limit 1"));
|
|
|
if (claudeCodeUser == null) {
|
|
|
if (groupsRelationView != null) {
|
|
|
@@ -326,11 +336,28 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
if (codePoints < relationViewCodePoints) {
|
|
|
claudeCodeUser.setCodePoints(relationViewCodePoints);
|
|
|
claudeCodeUser.setCodeCreditRecovery(groupsRelationView.getCodeCreditRecovery());
|
|
|
- claudeCodeUser.setRenewExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
- claudeCodeUser.setRenewSkuId(groupsRelationView.getSkuId());
|
|
|
+ claudeCodeUser.setRenewSkuId(groupsRelationView.getCodeSkuId());
|
|
|
+ claudeCodeUser.setRenewExpiryTime(groupsRelationView.getCodeRenewExpiryTime());
|
|
|
+ //更新缓存
|
|
|
+ invalidateUserCache(claudeCodeUser.getRelationId());
|
|
|
}
|
|
|
claudeCodeUser.setExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
}
|
|
|
+ if (claudeCodeUser.getRenewSkuId() != null) {
|
|
|
+ GoodsDonSku renewSku = skuMapper.selectById(claudeCodeUser.getRenewSkuId());
|
|
|
+ if (renewSku != null) {
|
|
|
+ specVal = renewSku.getSpecVal();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ClaudeCodeUserInfoView.builder()
|
|
|
+ .planName(specVal)
|
|
|
+ .relationId(claudeCodeUser.getRelationId())
|
|
|
+ .codePoints(claudeCodeUser.getCodePoints())
|
|
|
+ .codeCreditRecovery(claudeCodeUser.getCodeCreditRecovery())
|
|
|
+ .expiryTime(claudeCodeUser.getExpiryTime())
|
|
|
+ .renewSkuId(claudeCodeUser.getRenewSkuId())
|
|
|
+ .renewExpiryTime(claudeCodeUser.getRenewExpiryTime())
|
|
|
+ .build();
|
|
|
}
|
|
|
|
|
|
public ClaudeCodeResp createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer codePoints, Integer codeCreditRecovery, Date expiryTime) throws Exception {
|