|
|
@@ -3,6 +3,7 @@ package com.cyksj.service.codex.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
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.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
@@ -41,6 +42,7 @@ import com.cyksj.service.groups.GroupsFuncService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
+import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import com.github.rholder.retry.Retryer;
|
|
|
import com.github.rholder.retry.RetryerBuilder;
|
|
|
@@ -231,13 +233,19 @@ public class CodexServiceImpl implements CodexService {
|
|
|
public CodexDeductResp getDeductMoney(Long userId, Long relationId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
CodexDeductResp codexDeductResp = new CodexDeductResp();
|
|
|
- Integer selectCount = claudeCodeUserMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList));
|
|
|
- if (selectCount > 0) {
|
|
|
- codexDeductResp.setIsDeduct(Boolean.FALSE);
|
|
|
- return codexDeductResp;
|
|
|
+ List<Long> sendCodexSkuIds = skuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID).eq(GoodsDonSku::getIsCodex, Boolean.TRUE)).stream().map(GoodsDonSku::getId).collect(Collectors.toList());
|
|
|
+ if (CollUtil.isNotEmpty(sendCodexSkuIds)) {
|
|
|
+ GroupsRelationView ccRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getSkuId, sendCodexSkuIds).op(Operator.InList).field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan).field(GroupsRelationView::getUserId, userIdList).op(Operator.InList).field(GroupsRelationView::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID).build());
|
|
|
+ if (ccRelationView != null) {
|
|
|
+ codexDeductResp.setIsDeduct(Boolean.FALSE);
|
|
|
+ return codexDeductResp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MapBuilder builder = MapUtils.builder();
|
|
|
+ if (relationId != null) {
|
|
|
+ builder.field(GroupsRelationView::getId, relationId);
|
|
|
}
|
|
|
- GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
- .field(GroupsRelationView::getId, relationId)
|
|
|
+ GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, builder
|
|
|
.field(GroupsRelationView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
.field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
.field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
@@ -246,7 +254,9 @@ public class CodexServiceImpl implements CodexService {
|
|
|
if (groupsRelationView == null || groupsRelationView.getExpiryTime().before(DateTime.now())) {
|
|
|
deductMoney = BigDecimal.ZERO;
|
|
|
} else {
|
|
|
- CodexUser codexUser = codexUserMapper.selectById(relationId);
|
|
|
+ relationId = groupsRelationView.getId();
|
|
|
+ CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).eq(CodexUser::getRelationId, relationId).last("limit 1"));
|
|
|
+ Assert.notNull(codexUser, "系统异常,请联系客服");
|
|
|
deductMoney = getFinalDeductMoney(relationId, groupsRelationView.getSkuId(), codexUser.getRenewSkuId(), codexUser.getRenewOrderId(), codexUser.getRenewExpiryTime(), groupsRelationView.getStartTime(), groupsRelationView.getExpiryTime(), DateTime.now(), userIdList);
|
|
|
}
|
|
|
codexDeductResp.setDeductMoney(deductMoney);
|