|
|
@@ -42,6 +42,7 @@ import com.cyksj.service.chatgpt.ChatGptAccountService;
|
|
|
import com.cyksj.service.claude.ClaudeService;
|
|
|
import com.cyksj.service.order.VipOrderDonService;
|
|
|
import com.cyksj.service.pay.AliPayCommonService;
|
|
|
+import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
@@ -57,10 +58,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -131,6 +129,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
|
|
|
private final UserPlatDistributeRateMapper userPlatDistributeRateMapper;
|
|
|
|
|
|
+ private final GroupRelationClearService relationClearService;
|
|
|
+
|
|
|
private final BusinessDistributeDefaultRateConfigMapper businessDistributeDefaultRateConfigMapper;
|
|
|
|
|
|
@Override
|
|
|
@@ -145,8 +145,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
orderDon.setOrderNo(donNo);
|
|
|
orderDon.setOpenId(user.getOpenId());
|
|
|
//获取会员价格
|
|
|
- VipDeductDto vipMoneyIfDeduct = getVipMoneyIfDeduct(user, payRequest.getIsDeduct());
|
|
|
- BigDecimal vipMoney = getVipMoney();
|
|
|
+ VipDeductDto vipMoneyIfDeduct = getVipMoneyIfDeduct(user, payRequest.getIsDeduct(), payRequest.getNum());
|
|
|
+ BigDecimal vipMoney = getVipMoney(payRequest.getNum());
|
|
|
payRequest.setDonMoney(vipMoney);
|
|
|
if (vipMoneyIfDeduct != null) {
|
|
|
payRequest.setDonMoney(vipMoney.subtract(vipMoneyIfDeduct.getDeductMoney()));
|
|
|
@@ -165,6 +165,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
//设置订单支付商品信息
|
|
|
orderDon.setPayTitle(Constant.VIP_TITLE);
|
|
|
orderDon.setGoodsId(Constant.VIP_RELATE_GOODS_ID);
|
|
|
+ //购买月数
|
|
|
+ orderDon.setNum(payRequest.getNum());
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
Long orderId = orderDon.getId();
|
|
|
@@ -257,7 +259,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
orderDon.setOrderNo(donNo);
|
|
|
orderDon.setOpenId(user.getOpenId());
|
|
|
//获取续费会员价格
|
|
|
- payRequest.setDonMoney(getVipMoney());
|
|
|
+ payRequest.setDonMoney(getVipMoney(payRequest.getNum()));
|
|
|
//续费订单
|
|
|
orderDon.setOrderType(2);
|
|
|
orderDon.setMoney(payRequest.getDonMoney());
|
|
|
@@ -274,6 +276,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
//设置订单支付商品信息
|
|
|
orderDon.setPayTitle(Constant.VIP_TITLE);
|
|
|
orderDon.setGoodsId(Constant.VIP_RELATE_GOODS_ID);
|
|
|
+ orderDon.setNum(payRequest.getNum());
|
|
|
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
@@ -364,10 +367,11 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
.in(VipUser::getUserId, userIdList)
|
|
|
.last("limit 1"))).orElse(new VipUser());
|
|
|
vipUser.setUserId(userId);
|
|
|
+ int offsetMonths = orderDon.getNum();
|
|
|
//发放会员车票 普通订单
|
|
|
if (orderDon.getOrderType() == 1) {
|
|
|
vipUser.setStartTime(DateTime.now());
|
|
|
- vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getStartTime(), 1));
|
|
|
+ vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getStartTime(), offsetMonths));
|
|
|
if (vipUser.getId() == null) {
|
|
|
try {
|
|
|
vipUserMapper.insert(vipUser);
|
|
|
@@ -378,7 +382,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
sendVipTicketToUser(vipUser.getUserId(), vipUser.getStartTime(), vipUser.getExpiryTime(), userIdList, orderDon.getId());
|
|
|
} else {
|
|
|
//续费订单
|
|
|
- vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getExpiryTime(), 1));
|
|
|
+ vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getExpiryTime(), offsetMonths));
|
|
|
vipUserMapper.updateById(vipUser);
|
|
|
//续费订单
|
|
|
setTicketToVipExpiryTime(userIdList, vipUser.getUserId(), vipUser.getExpiryTime());
|
|
|
@@ -410,17 +414,41 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
List<GroupsRelationView> groupsRelationViews = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
|
|
|
.field(GroupsRelationView::getUserId, userIds).op(Operator.InList)
|
|
|
.field(GroupsRelationView::getId, deductRelationIds).op(Operator.InList).build());
|
|
|
- deductSkuIds = groupsRelationViews.stream().map(GroupsRelationView::getSkuId).collect(Collectors.toList());
|
|
|
- //将车票弄成会员类型
|
|
|
- relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
- .set(GroupsRelation::getUserId, userId)
|
|
|
- .set(GroupsRelation::getIsVip, Boolean.TRUE)
|
|
|
- .set(GroupsRelation::getStartTime, vipStartTime)
|
|
|
- .set(GroupsRelation::getExpiryTime, vipExpiryTime)
|
|
|
- .in(GroupsRelation::getUserId, userIds)
|
|
|
- .in(GroupsRelation::getId, deductRelationIds));
|
|
|
- //重置镜像user
|
|
|
- resetMirrorUser(groupsRelationViews, vipExpiryTime);
|
|
|
+ deductSkuIds = new ArrayList<>();
|
|
|
+ //不是同规格车票直接清除
|
|
|
+ List<Long> vipSkuIds = skus.stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<VipGoodsSku>> vipGoodsSkuMap = skus.stream().collect(Collectors.groupingBy(VipGoodsSku::getGoodsId));
|
|
|
+ for (GroupsRelationView groupsRelationView : groupsRelationViews) {
|
|
|
+ Long goodsId = groupsRelationView.getGoodsId();
|
|
|
+ Long skuId = groupsRelationView.getSkuId();
|
|
|
+ Long relationId = groupsRelationView.getId();
|
|
|
+ Long newRelationId = relationId;
|
|
|
+ Long vipSkuId = skuId;
|
|
|
+ if (vipSkuIds.contains(skuId)) {
|
|
|
+ //同规格抵扣会员
|
|
|
+ //将车票弄成会员类型
|
|
|
+ relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
+ .set(GroupsRelation::getUserId, userId)
|
|
|
+ .set(GroupsRelation::getIsVip, Boolean.TRUE)
|
|
|
+ .set(GroupsRelation::getStartTime, vipStartTime)
|
|
|
+ .set(GroupsRelation::getExpiryTime, vipExpiryTime)
|
|
|
+ .in(GroupsRelation::getUserId, userIds)
|
|
|
+ .eq(GroupsRelation::getId, relationId));
|
|
|
+ } else {
|
|
|
+ //获取对应类型 会员规格id
|
|
|
+ List<VipGoodsSku> thisGoodsVipSkuIds = vipGoodsSkuMap.get(goodsId);
|
|
|
+ vipSkuId = thisGoodsVipSkuIds.get(0).getSkuId();
|
|
|
+ newRelationId = groupRelationFrontService.getTicket(userId, vipSkuId, Boolean.TRUE);
|
|
|
+ GroupsRelation relation = relationMapper.selectById(relationId);
|
|
|
+ relation.setNewRelationId(newRelationId);
|
|
|
+ //清除不是同规格旧车票
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.vip_deduct);
|
|
|
+ }
|
|
|
+ //抵扣规格
|
|
|
+ deductSkuIds.add(vipSkuId);
|
|
|
+ //重置镜像user
|
|
|
+ resetMirrorUser(goodsId, vipSkuId, relationId, newRelationId, vipExpiryTime);
|
|
|
+ }
|
|
|
}
|
|
|
for (VipGoodsSku sku : skus) {
|
|
|
//未有抵扣 直接发送会员车票
|
|
|
@@ -436,10 +464,10 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
deductBalancePayOrderMoney(orderDon, balance, user);
|
|
|
}
|
|
|
|
|
|
- private VipDeductDto getVipMoneyIfDeduct(User user, Boolean isDeduct) {
|
|
|
+ private VipDeductDto getVipMoneyIfDeduct(User user, Boolean isDeduct, Integer months) {
|
|
|
//若用户抵扣
|
|
|
if (isDeduct) {
|
|
|
- return vipFrontService.checkAndGetOrderDeductMoney(user.getId());
|
|
|
+ return vipFrontService.checkAndGetOrderDeductMoney(user.getId(), months);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -492,15 +520,19 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
.eq(GroupsRelation::getIsVip, Boolean.TRUE));
|
|
|
}
|
|
|
|
|
|
- private BigDecimal getVipMoney() {
|
|
|
+ private BigDecimal getVipMoney(Integer num) {
|
|
|
SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
.eq(SysConfig::getSysKey, Constant.VIP_FEE_KEY)
|
|
|
.last("limit 1"));
|
|
|
if (sysConfig == null || StrUtil.isEmpty(sysConfig.getSysValue())) {
|
|
|
throw BusinessRuntimeException.getInstance("系统异常");
|
|
|
}
|
|
|
+ //校验月数
|
|
|
+ if (num != 1 && num != 3 && num != 12) {
|
|
|
+ throw BusinessRuntimeException.getInstance("购买的会员月数错误");
|
|
|
+ }
|
|
|
BigDecimal vipFee = BigDecimal.valueOf(Long.valueOf(sysConfig.getSysValue()));
|
|
|
- return vipFee;
|
|
|
+ return vipFee.multiply(BigDecimal.valueOf(num));
|
|
|
}
|
|
|
|
|
|
private void recordVipDeductRelationIds(Long orderId, Long userId, List<Long> deductRelationIds) {
|
|
|
@@ -514,94 +546,94 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
/**
|
|
|
* 重置镜像user
|
|
|
*/
|
|
|
- private void resetMirrorUser(List<GroupsRelationView> groupsRelationViews, Date vipExpiryTime) {
|
|
|
- for (GroupsRelationView groupsRelationView : groupsRelationViews) {
|
|
|
- Long skuId = groupsRelationView.getSkuId();
|
|
|
- Long goodsId = groupsRelationView.getGoodsId();
|
|
|
- Long relationId = groupsRelationView.getId();
|
|
|
- GoodsDonSku sku = skuMapper.selectById(skuId);
|
|
|
- if (goodsId == Constant.MJ_GID) {
|
|
|
- MidjourneyUser user = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
|
|
|
- .eq(MidjourneyUser::getRelationId, relationId)
|
|
|
- .last("limit 1"));
|
|
|
- if (user != null) {
|
|
|
- user.setMjFastNum(sku.getMjFastNum());
|
|
|
- user.setMjRelaxNum(sku.getMjRelaxNum());
|
|
|
- user.setIsVip(Boolean.TRUE);
|
|
|
- user.setExpireTime(vipExpiryTime);
|
|
|
- midjourneyUserMapper.updateById(user);
|
|
|
- redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + user.getUserToken());
|
|
|
- }
|
|
|
+ private void resetMirrorUser(Long goodsId, Long skuId, Long oldRelationId, Long newRelationId, Date vipExpiryTime) {
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(skuId);
|
|
|
+ if (goodsId == Constant.MJ_GID) {
|
|
|
+ MidjourneyUser user = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
|
|
|
+ .eq(MidjourneyUser::getRelationId, oldRelationId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (user != null) {
|
|
|
+ user.setMjFastNum(sku.getMjFastNum());
|
|
|
+ user.setMjRelaxNum(sku.getMjRelaxNum());
|
|
|
+ user.setIsVip(Boolean.TRUE);
|
|
|
+ user.setExpireTime(vipExpiryTime);
|
|
|
+ user.setRelationId(newRelationId);
|
|
|
+ midjourneyUserMapper.updateById(user);
|
|
|
+ redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + user.getUserToken());
|
|
|
}
|
|
|
- if (goodsId == Constant.GPT_PLUS_GID) {
|
|
|
- ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
|
|
|
- .eq(ChatgptUser::getRelationId, relationId)
|
|
|
- .last("limit 1"));
|
|
|
- if (chatgptUser != null) {
|
|
|
- chatgptUser.setLimitNum(sku.getGptLimitNum());
|
|
|
- chatgptUser.setLimitTime(sku.getGptLimitTime());
|
|
|
- chatgptUser.setDsLimitNum(sku.getDsLimitNum());
|
|
|
- chatgptUser.setDsLimitTime(sku.getDsLimitTime());
|
|
|
- chatgptUser.setOtherLimitNum(sku.getOtherLimitNum());
|
|
|
- chatgptUser.setOtherLimitTime(sku.getOtherLimitTime());
|
|
|
- chatgptUser.setPackageId(0l);
|
|
|
- chatgptUser.setClearPackageTime(null);
|
|
|
- chatgptUser.setRenewOrderId(0l);
|
|
|
- chatgptUser.setRenewSkuId(null);
|
|
|
- chatgptUser.setRenewExpiryTime(null);
|
|
|
- chatgptUser.setIsVip(Boolean.TRUE);
|
|
|
- chatgptUser.setExpireTime(vipExpiryTime);
|
|
|
- chatgptUserMapper.updateById(chatgptUser);
|
|
|
- try {
|
|
|
- //清除次数
|
|
|
- chatGptAccountService.clearGptNum(relationId);
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (goodsId == Constant.GPT_PLUS_GID) {
|
|
|
+ ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
|
|
|
+ .eq(ChatgptUser::getRelationId, oldRelationId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (chatgptUser != null) {
|
|
|
+ chatgptUser.setLimitNum(sku.getGptLimitNum());
|
|
|
+ chatgptUser.setLimitTime(sku.getGptLimitTime());
|
|
|
+ chatgptUser.setDsLimitNum(sku.getDsLimitNum());
|
|
|
+ chatgptUser.setDsLimitTime(sku.getDsLimitTime());
|
|
|
+ chatgptUser.setOtherLimitNum(sku.getOtherLimitNum());
|
|
|
+ chatgptUser.setOtherLimitTime(sku.getOtherLimitTime());
|
|
|
+ chatgptUser.setPackageId(0l);
|
|
|
+ chatgptUser.setClearPackageTime(null);
|
|
|
+ chatgptUser.setRenewOrderId(0l);
|
|
|
+ chatgptUser.setRenewSkuId(null);
|
|
|
+ chatgptUser.setRenewExpiryTime(null);
|
|
|
+ chatgptUser.setIsVip(Boolean.TRUE);
|
|
|
+ chatgptUser.setExpireTime(vipExpiryTime);
|
|
|
+ chatgptUser.setRelationId(newRelationId);
|
|
|
+ chatgptUserMapper.updateById(chatgptUser);
|
|
|
+ try {
|
|
|
+ //清除次数
|
|
|
+ chatGptAccountService.clearGptNum(oldRelationId);
|
|
|
+ } catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
- if (goodsId == Constant.CALUDE_GOODS_ID) {
|
|
|
- ClaudeUser claudeUser = claudeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeUser.class)
|
|
|
- .eq(ClaudeUser::getRelationId, relationId)
|
|
|
- .last("limit 1"));
|
|
|
- if (claudeUser != null) {
|
|
|
- claudeUser.setLimitNum(sku.getGptLimitNum());
|
|
|
- claudeUser.setLimitTime(sku.getGptLimitTime());
|
|
|
- claudeUser.setRenewOrderId(null);
|
|
|
- claudeUser.setRenewExpiryTime(null);
|
|
|
- claudeUser.setRenewSkuId(null);
|
|
|
- claudeUser.setIsVip(Boolean.TRUE);
|
|
|
- claudeUser.setExpireTime(vipExpiryTime);
|
|
|
- claudeUserMapper.updateById(claudeUser);
|
|
|
- try {
|
|
|
- //清除次数
|
|
|
- claudeService.clearNum(claudeUser.getUserToken());
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (goodsId == Constant.CALUDE_GOODS_ID) {
|
|
|
+ ClaudeUser claudeUser = claudeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeUser.class)
|
|
|
+ .eq(ClaudeUser::getRelationId, oldRelationId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (claudeUser != null) {
|
|
|
+ claudeUser.setLimitNum(sku.getGptLimitNum());
|
|
|
+ claudeUser.setLimitTime(sku.getGptLimitTime());
|
|
|
+ claudeUser.setRenewOrderId(null);
|
|
|
+ claudeUser.setRenewExpiryTime(null);
|
|
|
+ claudeUser.setRenewSkuId(null);
|
|
|
+ claudeUser.setIsVip(Boolean.TRUE);
|
|
|
+ claudeUser.setExpireTime(vipExpiryTime);
|
|
|
+ claudeUser.setRelationId(newRelationId);
|
|
|
+ claudeUserMapper.updateById(claudeUser);
|
|
|
+ try {
|
|
|
+ //清除次数
|
|
|
+ claudeService.clearNum(claudeUser.getUserToken());
|
|
|
+ } catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
- if (goodsId == Constant.GROK_GOODS_ID) {
|
|
|
- GrokUser grokUser = grokUserMapper.selectOne(Wrappers.lambdaQuery(GrokUser.class)
|
|
|
- .eq(GrokUser::getRelationId, relationId)
|
|
|
- .last("limit 1"));
|
|
|
- if (grokUser != null) {
|
|
|
- grokUser.setLimitNum(sku.getGptLimitNum());
|
|
|
- grokUser.setLimitTime(sku.getGptLimitTime());
|
|
|
- grokUser.setIsVip(Boolean.TRUE);
|
|
|
- grokUser.setExpireTime(vipExpiryTime);
|
|
|
- grokUserMapper.updateById(grokUser);
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (goodsId == Constant.GROK_GOODS_ID) {
|
|
|
+ GrokUser grokUser = grokUserMapper.selectOne(Wrappers.lambdaQuery(GrokUser.class)
|
|
|
+ .eq(GrokUser::getRelationId, oldRelationId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (grokUser != null) {
|
|
|
+ grokUser.setLimitNum(sku.getGptLimitNum());
|
|
|
+ grokUser.setLimitTime(sku.getGptLimitTime());
|
|
|
+ grokUser.setIsVip(Boolean.TRUE);
|
|
|
+ grokUser.setExpireTime(vipExpiryTime);
|
|
|
+ grokUser.setRelationId(newRelationId);
|
|
|
+ grokUserMapper.updateById(grokUser);
|
|
|
}
|
|
|
- if (goodsId == Constant.LUMA_GOODS_ID) {
|
|
|
- LumaUser lumaUser = lumaUserMapper.selectOne(Wrappers.lambdaQuery(LumaUser.class)
|
|
|
- .eq(LumaUser::getRelationId, relationId)
|
|
|
- .last("limit 1"));
|
|
|
- if (lumaUser != null) {
|
|
|
- lumaUser.setNum(sku.getLumaNum());
|
|
|
- lumaUser.setIsVip(Boolean.TRUE);
|
|
|
- lumaUser.setExpireTime(vipExpiryTime);
|
|
|
- lumaUserMapper.updateById(lumaUser);
|
|
|
- redisService.del(RedisService.key.LUMA_NUM_LIMIT.getName() + lumaUser.getId());
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (goodsId == Constant.LUMA_GOODS_ID) {
|
|
|
+ LumaUser lumaUser = lumaUserMapper.selectOne(Wrappers.lambdaQuery(LumaUser.class)
|
|
|
+ .eq(LumaUser::getRelationId, oldRelationId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (lumaUser != null) {
|
|
|
+ lumaUser.setNum(sku.getLumaNum());
|
|
|
+ lumaUser.setIsVip(Boolean.TRUE);
|
|
|
+ lumaUser.setExpireTime(vipExpiryTime);
|
|
|
+ lumaUser.setRelationId(newRelationId);
|
|
|
+ lumaUserMapper.updateById(lumaUser);
|
|
|
+ redisService.del(RedisService.key.LUMA_NUM_LIMIT.getName() + lumaUser.getId());
|
|
|
}
|
|
|
}
|
|
|
}
|