|
|
@@ -21,6 +21,7 @@ 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.dto.ClaudeCodeDeductDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.request.ClaudeCodeApiKeysReq;
|
|
|
@@ -1026,7 +1027,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public BigDecimal getDeductSkuMoney(Long userId, Long relationId, Long skuId) {
|
|
|
+ public ClaudeCodeDeductDto getDeductSkuMoney(Long userId, Long relationId, Long skuId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
GroupsRelationView relationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
.field(GroupsRelationView::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID)
|
|
|
@@ -1034,13 +1035,16 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
.field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
.field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
+ ClaudeCodeDeductDto claudeCodeDeductDto = new ClaudeCodeDeductDto();
|
|
|
if (relationView == null) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ claudeCodeDeductDto.setDeductMoney(BigDecimal.ZERO);
|
|
|
+ return claudeCodeDeductDto;
|
|
|
}
|
|
|
ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
GoodsDonSku upgradeSku = skuMapper.selectById(skuId);
|
|
|
if (upgradeSku.getGoodsId() != Constant.CLAUDE_CODE_GOODS_ID) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ claudeCodeDeductDto.setDeductMoney(BigDecimal.ZERO);
|
|
|
+ return claudeCodeDeductDto;
|
|
|
}
|
|
|
GoodsDonSku relationPresentSku = null;
|
|
|
Long renewSkuId = claudeCodeUser.getRenewSkuId();
|
|
|
@@ -1051,24 +1055,27 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
relationPresentSku = skuMapper.selectById(relationView.getSkuId());
|
|
|
}
|
|
|
if (upgradeSku.getClaudeQuota().intValue() < relationPresentSku.getClaudeQuota().intValue()) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ claudeCodeDeductDto.setDeductMoney(BigDecimal.ZERO);
|
|
|
+ return claudeCodeDeductDto;
|
|
|
}
|
|
|
- BigDecimal deductMoney = getDeductMoney(relationId, relationView.getSkuId(), claudeCodeUser.getRenewSkuId(), claudeCodeUser.getRenewOrderId(), claudeCodeUser.getRenewExpiryTime(), relationView.getStartTime(), relationView.getExpiryTime(), DateTime.now(), userIdList);
|
|
|
- return deductMoney;
|
|
|
+ claudeCodeDeductDto = getDeductMoney(relationId, relationView.getSkuId(), claudeCodeUser.getRenewSkuId(), claudeCodeUser.getRenewOrderId(), claudeCodeUser.getRenewExpiryTime(), relationView.getStartTime(), relationView.getExpiryTime(), DateTime.now(), userIdList, upgradeSku);
|
|
|
+ return claudeCodeDeductDto;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public BigDecimal getDeductMoney(Long relationId, Long relationSkuId, Long renewSkuId, Long renewOrderId, Date renewExpiryTime, Date relationStartTime, Date relationExpiryTime, DateTime now, List<Long> userIdList) {
|
|
|
+ public ClaudeCodeDeductDto getDeductMoney(Long relationId, Long relationSkuId, Long renewSkuId, Long renewOrderId, Date renewExpiryTime, Date relationStartTime, Date relationExpiryTime, DateTime now, List<Long> userIdList, GoodsDonSku upgradeSku) {
|
|
|
BigDecimal deductMoney = BigDecimal.ZERO;
|
|
|
//一个月当30天算单价 往上取整
|
|
|
//续费规格
|
|
|
+ ClaudeCodeDeductDto claudeCodeDeductDto = new ClaudeCodeDeductDto();
|
|
|
if (renewSkuId != null && renewExpiryTime.compareTo(now) > 0) {
|
|
|
OrderDon renewOrderDon = orderDonMapper.selectById(renewOrderId);
|
|
|
BigDecimal orderMoney = renewOrderDon.getMoney().add(Optional.ofNullable(renewOrderDon.getBalance()).orElse(BigDecimal.ZERO));
|
|
|
GoodsDonSku presentSku = skuMapper.selectById(renewSkuId);
|
|
|
if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
//存在升级后的0元订单 即兑换码订单 不让抵扣
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ claudeCodeDeductDto.setDeductMoney(BigDecimal.ZERO);
|
|
|
+ return claudeCodeDeductDto;
|
|
|
} else {
|
|
|
Long betweenDay = DateUtil.betweenDay(now, renewExpiryTime, false) + 1;
|
|
|
//当天购买的按规格原价抵扣
|
|
|
@@ -1100,7 +1107,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
BigDecimal thisOrderMoney = thisRenewOrderDon.getMoney().add(Optional.ofNullable(thisRenewOrderDon.getBalance()).orElse(BigDecimal.ZERO));
|
|
|
if (thisOrderMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
//存在升级后的0元订单 即兑换码订单 不让抵扣
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ claudeCodeDeductDto.setDeductMoney(BigDecimal.ZERO);
|
|
|
+ return claudeCodeDeductDto;
|
|
|
}
|
|
|
//当天购买的按规格原价抵扣
|
|
|
BigDecimal thisRenewDeductMoney = BigDecimal.ZERO;
|
|
|
@@ -1154,7 +1162,18 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
deductMoney = deductMoney.add(deductMoneyFromTicket);
|
|
|
}
|
|
|
log.info("车票id:{}最终到期时间为:{}车票可返回 抵扣金额:{}", relationId, DateUtil.format(relationExpiryTime, "yyyy-MM-dd HH:mm:ss"), deductMoney);
|
|
|
- return deductMoney;
|
|
|
+ //超出可抵扣的金额 直接返回
|
|
|
+ if (deductMoney.compareTo(upgradeSku.getPrice()) >= 0) {
|
|
|
+ BigDecimal overMoney = deductMoney.subtract(upgradeSku.getPrice());
|
|
|
+ //超过抵扣金额可换延长会员多少天
|
|
|
+ //每天单价
|
|
|
+ BigDecimal daySingle = upgradeSku.getPrice().divide(BigDecimal.valueOf(upgradeSku.getMonths())).divide(BigDecimal.valueOf(30), 0, RoundingMode.DOWN);
|
|
|
+ //超出部分可换取多少天 低于每天单价为0天
|
|
|
+ BigDecimal extendsDays = overMoney.divide(daySingle, 0, RoundingMode.UP);
|
|
|
+ claudeCodeDeductDto.setExtendsDays(extendsDays.intValue());
|
|
|
+ }
|
|
|
+ claudeCodeDeductDto.setDeductMoney(deductMoney);
|
|
|
+ return claudeCodeDeductDto;
|
|
|
}
|
|
|
|
|
|
private void adjClaudeCodeUserPoints(Long userId, Integer points, String type, String description) throws Exception {
|