|
|
@@ -26,7 +26,6 @@ import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
import com.cyksj.model.dto.CouponPopularizeDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
-import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.request.ClaudeCodeApiKeysReq;
|
|
|
import com.cyksj.model.request.ClaudeCodeDelReq;
|
|
|
import com.cyksj.model.request.CodexUpgradePayReq;
|
|
|
@@ -34,10 +33,7 @@ import com.cyksj.model.request.UpdateDailyLimitRequest;
|
|
|
import com.cyksj.model.request.codex.CodexUserPackageReq;
|
|
|
import com.cyksj.model.response.CodexDeductResp;
|
|
|
import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
|
-import com.cyksj.model.views.ClaudeCodeUserApiKeysView;
|
|
|
-import com.cyksj.model.views.CodexUserInfoView;
|
|
|
-import com.cyksj.model.views.CouponNewUserView;
|
|
|
-import com.cyksj.model.views.CouponUserView;
|
|
|
+import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.api.ClaudeCodexApiService;
|
|
|
import com.cyksj.service.codex.CodexService;
|
|
|
@@ -164,7 +160,12 @@ public class CodexServiceImpl implements CodexService {
|
|
|
CodexDeductResp codexDeductResp = new 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());
|
|
|
+ GroupsRelationMirrorView ccRelationView = beanSearcher.searchFirst(GroupsRelationMirrorView.class, MapUtils.builder()
|
|
|
+ .field(GroupsRelationMirrorView::getSkuId, sendCodexSkuIds).op(Operator.InList)
|
|
|
+ .field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
+ .field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(GroupsRelationMirrorView::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID)
|
|
|
+ .build());
|
|
|
if (ccRelationView != null) {
|
|
|
codexDeductResp.setIsDeduct(Boolean.FALSE);
|
|
|
return codexDeductResp;
|
|
|
@@ -172,21 +173,21 @@ public class CodexServiceImpl implements CodexService {
|
|
|
}
|
|
|
MapBuilder builder = MapUtils.builder();
|
|
|
if (relationId != null) {
|
|
|
- builder.field(GroupsRelationView::getId, relationId);
|
|
|
+ builder.field(GroupsRelationMirrorView::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)
|
|
|
+ GroupsRelationMirrorView groupsRelationMirrorView = beanSearcher.searchFirst(GroupsRelationMirrorView.class, builder
|
|
|
+ .field(GroupsRelationMirrorView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
+ .field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
BigDecimal deductMoney;
|
|
|
- if (groupsRelationView == null || groupsRelationView.getExpiryTime().before(DateTime.now())) {
|
|
|
+ if (groupsRelationMirrorView == null || groupsRelationMirrorView.getExpiryTime().before(DateTime.now())) {
|
|
|
deductMoney = BigDecimal.ZERO;
|
|
|
} else {
|
|
|
- relationId = groupsRelationView.getId();
|
|
|
+ relationId = groupsRelationMirrorView.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);
|
|
|
+ deductMoney = getFinalDeductMoney(relationId, groupsRelationMirrorView.getSkuId(), codexUser.getRenewSkuId(), codexUser.getRenewOrderId(), codexUser.getRenewExpiryTime(), groupsRelationMirrorView.getStartTime(), groupsRelationMirrorView.getExpiryTime(), DateTime.now(), userIdList);
|
|
|
}
|
|
|
codexDeductResp.setDeductMoney(deductMoney);
|
|
|
return codexDeductResp;
|
|
|
@@ -256,13 +257,13 @@ public class CodexServiceImpl implements CodexService {
|
|
|
throw BusinessRuntimeException.getInstance("你存在claude code 无法抵扣");
|
|
|
}
|
|
|
} else {
|
|
|
- GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
- .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
- .field(GroupsRelationView::getSkuId, sendCodexSkuIds).op(Operator.NotIn)
|
|
|
- .field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
+ GroupsRelationMirrorView groupsRelationMirrorView = beanSearcher.searchFirst(GroupsRelationMirrorView.class, MapUtils.builder()
|
|
|
+ .field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(GroupsRelationMirrorView::getSkuId, sendCodexSkuIds).op(Operator.NotIn)
|
|
|
+ .field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
- if (groupsRelationView != null) {
|
|
|
- ccRelationId = groupsRelationView.getId();
|
|
|
+ if (groupsRelationMirrorView != null) {
|
|
|
+ ccRelationId = groupsRelationMirrorView.getId();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -288,14 +289,14 @@ public class CodexServiceImpl implements CodexService {
|
|
|
public Boolean getUserSubs(Long userId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
//是否有该车票
|
|
|
- GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
- .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
- .field(GroupsRelationView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
- .field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
+ GroupsRelationMirrorView groupsRelationMirrorView = beanSearcher.searchFirst(GroupsRelationMirrorView.class, MapUtils.builder()
|
|
|
+ .field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(GroupsRelationMirrorView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
+ .field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).in(CodexUser::getUserId, userIdList).last("limit 1"));
|
|
|
//车票不存在
|
|
|
- if (groupsRelationView == null) {
|
|
|
+ if (groupsRelationMirrorView == null) {
|
|
|
//套餐是否存在
|
|
|
if (codexUser != null) {
|
|
|
//清除用户套餐
|
|
|
@@ -313,14 +314,14 @@ public class CodexServiceImpl implements CodexService {
|
|
|
public CodexUserInfoView getUserSubsInfo(long userId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
//是否有该车票
|
|
|
- GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
- .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
- .field(GroupsRelationView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
- .field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
+ GroupsRelationMirrorView groupsRelationMirrorView = beanSearcher.searchFirst(GroupsRelationMirrorView.class, MapUtils.builder()
|
|
|
+ .field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(GroupsRelationMirrorView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
+ .field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).in(CodexUser::getUserId, userIdList).last("limit 1"));
|
|
|
//车票不存在
|
|
|
- if (groupsRelationView == null) {
|
|
|
+ if (groupsRelationMirrorView == null) {
|
|
|
//套餐是否存在
|
|
|
if (codexUser != null) {
|
|
|
//清除用户套餐
|
|
|
@@ -335,7 +336,7 @@ public class CodexServiceImpl implements CodexService {
|
|
|
if (codexUser == null) {
|
|
|
OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
.eq(OrderDon::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
- .eq(OrderDon::getRelationId, groupsRelationView.getId())
|
|
|
+ .eq(OrderDon::getRelationId, groupsRelationMirrorView.getId())
|
|
|
.in(OrderDon::getUserId, userIdList)
|
|
|
.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
.orderByDesc(OrderDon::getId)
|
|
|
@@ -345,9 +346,9 @@ public class CodexServiceImpl implements CodexService {
|
|
|
createOrUpdateCodexUserInfo(orderDon.getId(), orderDon.getRelationId(), orderDon.getUserId(), sku, orderDon.getOrderType());
|
|
|
} else {
|
|
|
//试用车票
|
|
|
- Long skuId = groupsRelationView.getSkuId();
|
|
|
+ Long skuId = groupsRelationMirrorView.getSkuId();
|
|
|
sku = skuMapper.selectById(skuId);
|
|
|
- createOrUpdateCodexUserInfo(null, groupsRelationView.getId(), groupsRelationView.getUserId(), sku, null);
|
|
|
+ createOrUpdateCodexUserInfo(null, groupsRelationMirrorView.getId(), groupsRelationMirrorView.getUserId(), sku, null);
|
|
|
}
|
|
|
codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).in(CodexUser::getUserId, userIdList).last("limit 1"));
|
|
|
}
|
|
|
@@ -356,11 +357,11 @@ public class CodexServiceImpl implements CodexService {
|
|
|
sku = skuMapper.selectById(codexUser.getRenewSkuId());
|
|
|
}
|
|
|
if (sku == null) {
|
|
|
- sku = skuMapper.selectById(groupsRelationView.getSkuId());
|
|
|
+ sku = skuMapper.selectById(groupsRelationMirrorView.getSkuId());
|
|
|
}
|
|
|
if (codexUser != null) {
|
|
|
codexUser.setPlanName(sku.getSpecVal());
|
|
|
- codexUser.setExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
+ codexUser.setExpiryTime(groupsRelationMirrorView.getExpiryTime());
|
|
|
codexUserMapper.updateById(codexUser);
|
|
|
}
|
|
|
//是否需要重试更新 cladueCode userInfo信息
|
|
|
@@ -385,7 +386,7 @@ public class CodexServiceImpl implements CodexService {
|
|
|
.openaiDailyLimit(codexUser.getOpenaiDailyLimit())
|
|
|
.openaiQuota(codexUser.getOpenaiQuota())
|
|
|
.expiryTime(codexUser.getExpiryTime())
|
|
|
- .renewSkuId(Optional.ofNullable(codexUser.getRenewSkuId()).orElse(groupsRelationView.getSkuId()))
|
|
|
+ .renewSkuId(Optional.ofNullable(codexUser.getRenewSkuId()).orElse(groupsRelationMirrorView.getSkuId()))
|
|
|
.renewOrderId(codexUser.getRenewOrderId())
|
|
|
.renewExpiryTime(codexUser.getRenewExpiryTime())
|
|
|
.build();
|
|
|
@@ -1187,13 +1188,13 @@ public class CodexServiceImpl implements CodexService {
|
|
|
*/
|
|
|
public Long getCodexUserId(Long userId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
- .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
- .field(GroupsRelationView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
- .field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
+ GroupsRelationMirrorView groupsRelationMirrorView = beanSearcher.searchFirst(GroupsRelationMirrorView.class, MapUtils.builder()
|
|
|
+ .field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(GroupsRelationMirrorView::getGoodsId, Constant.CODEX_GOODS_ID)
|
|
|
+ .field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
- if (groupsRelationView != null) {
|
|
|
- return groupsRelationView.getUserId();
|
|
|
+ if (groupsRelationMirrorView != null) {
|
|
|
+ return groupsRelationMirrorView.getUserId();
|
|
|
}
|
|
|
return null;
|
|
|
}
|