|
|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.user.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -14,16 +15,15 @@ import com.cyksj.common.util.Codec;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
|
-import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
-import com.cyksj.mapper.PhoneCodeMapper;
|
|
|
-import com.cyksj.mapper.GiftCardUserRecordMapper;
|
|
|
-import com.cyksj.mapper.UserMapper;
|
|
|
+import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.channel.ChannelPopularizeMapper;
|
|
|
import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.LoginReq;
|
|
|
+import com.cyksj.model.views.RenewalView;
|
|
|
+import com.cyksj.model.views.UserTicketView;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
|
import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
|
|
|
@@ -31,8 +31,12 @@ import com.cyksj.service.exchange.ExchangeCodeService;
|
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
|
import com.cyksj.service.market.task.BindTaskService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
+import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.param.Operator;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
@@ -40,7 +44,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
@@ -85,6 +88,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
|
|
|
+ private final GroupsRelationMapper groupsRelationMapper;
|
|
|
+
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final UserBindRelationService userBindRelationService;
|
|
|
+
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
@Override
|
|
|
@@ -508,7 +517,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
- public void receiveGiftCardByRc(Long userId, String code) {
|
|
|
+ public void receiveGiftCardByRc(Long userId, String code, Long relationId) {
|
|
|
GiftCardUserRecord giftCardUserRecord = giftCardUserRecordMapper.selectOne(Wrappers.lambdaQuery(GiftCardUserRecord.class)
|
|
|
.eq(GiftCardUserRecord::getRc, code).last("limit 1"));
|
|
|
if (giftCardUserRecord == null) {
|
|
|
@@ -546,11 +555,60 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
log.info("礼品卡id:{}虚拟车票skuId:{}不存在", giftCardUserRecord.getId(), gcSkuId);
|
|
|
throw BusinessRuntimeException.getInstance("该礼品卡对应的虚拟卡不存在,请联系客服");
|
|
|
}
|
|
|
- GroupsRelation relationNoOrder = exchangeCodeService.getRelationNoOrder(sku, userId);
|
|
|
- giftCardUserRecordMapper.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
|
|
|
- .set(GiftCardUserRecord::getRelationId, relationNoOrder.getId())
|
|
|
- .eq(GiftCardUserRecord::getId, giftCardUserRecord.getId()));
|
|
|
- log.info("发送至用户userId:{}礼品卡虚拟车票结束", userId);
|
|
|
+ List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
+ if (relationId != null) {
|
|
|
+ GroupsRelation groupsRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .in(GroupsRelation::getUserId, relationUserIdList)
|
|
|
+ .eq(GroupsRelation::getId, relationId)
|
|
|
+ .in(GroupsRelation::getStatus, List.of(GroupsRelation.Status.validity, GroupsRelation.Status.outside)).last("limit 1"));
|
|
|
+ if (groupsRelation == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您选择的车票不存在");
|
|
|
+ }
|
|
|
+ Date expiryTime = groupsRelation.getExpiryTime();
|
|
|
+ if (expiryTime == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请等您该类型下的车票配置账号后再增加对应时长");
|
|
|
+ }
|
|
|
+ if (sku.getDays() != null && sku.getDays() > 0) {
|
|
|
+ expiryTime = DateUtil.offsetDay(expiryTime, sku.getDays());
|
|
|
+ } else {
|
|
|
+ expiryTime = DateUtil.offsetMonth(expiryTime, sku.getMonths());
|
|
|
+ }
|
|
|
+ log.info("userId:{}领取虚拟卡skuId:{},增加车票时长至:{}", userId, sku.getId(), expiryTime.toString());
|
|
|
+ groupsRelation.setExpiryTime(expiryTime);
|
|
|
+ groupsRelationMapper.updateById(groupsRelation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //是否存在对应车票
|
|
|
+ List<UserTicketView> ticketViews = beanSearcher.searchAll(UserTicketView.class, MapUtils.builder()
|
|
|
+ .field(UserTicketView::getUserId, relationUserIdList).op(Operator.InList)
|
|
|
+ .field(UserTicketView::getGoodsId, giftCardUserRecord.getGcGoodsId())
|
|
|
+ .field(RenewalView::getStatus, List.of("validity", "outside")).op(Operator.InList)
|
|
|
+ .orderBy(UserTicketView::getRelationId).asc()
|
|
|
+ .build());
|
|
|
+ if (CollUtil.isEmpty(ticketViews)) {
|
|
|
+ GroupsRelation relationNoOrder = exchangeCodeService.getRelationNoOrder(sku, userId);
|
|
|
+ giftCardUserRecordMapper.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
|
|
|
+ .set(GiftCardUserRecord::getRelationId, relationNoOrder.getId())
|
|
|
+ .eq(GiftCardUserRecord::getId, giftCardUserRecord.getId()));
|
|
|
+ log.info("用户未有该规格:{}车票,发送至用户userId:{}礼品卡虚拟车票结束", gcSkuId, userId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ticketViews.size() > 1) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您有多张该类型的车票,请选择一张增加时长");
|
|
|
+ }
|
|
|
+ UserTicketView userTicketView = ticketViews.get(0);
|
|
|
+ Date expiryTime = userTicketView.getExpiryTime();
|
|
|
+ if (expiryTime == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请等您该类型下的车票配置账号后再增加对应时长");
|
|
|
+ }
|
|
|
+ if (sku.getDays() != null && sku.getDays() > 0) {
|
|
|
+ expiryTime = DateUtil.offsetDay(expiryTime, sku.getDays());
|
|
|
+ } else {
|
|
|
+ expiryTime = DateUtil.offsetMonth(expiryTime, sku.getMonths());
|
|
|
+ }
|
|
|
+ groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
+ .set(GroupsRelation::getExpiryTime, expiryTime)
|
|
|
+ .eq(GroupsRelation::getId, userTicketView.getRelationId()));
|
|
|
}
|
|
|
}
|
|
|
}
|