|
|
@@ -1,11 +1,18 @@
|
|
|
package com.cyksj.service.vip.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
+import com.cyksj.mapper.ChatgptUserMapper;
|
|
|
+import com.cyksj.mapper.ClaudeUserMapper;
|
|
|
+import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
+import com.cyksj.mapper.OrderDonRenewRecordMapper;
|
|
|
import com.cyksj.mapper.sys.SysConfigMapper;
|
|
|
import com.cyksj.mapper.vip.VipGoodsSkuMapper;
|
|
|
+import com.cyksj.model.entity.ChatgptUser;
|
|
|
+import com.cyksj.model.entity.GoodsDonSku;
|
|
|
import com.cyksj.model.entity.SysConfig;
|
|
|
import com.cyksj.model.entity.VipGoodsSku;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
@@ -19,6 +26,8 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -39,6 +48,14 @@ public class VipFrontServiceImpl implements VipFrontService {
|
|
|
|
|
|
private final BeanSearcher beanSearcher;
|
|
|
|
|
|
+ private final GoodsDonSkuMapper skuMapper;
|
|
|
+
|
|
|
+ private final ChatgptUserMapper chatgptUserMapper;
|
|
|
+
|
|
|
+ private final OrderDonRenewRecordMapper orderDonRenewRecordMapper;
|
|
|
+
|
|
|
+ private final ClaudeUserMapper claudeUserMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public void fillVipInfo(long userId, VipUserPageResp vipUserPageResp) {
|
|
|
SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
@@ -52,10 +69,11 @@ public class VipFrontServiceImpl implements VipFrontService {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
|
|
|
//可有抵扣车票
|
|
|
+ DateTime now = DateTime.now();
|
|
|
Number count = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder()
|
|
|
.field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
.field(GroupsRelationView::getSkuId, vipSkuIds).op(Operator.InList)
|
|
|
- .field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
+ .field(GroupsRelationView::getExpiryTime, now).op(Operator.GreaterThan)
|
|
|
.build());
|
|
|
//可抵扣车票
|
|
|
if (count.intValue() > 0) {
|
|
|
@@ -67,9 +85,41 @@ public class VipFrontServiceImpl implements VipFrontService {
|
|
|
.build());
|
|
|
if (relation != null) {
|
|
|
Long goodsId = relation.getGoodsId();
|
|
|
+ Long relationId = relation.getId();
|
|
|
//GPT
|
|
|
if (goodsId == Constant.GPT_PLUS_GID) {
|
|
|
-
|
|
|
+ Date relationExpiryTime = relation.getExpiryTime();
|
|
|
+ ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
|
|
|
+ .eq(ChatgptUser::getRelationId, relationId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (chatgptUser != null) {
|
|
|
+ //续费规格
|
|
|
+ Long renewSkuId = chatgptUser.getRenewSkuId();
|
|
|
+ if (renewSkuId != null) {
|
|
|
+ Date renewExpiryTime = chatgptUser.getRenewExpiryTime();
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(renewSkuId);
|
|
|
+ BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
|
|
|
+ Long betweenDay = DateUtil.betweenDay(now, renewExpiryTime, false);
|
|
|
+ //该车票抵扣金额
|
|
|
+ deductMoney.add(single.multiply(BigDecimal.valueOf(betweenDay)));
|
|
|
+ relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, betweenDay.intValue());
|
|
|
+ }else {
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(vipSkuId);
|
|
|
+ BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
|
|
|
+ Long betweenDay = DateUtil.betweenDay(now, relationExpiryTime, false);
|
|
|
+ //该车票抵扣金额
|
|
|
+ deductMoney.add(single.multiply(BigDecimal.valueOf(betweenDay)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (goodsId == Constant.CLAUDE_PRO_GID) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Long skuId = relation.getSkuId();
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(skuId);
|
|
|
+ BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
|
|
|
+ long betweenDay = DateUtil.betweenDay(now, relation.getExpiryTime(), false);
|
|
|
+ //该车票抵扣金额
|
|
|
+ deductMoney.add(single.multiply(BigDecimal.valueOf(betweenDay)));
|
|
|
}
|
|
|
}
|
|
|
}
|