|
|
@@ -3,6 +3,7 @@ package com.cyksj.service.order.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
@@ -152,6 +153,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
|
|
|
private final UserBalanceSourceRecordMapper userBalanceSourceRecordMapper;
|
|
|
|
|
|
+ private final NanoUserQuotaMapper nanoUserQuotaMapper;
|
|
|
+
|
|
|
private static final Long EXPIRY_TIME = 1000 * 60 * 5L;
|
|
|
|
|
|
@Override
|
|
|
@@ -446,13 +449,27 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
}
|
|
|
} else vipUserMapper.updateById(vipUser);
|
|
|
//发送车票
|
|
|
- sendVipTicketToUser(vipUser.getUserId(), vipUser.getStartTime(), vipUser.getExpiryTime(), userIdList, orderDon.getId());
|
|
|
+ sendVipTicketToUser(orderDon.getNum(), vipUser.getUserId(), vipUser.getStartTime(), vipUser.getExpiryTime(), userIdList, orderDon.getId());
|
|
|
} else {
|
|
|
//续费订单
|
|
|
vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getExpiryTime(), offsetMonths));
|
|
|
vipUserMapper.updateById(vipUser);
|
|
|
//续费订单
|
|
|
setTicketToVipExpiryTime(userIdList, vipUser.getUserId(), vipUser.getExpiryTime());
|
|
|
+
|
|
|
+ //增加nano剩余次数
|
|
|
+ GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getGoodsId, Constant.NANO_GOODS_ID).field(GroupsRelationView::getUserId, userIdList).op(Operator.InList).field(GroupsRelationView::getIsVip, Boolean.TRUE).build());
|
|
|
+ if (groupsRelationView != null) {
|
|
|
+ NanoUserQuota nanoUserQuota = nanoUserQuotaMapper.selectOne(Wrappers.lambdaQuery(NanoUserQuota.class).eq(NanoUserQuota::getRelationId, groupsRelationView.getId()).last("limit 1"));
|
|
|
+ if (nanoUserQuota != null) {
|
|
|
+ Long skuId = groupsRelationView.getSkuId();
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(skuId);
|
|
|
+ Integer offestNum = offsetMonths * sku.getNanoQuota();
|
|
|
+ nanoUserQuota.setTotalQuota(nanoUserQuota.getTotalQuota() + offestNum);
|
|
|
+ nanoUserQuota.setRemainingQuota(nanoUserQuota.getRemainingQuota() + offestNum);
|
|
|
+ nanoUserQuotaMapper.updateById(nanoUserQuota);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
//金额大于0 是否是分销订单
|
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
@@ -466,7 +483,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
deductIfCloseOrderReturnBalance(orderDon.getId(), UserBalanceSourceRecord.Source.vip_order_close);
|
|
|
}
|
|
|
|
|
|
- private void sendVipTicketToUser(Long userId, Date vipStartTime, Date vipExpiryTime, List<Long> userIds, Long orderId) {
|
|
|
+ private void sendVipTicketToUser(Integer num, Long userId, Date vipStartTime, Date vipExpiryTime, List<Long> userIds, Long orderId) {
|
|
|
//是否存在抵扣 抵扣成功 清除车票
|
|
|
VipOrderDonDeductRelation vipOrderDonDeductRelation = vipOrderDonDeductRelationMapper.selectOne(Wrappers.lambdaQuery(VipOrderDonDeductRelation.class)
|
|
|
.eq(VipOrderDonDeductRelation::getOrderId, orderId)
|
|
|
@@ -525,7 +542,12 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
for (VipGoodsSku sku : skus) {
|
|
|
//未有抵扣 直接发送会员车票
|
|
|
if (deductSkuIds == null || !deductSkuIds.contains(sku.getSkuId())) {
|
|
|
- groupRelationFrontService.getTicket(userId, sku.getSkuId(), Boolean.TRUE);
|
|
|
+ Long relationId = groupRelationFrontService.getTicket(userId, sku.getSkuId(), Boolean.TRUE);
|
|
|
+ if (relationId != null && sku.getGoodsId() == Constant.NANO_GOODS_ID) {
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ GoodsDonSku goodsDonSku = skuMapper.selectById(sku.getSkuId());
|
|
|
+ createNanoUser(relationId, user, goodsDonSku.getNanoQuota() * num);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -954,4 +976,22 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
|
|
|
userBalanceSourceRecordMapper.deleteById(userBalanceSourceRecord.getId());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private NanoUserQuota createNanoUser(Long relationId, User user, Integer nanoQuota) {
|
|
|
+ NanoUserQuota nanoUserQuota = new NanoUserQuota();
|
|
|
+ nanoUserQuota.setUid(user.getId());
|
|
|
+ nanoUserQuota.setRelationId(relationId);
|
|
|
+ nanoUserQuota.setUserToken(UUID.randomUUID().toString());
|
|
|
+ nanoUserQuota.setNickname(user.getNickname());
|
|
|
+ nanoUserQuota.setAvatar(user.getHeadimgurl());
|
|
|
+ nanoUserQuota.setPurchaseDate(DateTime.now());
|
|
|
+ nanoUserQuota.setTotalQuota(nanoQuota);
|
|
|
+ nanoUserQuota.setRemainingQuota(nanoUserQuota.getTotalQuota());
|
|
|
+ try {
|
|
|
+ nanoUserQuotaMapper.insert(nanoUserQuota);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return nanoUserQuota;
|
|
|
+ }
|
|
|
}
|