|
|
@@ -28,6 +28,7 @@ import com.cyksj.model.request.ExchangeCodeReq;
|
|
|
import com.cyksj.model.request.ExchangeCodeTicket;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
|
+import com.cyksj.service.codex.CodexService;
|
|
|
import com.cyksj.service.exchange.ExchangeCodeService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.relation.GroupsRelationExpiryRecordService;
|
|
|
@@ -99,10 +100,10 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
|
|
|
private final UserBindRelationService userBindRelationService;
|
|
|
|
|
|
- private final ClaudeCodeUserMapper claudeCodeUserMapper;
|
|
|
-
|
|
|
private final ClaudeCodeService claudeCodeService;
|
|
|
|
|
|
+ private final CodexService codexService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
public List<ExcelExchangeCodeData> createExchangeCode(ExchangeCodeReq exchangeCodeReq) throws Exception {
|
|
|
@@ -391,14 +392,18 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
orderDonMapper.insert(orderDon);
|
|
|
log.info("用户{}兑换规格:{}车位成功", user.getId(), orderDon.getSkuId());
|
|
|
|
|
|
- if (relation.getIsClaudeCodeRenew() != null && relation.getIsClaudeCodeRenew()) {
|
|
|
- //claude code续费
|
|
|
+ if (relation.getIsRenew() != null && relation.getIsRenew()) {
|
|
|
+ //claude code/codex续费
|
|
|
orderDon.setOrderType(2);
|
|
|
orderDonMapper.updateById(orderDon);
|
|
|
- //续费且升级
|
|
|
+ //claude code续费且升级
|
|
|
if (relation.getIsClaudeCodeUpgrade() != null && relation.getIsClaudeCodeUpgrade()) {
|
|
|
claudeCodeService.handleClaudeCodeUserPackageSku(relation, sku, orderDon.getId());
|
|
|
}
|
|
|
+ //codex 续费且升级
|
|
|
+ if (relation.getIsClaudeCodeUpgrade() != null && relation.getIsClaudeCodeUpgrade()) {
|
|
|
+ codexService.handleClaudeCodeUserPackageSku(relation, sku, orderDon.getId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (orderDonTye == OrderDon.Type.EX_CODE) {
|
|
|
@@ -447,13 +452,41 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
relation.setExpiryTime(expiryTime);
|
|
|
groupsRelationMapper.updateById(relation);
|
|
|
//同规格只加时长
|
|
|
- relation.setIsClaudeCodeRenew(Boolean.TRUE);
|
|
|
+ relation.setIsRenew(Boolean.TRUE);
|
|
|
if (relationSku.getClaudeDailyLimit() != sku.getClaudeDailyLimit()) {
|
|
|
relation.setIsClaudeCodeUpgrade(true);
|
|
|
}
|
|
|
return relation;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //codex 商品兑换
|
|
|
+ if (sku.getGoodsId() == Constant.CODEX_GOODS_ID) {
|
|
|
+ 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).build());
|
|
|
+ if (groupsRelationView != null) {
|
|
|
+ GoodsDonSku relationSku = goodsDonSkuMapper.selectById(groupsRelationView.getSkuId());
|
|
|
+ //兑换的规格 低于当前规格 不让兑换
|
|
|
+ if (relationSku.getOpenaiDailyLimit() > sku.getOpenaiDailyLimit()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请在codex当前版本过期后再兑换");
|
|
|
+ }
|
|
|
+ Date expiryTime = groupsRelationView.getExpiryTime();
|
|
|
+ if (sku.getDays() != null) {
|
|
|
+ expiryTime = DateUtil.offsetDay(expiryTime, sku.getDays());
|
|
|
+ } else {
|
|
|
+ expiryTime = DateUtil.offsetMonth(expiryTime, sku.getMonths());
|
|
|
+ }
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectById(groupsRelationView.getId());
|
|
|
+ relation.setExpiryTime(expiryTime);
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
+ //同规格只加时长
|
|
|
+ relation.setIsRenew(Boolean.TRUE);
|
|
|
+ if (relationSku.getOpenaiDailyLimit() != sku.getOpenaiDailyLimit()) {
|
|
|
+ relation.setIsCodexUpgrade(true);
|
|
|
+ }
|
|
|
+ return relation;
|
|
|
+ }
|
|
|
+ }
|
|
|
Integer retryNum = 1;
|
|
|
List<Long> errorsRelationIds = new ArrayList<>();
|
|
|
GroupsRelation relation = getFinalRelation(sku, userId, retryNum, yhsId, errorsRelationIds);
|