|
@@ -2,6 +2,7 @@ package com.cyksj.service.claude.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.http.Method;
|
|
import cn.hutool.http.Method;
|
|
@@ -9,7 +10,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
|
|
+import com.cyksj.mapper.ClaudeCodeUserRenewExpiryRecordMapper;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
|
|
+import com.cyksj.model.entity.ClaudeCodeUserRenewExpiryRecord;
|
|
|
import com.cyksj.model.entity.GoodsDonSku;
|
|
import com.cyksj.model.entity.GoodsDonSku;
|
|
|
import com.cyksj.model.entity.GroupsRelation;
|
|
import com.cyksj.model.entity.GroupsRelation;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
@@ -50,26 +53,37 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
|
|
private final BeanSearcher beanSearcher;
|
|
private final BeanSearcher beanSearcher;
|
|
|
|
|
|
|
|
|
|
+ private final ClaudeCodeUserRenewExpiryRecordMapper claudeCodeUserRenewExpiryRecordMapper;
|
|
|
|
|
+
|
|
|
private final static String CLAUDE_CODE_API_PREFIX = "https://relay01.yhlxj.com/";
|
|
private final static String CLAUDE_CODE_API_PREFIX = "https://relay01.yhlxj.com/";
|
|
|
|
|
|
|
|
public static final String CLAUDE_CODE_API_ADMIN_KEY = "claudecodeyhlxjclaude";
|
|
public static final String CLAUDE_CODE_API_ADMIN_KEY = "claudecodeyhlxjclaude";
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void generateOrUpdateClaudeCodeUserInfo(Long relationId, Long userId, GoodsDonSku sku, Integer orderType) {
|
|
|
|
|
|
|
+ public void generateOrUpdateClaudeCodeUserInfo(Long orderId, Long relationId, Long userId, GoodsDonSku sku, Integer orderType) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getId, relationId).in(GroupsRelation::getUserId, userIdList));
|
|
GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getId, relationId).in(GroupsRelation::getUserId, userIdList));
|
|
|
|
|
+ Long relationUserId = relation.getUserId();
|
|
|
|
|
+ Integer relationCodePoints = relation.getCodePoints();
|
|
|
|
|
+ Long relationCodeSkuId = relation.getCodeSkuId();
|
|
|
Date expiryTime = relation.getExpiryTime();
|
|
Date expiryTime = relation.getExpiryTime();
|
|
|
Integer codePoints = sku.getCodePoints();
|
|
Integer codePoints = sku.getCodePoints();
|
|
|
Integer codeCreditRecovery = sku.getCodeCreditRecovery();
|
|
Integer codeCreditRecovery = sku.getCodeCreditRecovery();
|
|
|
|
|
+ Long skuId = sku.getId();
|
|
|
//生成claude code用户套餐
|
|
//生成claude code用户套餐
|
|
|
try {
|
|
try {
|
|
|
createOrUpdateClaudeCodeUserPackage(relation.getUserId(), sku.getSpecVal(), codePoints, codeCreditRecovery, expiryTime);
|
|
createOrUpdateClaudeCodeUserPackage(relation.getUserId(), sku.getSpecVal(), codePoints, codeCreditRecovery, expiryTime);
|
|
|
//设置车位的套餐
|
|
//设置车位的套餐
|
|
|
relation.setCodePoints(codePoints);
|
|
relation.setCodePoints(codePoints);
|
|
|
relation.setCodeCreditRecovery(codeCreditRecovery);
|
|
relation.setCodeCreditRecovery(codeCreditRecovery);
|
|
|
|
|
+ relation.setCodeSkuId(skuId);
|
|
|
relationMapper.updateById(relation);
|
|
relationMapper.updateById(relation);
|
|
|
if (orderType == 2) {
|
|
if (orderType == 2) {
|
|
|
- invalidateUserCache(userId);
|
|
|
|
|
|
|
+ invalidateUserCache(relationUserId);
|
|
|
|
|
+ //若是续费升级 记录此时续费升级的过期时间
|
|
|
|
|
+ if (relationCodePoints != null && relationCodePoints <= codePoints && !ObjectUtil.equal(relationCodeSkuId, skuId)) {
|
|
|
|
|
+ saveClaudeCodeRenewExpiryRecord(orderId, relationUserId, relationId, expiryTime, skuId);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
@@ -324,4 +338,18 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
.execute();
|
|
.execute();
|
|
|
return execute.body();
|
|
return execute.body();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 记录claude code 续费升级的过期时间
|
|
|
|
|
+ */
|
|
|
|
|
+ private void saveClaudeCodeRenewExpiryRecord(Long orderId, Long relationUserId, Long relationId, Date expiryTime, Long skuId) {
|
|
|
|
|
+ ClaudeCodeUserRenewExpiryRecord renewExpiryRecord = new ClaudeCodeUserRenewExpiryRecord();
|
|
|
|
|
+ renewExpiryRecord.setOrderId(orderId);
|
|
|
|
|
+ renewExpiryRecord.setUserId(relationUserId);
|
|
|
|
|
+ renewExpiryRecord.setRelationId(relationId);
|
|
|
|
|
+ renewExpiryRecord.setRenewSkuId(skuId);
|
|
|
|
|
+ renewExpiryRecord.setExpiryTime(expiryTime);
|
|
|
|
|
+ claudeCodeUserRenewExpiryRecordMapper.insert(renewExpiryRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|