|
|
@@ -22,7 +22,10 @@ import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
|
|
|
import com.cyksj.model.dto.ClaudeCodeDeductDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
-import com.cyksj.model.request.*;
|
|
|
+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.codex.CodexUserPackageReq;
|
|
|
import com.cyksj.model.response.ClaudeCodeRewardDetailsResp;
|
|
|
import com.cyksj.model.response.CreditResetResp;
|
|
|
@@ -33,9 +36,6 @@ import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.api.ClaudeCodexApiService;
|
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
|
import com.cyksj.service.codex.CodexService;
|
|
|
-import com.cyksj.service.order.OrderRefundService;
|
|
|
-import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
-import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
@@ -108,14 +108,6 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
private final ClaudeCodeDeductOrderRelateMapper claudeCodeDeductOrderRelateMapper;
|
|
|
|
|
|
- private final GroupRelationFrontService groupRelationFrontService;
|
|
|
-
|
|
|
- private final GroupRelationClearService clearService;
|
|
|
-
|
|
|
- private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
-
|
|
|
- private final OrderRefundService orderRefundService;
|
|
|
-
|
|
|
@Override
|
|
|
public void generateOrUpdateClaudeCodeUserInfo(Long orderId, Long relationId, Long userId, GoodsDonSku sku, Integer orderType) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
@@ -172,7 +164,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void generateOrUpdateClaudeCodeUser(Long relationUserId, Long relationId, Integer claudeDailyLimit, Integer claudePermanentBalance, Date expiryTime, Boolean isUpgrade, Long orderId, Long renewSkuId, Date renewExpiryTime, String planName, List<Long> userIdList) {
|
|
|
+ @Override
|
|
|
+ public void generateOrUpdateClaudeCodeUser(Long relationUserId, Long relationId, Integer claudeDailyLimit, Integer claudePermanentBalance, 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();
|
|
|
@@ -1206,70 +1199,6 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public BigDecimal getCcRemainDeductMoney(long userId) {
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- GroupsRelationView relationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
- .field(GroupsRelationView::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID)
|
|
|
- .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
- .field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
- .build());
|
|
|
- if (relationView == null) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
- }
|
|
|
- Long relationId = relationView.getId();
|
|
|
- ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
- OrderDon oriOrderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getRelationId, relationId).in(OrderDon::getUserId, userIdList).notIn(OrderDon::getStatus, Constant.noOrderAllStatus).eq(OrderDon::getOrderType, 1).orderByDesc(OrderDon::getId).last("limit 1"));
|
|
|
- ClaudeCodeDeductDto claudeCodeDeductDto = getDeductMoney(relationId, oriOrderDon.getSkuId(), claudeCodeUser.getRenewSkuId(), claudeCodeUser.getRenewOrderId(), claudeCodeUser.getRenewExpiryTime(), relationView.getStartTime(), relationView.getExpiryTime(), DateTime.now(), userIdList, null);
|
|
|
- return claudeCodeDeductDto.getDeductMoney();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void ccRefund(long userId) throws Exception {
|
|
|
- BigDecimal ccRemainDeductMoney = getCcRemainDeductMoney(userId);
|
|
|
- if (ccRemainDeductMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("车票剩余价值为0,无法退款");
|
|
|
- }
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList).last("limit 1"));
|
|
|
- GroupsRelation groupsRelation = relationMapper.selectById(claudeCodeUser.getRelationId());
|
|
|
-
|
|
|
- Long relationId = groupsRelation.getId();
|
|
|
- OrderDon oriOrderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getRelationId, relationId).in(OrderDon::getUserId, userIdList).notIn(OrderDon::getStatus, Constant.noOrderAllStatus).eq(OrderDon::getOrderType, 1).orderByDesc(OrderDon::getId).last("limit 1"));
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(oriOrderDon.getSkuId());
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(oriOrderDon.getGoodsId());
|
|
|
- if (ccRemainDeductMoney.compareTo(oriOrderDon.getMoney()) > 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("请联系客服退款");
|
|
|
- } else {
|
|
|
- //直接退原订单
|
|
|
- ccRefund(goodsDon, sku, oriOrderDon, ccRemainDeductMoney, BigDecimal.ZERO);
|
|
|
- }
|
|
|
- clearService.clearTicket(groupsRelation, UserTicketClearedRecord.Source.refund);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Throwable.class)
|
|
|
- public void trans(long userId) {
|
|
|
- BigDecimal ccRemainDeductMoney = getCcRemainDeductMoney(userId);
|
|
|
- if (ccRemainDeductMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("车票剩余价值为0,不可转换");
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
-
|
|
|
- ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList).last("limit 1"));
|
|
|
- GroupsRelation groupsRelation = relationMapper.selectById(claudeCodeUser.getRelationId());
|
|
|
-
|
|
|
- //获取默认规格车票
|
|
|
- Long skuId = Constant.CC_TRANS_SKU_ID;
|
|
|
- Long relationId = groupRelationFrontService.getTicket(userId,skuId , false);
|
|
|
- clearService.clearTicket(groupsRelation, UserTicketClearedRecord.Source.cc_trans_other);
|
|
|
-
|
|
|
- BigDecimal transDeduct = ccRemainDeductMoney.multiply(BigDecimal.valueOf(1.2));
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
|
|
|
- generateOrUpdateClaudeCodeUser(userId, relationId, sku.getClaudeDailyLimit(), transDeduct.intValue(), DateUtil.offsetMonth(DateTime.now(), sku.getMonths()), false, null, null, null, sku.getSpecVal(), userIdList);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取订单单价
|
|
|
*/
|
|
|
@@ -1371,26 +1300,4 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
return deductMoney;
|
|
|
}
|
|
|
-
|
|
|
- public void ccRefund(GoodsDon goodsDon, GoodsDonSku sku, OrderDon orderDon, BigDecimal refundMoney, BigDecimal refundBalance) throws Exception {
|
|
|
- //调用第三方接口退款
|
|
|
- OrderRefundReq refundReq = new OrderRefundReq();
|
|
|
- refundReq.setRefundMoney(refundMoney);
|
|
|
- refundReq.setRefundType("money");
|
|
|
- String outNo = orderRefundService.centerRefund(refundReq, orderDon);
|
|
|
- orderDon.setRefundMoney(refundMoney);
|
|
|
- orderDon.setStatus(OrderDon.Status.refund);
|
|
|
- orderDon.setRefundDesc("cc售后退款");
|
|
|
- orderDonMapper.updateById(orderDon);
|
|
|
-
|
|
|
- String refundType;
|
|
|
- if (refundMoney.compareTo(BigDecimal.ZERO) > 0 && refundBalance.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- refundType = "bxj";
|
|
|
- } else if (refundMoney.compareTo(BigDecimal.ZERO) == 0 && refundBalance.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- refundType = "balance";
|
|
|
- } else {
|
|
|
- refundType = orderDon.getType().name();
|
|
|
- }
|
|
|
- orderRefundService.refundRecord(orderDon, refundMoney, null, "系统", goodsDon, sku, outNo, refundType, null);
|
|
|
- }
|
|
|
}
|