|
@@ -3,6 +3,7 @@ package shop.alien.store.service.impl;
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -20,6 +21,7 @@ import shop.alien.mapper.ActivityInviteConfigMapper;
|
|
|
import shop.alien.mapper.ActivityInviteLogMapper;
|
|
import shop.alien.mapper.ActivityInviteLogMapper;
|
|
|
import shop.alien.mapper.LifeUserMapper;
|
|
import shop.alien.mapper.LifeUserMapper;
|
|
|
import shop.alien.store.service.ActivityInviteConfigService;
|
|
import shop.alien.store.service.ActivityInviteConfigService;
|
|
|
|
|
+import shop.alien.store.service.LifeDiscountCouponService;
|
|
|
import shop.alien.store.service.UserPointService;
|
|
import shop.alien.store.service.UserPointService;
|
|
|
import shop.alien.util.common.RandomCreateUtil;
|
|
import shop.alien.util.common.RandomCreateUtil;
|
|
|
|
|
|
|
@@ -27,8 +29,11 @@ import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -43,6 +48,8 @@ public class ActivityInviteConfigServiceImpl extends ServiceImpl<ActivityInviteC
|
|
|
|
|
|
|
|
private final ActivityInviteLogMapper activityInviteLogMapper;
|
|
private final ActivityInviteLogMapper activityInviteLogMapper;
|
|
|
|
|
|
|
|
|
|
+ private final LifeDiscountCouponService lifeDiscountCouponService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public ActivityInviteConfigVo createOrUpdateInviteActivity(ActivityInviteConfigVo activityInviteConfigVo) {
|
|
public ActivityInviteConfigVo createOrUpdateInviteActivity(ActivityInviteConfigVo activityInviteConfigVo) {
|
|
|
|
|
|
|
@@ -236,9 +243,11 @@ public class ActivityInviteConfigServiceImpl extends ServiceImpl<ActivityInviteC
|
|
|
|
|
|
|
|
if(invitedLifeUser == null){
|
|
if(invitedLifeUser == null){
|
|
|
return "被邀请用户异常";
|
|
return "被邀请用户异常";
|
|
|
- } else if (StringUtils.isNotBlank(invitedLifeUser.getBindInviteCode())){
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.isNotBlank(invitedLifeUser.getBindInviteCode())){
|
|
|
return "已经绑定邀请码不能重复绑定";
|
|
return "已经绑定邀请码不能重复绑定";
|
|
|
- } else if (StringUtils.isNotBlank(invitedLifeUser.getInviteCode()) && invitedLifeUser.getInviteCode().equals(inviteCode)){
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.isNotBlank(invitedLifeUser.getInviteCode()) && invitedLifeUser.getInviteCode().equals(inviteCode)){
|
|
|
return "不能绑定自己的邀请码";
|
|
return "不能绑定自己的邀请码";
|
|
|
}else {
|
|
}else {
|
|
|
LambdaQueryWrapper<ActivityInviteConfig> activityInviteConfigLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<ActivityInviteConfig> activityInviteConfigLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
@@ -282,12 +291,22 @@ public class ActivityInviteConfigServiceImpl extends ServiceImpl<ActivityInviteC
|
|
|
activityInviteLog.setInviteTime(Date.from(Instant.now()));
|
|
activityInviteLog.setInviteTime(Date.from(Instant.now()));
|
|
|
activityInviteLogMapper.insert(activityInviteLog);
|
|
activityInviteLogMapper.insert(activityInviteLog);
|
|
|
|
|
|
|
|
|
|
+ //邀请奖励类型:2 积分
|
|
|
if(activityInviteConfig.getInviteRewardType() == 2){
|
|
if(activityInviteConfig.getInviteRewardType() == 2){
|
|
|
userPointService.addPoint(inviteUserId, activityInviteConfig.getInviteRewardPoint());
|
|
userPointService.addPoint(inviteUserId, activityInviteConfig.getInviteRewardPoint());
|
|
|
}
|
|
}
|
|
|
|
|
+ //邀请奖励类型:1 优惠券
|
|
|
|
|
+ else if(activityInviteConfig.getInviteRewardType() == 1 && activityInviteConfig.getInviteRewardCoupon() > 0){
|
|
|
|
|
+ lifeDiscountCouponService.issuePlatformCoupon(Collections.singletonList(inviteUserId), activityInviteConfig.getInviteRewardCoupon());
|
|
|
|
|
+ }
|
|
|
|
|
+ //被邀请奖励类型:2 积分
|
|
|
if(activityInviteConfig.getInvitedRewardType() == 2){
|
|
if(activityInviteConfig.getInvitedRewardType() == 2){
|
|
|
userPointService.addPoint(invitedUserId, activityInviteConfig.getInvitedRewardPoint());
|
|
userPointService.addPoint(invitedUserId, activityInviteConfig.getInvitedRewardPoint());
|
|
|
}
|
|
}
|
|
|
|
|
+ //被邀请奖励类型:1 优惠券
|
|
|
|
|
+ else if (activityInviteConfig.getInvitedRewardType() == 1 && activityInviteConfig.getInvitedRewardCoupon() > 0) {
|
|
|
|
|
+ lifeDiscountCouponService.issuePlatformCoupon(Collections.singletonList(invitedUserId), activityInviteConfig.getInvitedRewardCoupon());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
LifeUser updateLifeUser = new LifeUser();
|
|
LifeUser updateLifeUser = new LifeUser();
|
|
|
updateLifeUser.setId(invitedLifeUser.getId());
|
|
updateLifeUser.setId(invitedLifeUser.getId());
|
|
@@ -301,4 +320,69 @@ public class ActivityInviteConfigServiceImpl extends ServiceImpl<ActivityInviteC
|
|
|
}
|
|
}
|
|
|
return "参数异常";
|
|
return "参数异常";
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public boolean distributionInviteReward(String invitedUserId, int inviteCondition){
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<ActivityInviteLog> activityInviteLogLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ activityInviteLogLambdaQueryWrapper.eq(ActivityInviteLog::getInvitedUserId, invitedUserId);
|
|
|
|
|
+ activityInviteLogLambdaQueryWrapper.eq(ActivityInviteLog::getDeleteFlag, 0);
|
|
|
|
|
+ activityInviteLogLambdaQueryWrapper.eq(ActivityInviteLog::getDistributionStatus, 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 未发放的邀请记录
|
|
|
|
|
+ List<ActivityInviteLog> activityInviteLogList = activityInviteLogMapper.selectList(activityInviteLogLambdaQueryWrapper);
|
|
|
|
|
+ if(CollectionUtils.isEmpty(activityInviteLogList)){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Integer> logIdList = activityInviteLogList.stream()
|
|
|
|
|
+ .map(ActivityInviteLog::getId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if(CollectionUtils.isEmpty(logIdList)){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 邀请记录对应的活动
|
|
|
|
|
+ List<Integer> activityIdList = activityInviteLogList.stream()
|
|
|
|
|
+ .map(ActivityInviteLog::getActivityId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if(CollectionUtils.isEmpty(activityIdList)){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<ActivityInviteConfig> activityInviteConfigList = activityInviteConfigMapper.selectBatchIds(activityIdList);
|
|
|
|
|
+ if(CollectionUtils.isEmpty(activityInviteConfigList)){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<Integer, Integer> inviteConditionMap = activityInviteConfigList.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ ActivityInviteConfig::getId,
|
|
|
|
|
+ ActivityInviteConfig::getInviteCondition
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ for(ActivityInviteLog activityInviteLog : activityInviteLogList){
|
|
|
|
|
+ Integer activityId = activityInviteLog.getActivityId();
|
|
|
|
|
+ if(inviteConditionMap.containsKey(activityId)){
|
|
|
|
|
+ Integer inviteConditionValue = inviteConditionMap.get(activityId);
|
|
|
|
|
+ if(inviteConditionValue != null && !inviteConditionValue.equals(inviteCondition)){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(activityInviteLog.getInviteRewardType() == 2){
|
|
|
|
|
+ userPointService.addPoint(activityInviteLog.getInviteUserId(), activityInviteLog.getInviteRewardPoint());
|
|
|
|
|
+ } else if(activityInviteLog.getInviteRewardType() == 1 && activityInviteLog.getInviteRewardCoupon() > 0){
|
|
|
|
|
+ lifeDiscountCouponService.issuePlatformCoupon(Collections.singletonList(activityInviteLog.getInviteUserId()), activityInviteLog.getInviteRewardCoupon());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(activityInviteLog.getInvitedRewardType() == 2){
|
|
|
|
|
+ userPointService.addPoint(activityInviteLog.getInvitedUserId(), activityInviteLog.getInvitedRewardPoint());
|
|
|
|
|
+ } else if (activityInviteLog.getInvitedRewardType() == 1 && activityInviteLog.getInvitedRewardCoupon() > 0) {
|
|
|
|
|
+ lifeDiscountCouponService.issuePlatformCoupon(Collections.singletonList(activityInviteLog.getInvitedUserId()), activityInviteLog.getInvitedRewardCoupon());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ LambdaUpdateWrapper<ActivityInviteLog> activityInviteLogLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ activityInviteLogLambdaUpdateWrapper.in(ActivityInviteLog::getId, logIdList);
|
|
|
|
|
+ activityInviteLogLambdaUpdateWrapper.set(ActivityInviteLog::getDistributionStatus, 1);
|
|
|
|
|
+ activityInviteLogMapper.update(null, activityInviteLogLambdaUpdateWrapper);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|