|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.user.impl;
|
|
package com.cyksj.service.user.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
@@ -15,26 +16,33 @@ import com.cyksj.common.util.Codec;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
|
-import com.cyksj.mapper.PhoneCodeMapper;
|
|
|
|
|
-import com.cyksj.mapper.UserMapper;
|
|
|
|
|
|
|
+import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.channel.ChannelPopularizeMapper;
|
|
import com.cyksj.mapper.channel.ChannelPopularizeMapper;
|
|
|
import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
|
|
import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
import com.cyksj.model.dto.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.LoginReq;
|
|
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.redis.RedisService;
|
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
|
import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
|
|
import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
|
|
|
|
|
+import com.cyksj.service.exchange.ExchangeCodeService;
|
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
|
import com.cyksj.service.market.task.BindTaskService;
|
|
import com.cyksj.service.market.task.BindTaskService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
|
|
+import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.cyksj.service.user.UserService;
|
|
import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
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.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -76,6 +84,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
|
|
private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
|
|
private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
|
|
|
|
|
|
|
|
|
|
+ private final GiftCardUserRecordMapper giftCardUserRecordMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final ExchangeCodeService exchangeCodeService;
|
|
|
|
|
+
|
|
|
|
|
+ private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final GroupsRelationMapper groupsRelationMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserBindRelationService userBindRelationService;
|
|
|
|
|
+
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
|
|
private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -514,6 +534,104 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return redisService.getStr(re.getMappingId().toString());
|
|
return redisService.getStr(re.getMappingId().toString());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
|
|
+ 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) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("好友赠送礼品卡不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!giftCardUserRecord.getIsPay()) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("无效礼品卡,好友未购买");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
+ if (relationUserIdList.contains(giftCardUserRecord.getUserId())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("无法领取自己购买的礼品卡");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (giftCardUserRecord.getToUserId() != 0 && !giftCardUserRecord.getToUserId().equals(userId)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("好友赠送礼品卡已被领取");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (giftCardUserRecord.getToUserId().equals(userId)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("您已领取该礼品卡");
|
|
|
|
|
+ }
|
|
|
|
|
+ giftCardUserRecord.setToUserId(userId);
|
|
|
|
|
+ int update = giftCardUserRecordMapper.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
|
|
|
|
|
+ .set(giftCardUserRecord.getGcType() == 2, GiftCardUserRecord::getIsUsed, true)
|
|
|
|
|
+ .set(GiftCardUserRecord::getToUserId, userId)
|
|
|
|
|
+ .set(GiftCardUserRecord::getIsSend, true)
|
|
|
|
|
+ .set(GiftCardUserRecord::getReceivedTime, DateTime.now())
|
|
|
|
|
+ .eq(GiftCardUserRecord::getId, giftCardUserRecord.getId())
|
|
|
|
|
+ .eq(GiftCardUserRecord::getIsPay, true)
|
|
|
|
|
+ .eq(GiftCardUserRecord::getToUserId, 0));
|
|
|
|
|
+ if (update > 0) {
|
|
|
|
|
+ //虚拟卡
|
|
|
|
|
+ //直接发送 对应规格车票
|
|
|
|
|
+ if (giftCardUserRecord.getGcType() == 2) {
|
|
|
|
|
+ Long gcSkuId = giftCardUserRecord.getGcSkuId();
|
|
|
|
|
+ log.info("用户userId:{}领取礼品卡id:{},开始发放虚拟车票skuId:{}", userId, giftCardUserRecord.getId(), gcSkuId);
|
|
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectById(gcSkuId);
|
|
|
|
|
+ if (sku == null) {
|
|
|
|
|
+ log.info("礼品卡id:{}虚拟车票skuId:{}不存在", giftCardUserRecord.getId(), gcSkuId);
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该礼品卡对应的虚拟卡不存在,请联系客服");
|
|
|
|
|
+ }
|
|
|
|
|
+ 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()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 发放新用户福利
|
|
* 发放新用户福利
|
|
|
*/
|
|
*/
|