|
|
@@ -158,7 +158,7 @@ public class CodexServiceImpl implements CodexService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CodexDeductResp getDeductMoney(Long userId, Long relationId) {
|
|
|
+ public CodexDeductResp getDeductMoney(Long userId, Long relationId, Long upgradeSkuId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
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());
|
|
|
@@ -174,6 +174,11 @@ public class CodexServiceImpl implements CodexService {
|
|
|
return codexDeductResp;
|
|
|
}
|
|
|
}
|
|
|
+ GoodsDonSku upgradeSku = skuMapper.selectById(upgradeSkuId);
|
|
|
+ if (upgradeSku.getGoodsId() != Constant.CLAUDE_CODE_GOODS_ID) {
|
|
|
+ codexDeductResp.setDeductMoney(BigDecimal.ZERO);
|
|
|
+ return codexDeductResp;
|
|
|
+ }
|
|
|
MapBuilder builder = MapUtils.builder();
|
|
|
if (relationId != null) {
|
|
|
builder.field(GroupsRelationMirrorView::getId, relationId);
|
|
|
@@ -183,16 +188,14 @@ public class CodexServiceImpl implements CodexService {
|
|
|
.field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
.field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
- BigDecimal deductMoney;
|
|
|
if (groupsRelationMirrorView == null || groupsRelationMirrorView.getExpiryTime().before(DateTime.now())) {
|
|
|
- deductMoney = BigDecimal.ZERO;
|
|
|
- } else {
|
|
|
+ codexDeductResp.setDeductMoney(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
relationId = groupsRelationMirrorView.getId();
|
|
|
CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).eq(CodexUser::getRelationId, relationId).last("limit 1"));
|
|
|
Assert.notNull(codexUser, "系统异常,请联系客服");
|
|
|
- deductMoney = getFinalDeductMoney(relationId, groupsRelationMirrorView.getSkuId(), codexUser.getRenewSkuId(), codexUser.getRenewOrderId(), codexUser.getRenewExpiryTime(), groupsRelationMirrorView.getStartTime(), groupsRelationMirrorView.getExpiryTime(), DateTime.now(), userIdList);
|
|
|
+ codexDeductResp = getFinalDeductMoney(relationId, groupsRelationMirrorView.getSkuId(), codexUser.getRenewSkuId(), codexUser.getRenewOrderId(), codexUser.getRenewExpiryTime(), groupsRelationMirrorView.getStartTime(), groupsRelationMirrorView.getExpiryTime(), DateTime.now(), userIdList, upgradeSku);
|
|
|
}
|
|
|
- codexDeductResp.setDeductMoney(deductMoney);
|
|
|
return codexDeductResp;
|
|
|
}
|
|
|
|
|
|
@@ -202,13 +205,14 @@ public class CodexServiceImpl implements CodexService {
|
|
|
Long userId = payReq.getUserId();
|
|
|
//codex 车票id
|
|
|
Long relationId = payReq.getRelationId();
|
|
|
- CodexDeductResp codexDeductResp = getDeductMoney(userId, relationId);
|
|
|
+ CodexDeductResp codexDeductResp = getDeductMoney(userId, relationId, payReq.getSkuId());
|
|
|
if (!codexDeductResp.getIsDeduct()) {
|
|
|
throw BusinessRuntimeException.getInstance("你存在claude code 无法抵扣");
|
|
|
}
|
|
|
//抵扣金额
|
|
|
BigDecimal deductMoney = codexDeductResp.getDeductMoney();
|
|
|
- Long skuId = payReq.getSkuId();
|
|
|
+ Integer extendsDays = codexDeductResp.getExtendsDays();
|
|
|
+ Long skuId = payReq.getSkuId();
|
|
|
|
|
|
GoodsDonSku sku = skuMapper.selectById(skuId);
|
|
|
if (sku == null || sku.getGoodsId() != Constant.CLAUDE_CODE_GOODS_ID || !sku.getIsCodex()) {
|
|
|
@@ -279,6 +283,7 @@ public class CodexServiceImpl implements CodexService {
|
|
|
codexDeductRecord.setCcRelationId(ccRelationId);
|
|
|
codexDeductRecord.setOrderId(orderDon.getId());
|
|
|
codexDeductRecord.setRelationId(relationId);
|
|
|
+ codexDeductRecord.setExtendsDays(extendsDays);
|
|
|
codexDeductRecordMapper.insert(codexDeductRecord);
|
|
|
} finally {
|
|
|
if (redisService.hasKey(cacheKye)) {
|
|
|
@@ -472,7 +477,7 @@ public class CodexServiceImpl implements CodexService {
|
|
|
return relation;
|
|
|
}
|
|
|
|
|
|
- public BigDecimal getFinalDeductMoney(Long relationId, Long relationSkuId, Long renewSkuId, Long renewOrderId, Date renewExpiryTime, Date relationStartTime, Date relationExpiryTime, DateTime now, List<Long> userIdList) {
|
|
|
+ public CodexDeductResp getFinalDeductMoney(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天算单价 往上取整
|
|
|
//续费规格
|
|
|
@@ -563,13 +568,25 @@ public class CodexServiceImpl implements CodexService {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- if (relationExpiryTime.after(now)) {
|
|
|
+ CodexDeductResp codexDeductResp = new CodexDeductResp();
|
|
|
+ if (relationExpiryTime.after(now)) {
|
|
|
//该车票抵扣金额
|
|
|
BigDecimal deductMoneyFromTicket = getDeductMoneyFromTicket(relationId, userIdList, relationSkuId, now, relationStartTime, relationExpiryTime);
|
|
|
deductMoney = deductMoney.add(deductMoneyFromTicket);
|
|
|
}
|
|
|
+ //超出可抵扣的金额 直接返回
|
|
|
+ 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);
|
|
|
+ codexDeductResp.setExtendsDays(extendsDays.intValue());
|
|
|
+ }
|
|
|
log.info("codex车票id:{}最终到期时间为:{}车票可返回 抵扣金额:{}", relationId, DateUtil.format(relationExpiryTime, "yyyy-MM-dd HH:mm:ss"), deductMoney);
|
|
|
- return deductMoney;
|
|
|
+ codexDeductResp.setDeductMoney(deductMoney);
|
|
|
+ return codexDeductResp;
|
|
|
}
|
|
|
|
|
|
private Retryer<ClaudeCodeResp> getApiRetryer(int wait, int stop) {
|