|
@@ -14,22 +14,20 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.*;
|
|
import com.cyksj.mapper.*;
|
|
|
-import com.cyksj.mapper.claudecode.ClaudeCodeUserResetRecordMapper;
|
|
|
|
|
-import com.cyksj.mapper.claudecode.ClaudeCodeUserCreditCardRecordMapper;
|
|
|
|
|
import com.cyksj.mapper.claudecode.ClaudeCodeCreditCardMapper;
|
|
import com.cyksj.mapper.claudecode.ClaudeCodeCreditCardMapper;
|
|
|
|
|
+import com.cyksj.mapper.claudecode.ClaudeCodeUserCreditCardRecordMapper;
|
|
|
|
|
+import com.cyksj.mapper.claudecode.ClaudeCodeUserResetRecordMapper;
|
|
|
|
|
+import com.cyksj.mapper.manage.distribute.DistributePointsExchangeMoneyMapper;
|
|
|
|
|
+import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
-import com.cyksj.model.request.ClaudeCodeApiKeysReq;
|
|
|
|
|
-import com.cyksj.model.request.ClaudeCodeCreditCardUseReq;
|
|
|
|
|
-import com.cyksj.model.request.ClaudeCodeDelReq;
|
|
|
|
|
-import com.cyksj.model.request.CreditResetReq;
|
|
|
|
|
-import com.cyksj.model.request.TimeRateConfigReq;
|
|
|
|
|
|
|
+import com.cyksj.model.request.*;
|
|
|
import com.cyksj.model.response.*;
|
|
import com.cyksj.model.response.*;
|
|
|
import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserApiKeysView;
|
|
import com.cyksj.model.views.ClaudeCodeUserApiKeysView;
|
|
|
|
|
+import com.cyksj.model.views.ClaudeCodeUserCreditCardRecordView;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserInfoView;
|
|
import com.cyksj.model.views.ClaudeCodeUserInfoView;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserResetRecordView;
|
|
import com.cyksj.model.views.ClaudeCodeUserResetRecordView;
|
|
|
-import com.cyksj.model.views.ClaudeCodeUserCreditCardRecordView;
|
|
|
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
@@ -42,10 +40,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
@@ -81,6 +78,12 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
|
|
private final ClaudeCodeCreditCardMapper claudeCodeCreditCardMapper;
|
|
private final ClaudeCodeCreditCardMapper claudeCodeCreditCardMapper;
|
|
|
|
|
|
|
|
|
|
+ private final UserMapper userMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final DistributeWaitingSendPointsMapper distributeWaitingSendPointsMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final DistributePointsExchangeMoneyMapper distributePointsExchangeMoneyMapper;
|
|
|
|
|
+
|
|
|
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";
|
|
@@ -868,4 +871,71 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
.build());
|
|
.build());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ClaudeCodeRewardDetailsResp getUserRewardDetails(Long userId) {
|
|
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
+
|
|
|
|
|
+ ClaudeCodeRewardDetailsResp response = new ClaudeCodeRewardDetailsResp();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取用户Claude Code信息
|
|
|
|
|
+ ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(
|
|
|
|
|
+ Wrappers.lambdaQuery(ClaudeCodeUser.class)
|
|
|
|
|
+ .in(ClaudeCodeUser::getUserId, userIdList)
|
|
|
|
|
+ .last("limit 1")
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 设置可重置次数
|
|
|
|
|
+ if (claudeCodeUser != null) {
|
|
|
|
|
+ Integer resetCount = claudeCodeUser.getResetCount();
|
|
|
|
|
+ response.setResetCount(resetCount != null ? resetCount : 0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ response.setResetCount(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取可用积分卡数量
|
|
|
|
|
+ Integer availableCreditCards = claudeCodeCreditCardMapper.selectCount(
|
|
|
|
|
+ Wrappers.lambdaQuery(ClaudeCodeCreditCard.class)
|
|
|
|
|
+ .eq(ClaudeCodeCreditCard::getStatus, 0)
|
|
|
|
|
+ .isNull(ClaudeCodeCreditCard::getUsedUserId)
|
|
|
|
|
+ );
|
|
|
|
|
+ response.setAvailableCreditCards(availableCreditCards != null ? availableCreditCards : 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取分销相关数据
|
|
|
|
|
+ try {
|
|
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
|
|
+ List<DistributeWaitingSendPoints> distributeWaitingSendPoints = distributeWaitingSendPointsMapper.selectList(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class).eq(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.waiting).eq(DistributeWaitingSendPoints::getSharedId, userId).select(DistributeWaitingSendPoints::getPoints));
|
|
|
|
|
+ BigDecimal waitingPoints = BigDecimal.ZERO;
|
|
|
|
|
+ if (!distributeWaitingSendPoints.isEmpty()) {
|
|
|
|
|
+ Optional<BigDecimal> points = distributeWaitingSendPoints.stream().map(DistributeWaitingSendPoints::getPoints).reduce(BigDecimal::add);
|
|
|
|
|
+ if (points.isPresent()) {
|
|
|
|
|
+ waitingPoints = points.get();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (user.getPoints().compareTo(BigDecimal.ZERO) <= 0 && waitingPoints.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
+ response.setGotMoney(BigDecimal.ZERO);
|
|
|
|
|
+ response.setWaitingMoney(BigDecimal.ZERO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ DistributePointsExchangeMoney distributePointsExchangeMoney = distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).orderByDesc(DistributePointsExchangeMoney::getPoints).last("limit 1"));
|
|
|
|
|
+ BigDecimal points = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
|
|
|
|
|
+ BigDecimal money = distributePointsExchangeMoney.getMoney();
|
|
|
|
|
+ BigDecimal oneHundred = BigDecimal.valueOf(100);
|
|
|
|
|
+ if (user.getPoints().compareTo(BigDecimal.ZERO) >= 0) {
|
|
|
|
|
+ response.setGotMoney(user.getPoints().divide(points).multiply(money).divide(oneHundred, 2, RoundingMode.HALF_DOWN));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (user.getPoints().compareTo(BigDecimal.ZERO) >= 0) {
|
|
|
|
|
+ response.setWaitingMoney(waitingPoints.divide(points).multiply(money).divide(oneHundred, 2, RoundingMode.DOWN));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("获取用户{}分销数据异常", userId, e);
|
|
|
|
|
+ // 设置默认值
|
|
|
|
|
+ response.setGotMoney(BigDecimal.ZERO);
|
|
|
|
|
+ response.setWaitingMoney(BigDecimal.ZERO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return response;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|