|
|
@@ -112,14 +112,14 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
Long thisCodeOriSkuId = relationSku.getId();
|
|
|
Long relationUserId = relation.getUserId();
|
|
|
//此时车票的套餐规格积分
|
|
|
- Integer thisRelationCodePoints = null;
|
|
|
+ Integer thisRelationCodeDayilyLimit = null;
|
|
|
ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
if (claudeCodeUser != null) {
|
|
|
- thisRelationCodePoints = claudeCodeUser.getCodePoints();
|
|
|
+ thisRelationCodeDayilyLimit = claudeCodeUser.getClaudeDailyLimit();
|
|
|
}
|
|
|
Date expiryTime = relation.getExpiryTime();
|
|
|
- Integer codePoints = sku.getCodePoints();
|
|
|
- Integer codeCreditRecovery = sku.getCodeCreditRecovery();
|
|
|
+ Integer claudeDailyLimit = sku.getClaudeDailyLimit();
|
|
|
+ Integer claudeQuota = sku.getClaudeQuota();
|
|
|
Long skuId = sku.getId();
|
|
|
Boolean isUpgrade = false;
|
|
|
Date renewExpiryTime = null;
|
|
|
@@ -128,7 +128,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
//非车票原规格id 续费升级记录
|
|
|
saveClaudeCodeRenewExpiryRecord(orderId, relationUserId, relationId, skuId);
|
|
|
//是否需要修改当前claude code user 套餐等级
|
|
|
- if (thisRelationCodePoints != null && thisRelationCodePoints <= codePoints) {
|
|
|
+ if (thisRelationCodeDayilyLimit != null && thisRelationCodeDayilyLimit <= claudeDailyLimit) {
|
|
|
if (sku.getDays() != null) {
|
|
|
renewExpiryTime = DateUtil.offsetDay(DateTime.now(), sku.getDays());
|
|
|
} else {
|
|
|
@@ -137,12 +137,12 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
isUpgrade = true;
|
|
|
}
|
|
|
}
|
|
|
- generateOrUpdateClaudeCodeUser(relationUserId, relationId, codePoints, codeCreditRecovery, expiryTime, isUpgrade, orderId, skuId, renewExpiryTime, sku.getSpecVal(), userIdList);
|
|
|
+ generateOrUpdateClaudeCodeUser(relationUserId, relationId, claudeDailyLimit, claudeQuota, expiryTime, isUpgrade, orderId, skuId, renewExpiryTime, sku.getSpecVal(), userIdList);
|
|
|
try {
|
|
|
//获取最新的claude code user
|
|
|
claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
//生成claude code或更新用户套餐
|
|
|
- ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(relation.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), claudeCodeUser.getExpiryTime(), claudeCodeUser.getRelationId(), sku);
|
|
|
+ ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(relation.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getClaudeDailyLimit(), claudeCodeUser.getClaudeQuota(), claudeCodeUser.getExpiryTime(), claudeCodeUser.getRelationId(), sku);
|
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
|
//重试更新code userInfo数据
|
|
|
setClaudeCodeUserRetryUpdateInfo(relationId);
|
|
|
@@ -159,7 +159,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void generateOrUpdateClaudeCodeUser(Long relationUserId, Long relationId, Integer codePoints, Integer codeCreditRecovery, Date expiryTime, Boolean isUpgrade, Long orderId, Long renewSkuId, Date renewExpiryTime, String planName, List<Long> userIdList) {
|
|
|
+ private void generateOrUpdateClaudeCodeUser(Long relationUserId, Long relationId, Integer claudeDailyLimit, Integer claudeQuota, Date expiryTime, Boolean isUpgrade, Long orderId, Long renewSkuId, Date renewExpiryTime, String planName, List<Long> userIdList) {
|
|
|
ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
if (claudeCodeUser == null) {
|
|
|
claudeCodeUser = new ClaudeCodeUser();
|
|
|
@@ -169,16 +169,16 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
claudeCodeUser.setRenewSkuId(renewSkuId);
|
|
|
claudeCodeUser.setRenewExpiryTime(renewExpiryTime);
|
|
|
claudeCodeUser.setPlanName(planName);
|
|
|
- claudeCodeUser.setCodePoints(codePoints);
|
|
|
- claudeCodeUser.setCodeCreditRecovery(codeCreditRecovery);
|
|
|
+ claudeCodeUser.setClaudeDailyLimit(claudeDailyLimit);
|
|
|
+ claudeCodeUser.setClaudeQuota(claudeQuota);
|
|
|
}
|
|
|
claudeCodeUser.setUserId(relationUserId);
|
|
|
claudeCodeUser.setRelationId(relationId);
|
|
|
claudeCodeUser.setExpiryTime(expiryTime);
|
|
|
if (claudeCodeUser.getId() == null) {
|
|
|
claudeCodeUser.setPlanName(planName);
|
|
|
- claudeCodeUser.setCodePoints(codePoints);
|
|
|
- claudeCodeUser.setCodeCreditRecovery(codeCreditRecovery);
|
|
|
+ claudeCodeUser.setClaudeDailyLimit(claudeDailyLimit);
|
|
|
+ claudeCodeUser.setClaudeQuota(claudeQuota);
|
|
|
//可重置次数
|
|
|
Integer resetCount = claudeCodeUserResetRecordMapper.getUserResetCountByUserIds(userIdList);
|
|
|
if (resetCount != null && resetCount > 0) {
|
|
|
@@ -365,7 +365,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
//是否需要重试更新 cladueCode userInfo信息
|
|
|
if (claudeCodeUser.getIsRetry()) {
|
|
|
try {
|
|
|
- ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), claudeCodeUser.getExpiryTime(), claudeCodeUser.getRelationId(), sku);
|
|
|
+ ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getClaudeDailyLimit(), claudeCodeUser.getClaudeQuota(), claudeCodeUser.getExpiryTime(), claudeCodeUser.getRelationId(), sku);
|
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
|
claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
|
@@ -399,8 +399,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
return ClaudeCodeUserInfoView.builder()
|
|
|
.planName(claudeCodeUser.getPlanName())
|
|
|
.relationId(claudeCodeUser.getRelationId())
|
|
|
- .codePoints(claudeCodeUser.getCodePoints())
|
|
|
- .codeCreditRecovery(claudeCodeUser.getCodeCreditRecovery())
|
|
|
+ .claudeDailyLimit(claudeCodeUser.getClaudeDailyLimit())
|
|
|
+ .claudeQuota(claudeCodeUser.getClaudeQuota())
|
|
|
.expiryTime(claudeCodeUser.getExpiryTime())
|
|
|
.renewSkuId(claudeCodeUser.getRenewSkuId())
|
|
|
.renewOrderId(claudeCodeUser.getRenewOrderId())
|
|
|
@@ -410,11 +410,11 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
- public ClaudeCodeResp createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer codePoints, Integer codeCreditRecovery, Date expiryTime, Long relationId, GoodsDonSku sku) throws Exception {
|
|
|
+ public ClaudeCodeResp createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer claudeDailyLimit, Integer claudeQuota, Date expiryTime, Long relationId, GoodsDonSku sku) throws Exception {
|
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
|
parmas.put("plan_name", planName.replaceAll(";", ""));
|
|
|
- parmas.put("credit_limit", codePoints);
|
|
|
- parmas.put("credit_recovery", codeCreditRecovery);
|
|
|
+ parmas.put("claude_daily_limit", claudeDailyLimit);
|
|
|
+ parmas.put("claude_quota", claudeQuota);
|
|
|
if (sku.getIsCodex()) {
|
|
|
parmas.put("openai_daily_limit", sku.getOpenaiDailyLimit());
|
|
|
parmas.put("openai_quota", sku.getOpenaiQuota());
|
|
|
@@ -461,7 +461,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
@Override
|
|
|
public void updateClaudeCodeUserPackageInfo(ClaudeCodeUser claudeCodeUser, Date expiryTime, GoodsDonSku sku) {
|
|
|
try {
|
|
|
- ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), expiryTime, claudeCodeUser.getRelationId(), sku);
|
|
|
+ ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getClaudeDailyLimit(), claudeCodeUser.getClaudeQuota(), expiryTime, claudeCodeUser.getRelationId(), sku);
|
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
|
//重试标记
|
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
|
@@ -677,36 +677,6 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
.withStopStrategy(StopStrategies.stopAfterAttempt(attemptNum)).build();
|
|
|
return build;
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public void resetUserCodePoints(Long userId, Integer resetType, String resetReason) {
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(
|
|
|
- Wrappers.<ClaudeCodeUser>lambdaQuery().in(ClaudeCodeUser::getUserId, userIdList)
|
|
|
- );
|
|
|
-
|
|
|
- if (claudeCodeUser == null) {
|
|
|
- throw new BusinessRuntimeException("用户不存在或未开通Claude Code服务");
|
|
|
- }
|
|
|
-
|
|
|
- Integer beforeCodePoints = claudeCodeUser.getCodePoints();
|
|
|
- Integer afterCodePoints = claudeCodeUser.getOriCodePoints();
|
|
|
-
|
|
|
- claudeCodeUser.setCodePoints(afterCodePoints);
|
|
|
- claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
|
-
|
|
|
- ClaudeCodeUserResetRecord resetRecord = new ClaudeCodeUserResetRecord();
|
|
|
- resetRecord.setUserId(userId);
|
|
|
- resetRecord.setBeforeCodePoints(beforeCodePoints);
|
|
|
- resetRecord.setAfterCodePoints(afterCodePoints);
|
|
|
- resetRecord.setResetType(resetType);
|
|
|
- resetRecord.setResetReason(resetReason);
|
|
|
-
|
|
|
- claudeCodeUserResetRecordMapper.insert(resetRecord);
|
|
|
-
|
|
|
- log.info("用户{}的积分已重置", userId);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
public void useResetCount(Long userId) throws Exception {
|
|
|
@@ -777,16 +747,16 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
);
|
|
|
|
|
|
if (creditCard == null) {
|
|
|
- throw new BusinessRuntimeException("无可用积分卡");
|
|
|
+ throw new BusinessRuntimeException("无可用补充卡");
|
|
|
}
|
|
|
|
|
|
if (creditCard.getStatus() != 0) {
|
|
|
if (creditCard.getStatus() == 1) {
|
|
|
- throw new BusinessRuntimeException("积分卡已被使用");
|
|
|
+ throw new BusinessRuntimeException("补充卡已被使用");
|
|
|
} else if (creditCard.getStatus() == 2) {
|
|
|
- throw new BusinessRuntimeException("积分卡已过期");
|
|
|
+ throw new BusinessRuntimeException("补充卡已过期");
|
|
|
} else {
|
|
|
- throw new BusinessRuntimeException("积分卡状态异常");
|
|
|
+ throw new BusinessRuntimeException("补充卡状态异常");
|
|
|
}
|
|
|
}
|
|
|
String cardNumber = creditCard.getCardNumber();
|
|
|
@@ -794,7 +764,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
if (creditCard.getExpiryTime() != null && creditCard.getExpiryTime().before(new Date())) {
|
|
|
creditCard.setStatus(2);
|
|
|
claudeCodeCreditCardMapper.updateById(creditCard);
|
|
|
- throw new BusinessRuntimeException("积分卡已过期");
|
|
|
+ throw new BusinessRuntimeException("补充卡已过期");
|
|
|
}
|
|
|
|
|
|
ClaudeCodeResp userBalance = getUserBalance(userId);
|
|
|
@@ -828,15 +798,15 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
creditCardRecord.setCardNumber(cardNumber);
|
|
|
//使用一次
|
|
|
creditCardRecord.setNum(-1);
|
|
|
- creditCardRecord.setUseReason("使用积分卡");
|
|
|
+ creditCardRecord.setUseReason("使用补充卡");
|
|
|
|
|
|
claudeCodeUserCreditCardRecordMapper.insert(creditCardRecord);
|
|
|
|
|
|
- log.info("用户{}成功使用积分卡{},增加{}积分", userId, cardNumber, addCodePoints);
|
|
|
+ log.info("用户{}成功使用补充卡{},增加{}预算", userId, cardNumber, addCodePoints);
|
|
|
//调用API调整用户积分
|
|
|
- adjClaudeCodeUserPoints(claudeCodeUser.getUserId(), creditCard.getCreditAmount(), "adjustment", "用户使用积分卡");
|
|
|
+ adjClaudeCodeUserPoints(claudeCodeUser.getUserId(), creditCard.getCreditAmount(), "adjustment", "用户使用补充卡");
|
|
|
} else {
|
|
|
- throw new BusinessRuntimeException("积分卡使用失败,请重试");
|
|
|
+ throw new BusinessRuntimeException("补充卡使用失败,请重试");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -883,7 +853,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
response.setResetCount(0);
|
|
|
}
|
|
|
|
|
|
- // 获取可用积分卡数量
|
|
|
+ // 获取可用补充卡数量
|
|
|
Integer availableCreditCards = claudeCodeCreditCardMapper.selectCount(
|
|
|
Wrappers.lambdaQuery(ClaudeCodeCreditCard.class)
|
|
|
.eq(ClaudeCodeCreditCard::getStatus, 0)
|
|
|
@@ -891,11 +861,6 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
.isNull(ClaudeCodeCreditCard::getUsedUserId)
|
|
|
);
|
|
|
response.setAvailableCreditCards(availableCreditCards != null ? availableCreditCards : 0);
|
|
|
- if (claudeCodeUser.getCodePoints() > 5000) {
|
|
|
- Integer selectCount = claudeCodeDayResetRecordMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeDayResetRecord.class).in(ClaudeCodeDayResetRecord::getUserId, userIdList).gt(ClaudeCodeDayResetRecord::getCreatedTime, DateUtil.beginOfDay(DateTime.now())));
|
|
|
- //每日可用重置次数
|
|
|
- response.setDayRestNum(selectCount > 0 ? 0 : 1);
|
|
|
- }
|
|
|
|
|
|
//是否是普通推广
|
|
|
if (general != null && general) {
|
|
|
@@ -955,7 +920,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
creditCard.setRemark(remark);
|
|
|
claudeCodeCreditCardMapper.insert(creditCard);
|
|
|
|
|
|
- //积分卡明细
|
|
|
+ //补充卡明细
|
|
|
ClaudeCodeUserCreditCardRecord creditCardRecord = new ClaudeCodeUserCreditCardRecord();
|
|
|
creditCardRecord.setUserId(userId);
|
|
|
creditCardRecord.setCardNumber(cardNumber);
|
|
|
@@ -1027,7 +992,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
return;
|
|
|
}
|
|
|
//非标准版、专业版 不给使用
|
|
|
- if (claudeCodeUser.getCodePoints() < 5000) {
|
|
|
+ if (claudeCodeUser.getClaudeDailyLimit() < 5000) {
|
|
|
return;
|
|
|
}
|
|
|
Integer selectCount = claudeCodeDayResetRecordMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeDayResetRecord.class).in(ClaudeCodeDayResetRecord::getUserId, userIdList).gt(ClaudeCodeDayResetRecord::getCreatedTime, DateUtil.beginOfDay(DateTime.now())));
|
|
|
@@ -1087,7 +1052,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
parmas.put("description", description);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodePostApi(apiKeyUrl, Jsons.toJson(parmas));
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
|
- throw BusinessRuntimeException.getInstance("使用积分卡失败");
|
|
|
+ throw BusinessRuntimeException.getInstance("使用补充卡失败");
|
|
|
}
|
|
|
}
|
|
|
}
|