Jelajahi Sumber

Merge branch 'dev' into 'mp-server-test'

Dev

See merge request quanshu/mp-server!526
zhong chunping 3 tahun lalu
induk
melakukan
719b5568f8

+ 32 - 10
mp-admin/src/main/java/com/qs/mp/web/controller/api/channel/ChannelController.java

@@ -22,6 +22,7 @@ import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.core.page.TableDataInfo;
 import com.qs.mp.common.enums.ChannelCertifyStatusEnum;
 import com.qs.mp.common.enums.ChannelRoleEnum;
+import com.qs.mp.common.enums.ChannelStatusEnum;
 import com.qs.mp.common.enums.ChannelVerifyStatusEnum;
 import com.qs.mp.common.enums.ErrorCodeEnum;
 import com.qs.mp.common.exception.ServiceException;
@@ -80,10 +81,10 @@ public class ChannelController extends BaseApiController {
 
     @Autowired
     private ISysUserService userService;
-    
+
 	@Autowired
 	private IUserTicketOrderService userTicketOrderService;
-    
+
 	@Autowired
 	private ITicketService ticketService;
 
@@ -163,6 +164,10 @@ public class ChannelController extends BaseApiController {
 			return AjaxResult.error("该代理已存在");
 		}
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		Channel existChannel = channelService.getById(channelId);
+		if (existChannel.getStatus() == ChannelStatusEnum.OFF) {
+			return AjaxResult.error("账号异常");
+		}
 		Channel channel = mapperFacade.map(channelParam, Channel.class);
 		channel.setParentId(channelId);
 		// 1、校验名称是否重复、手机号是否存在(渠道表)
@@ -209,6 +214,7 @@ public class ChannelController extends BaseApiController {
 		if (null == channelParam || null == channelParam.getChannelId()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 		}
+
 		Channel channel = mapperFacade.map(channelParam, Channel.class);
 		// 1、校验修改子渠道是否为当前用户的子渠道
 		Channel oldChannel = channelService.getById(channel.getChannelId());
@@ -216,6 +222,10 @@ public class ChannelController extends BaseApiController {
 			return AjaxResult.error("代理'" + oldChannel.getName() + "'编辑失败");
 		}
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		Channel existChannel = channelService.getById(channelId);
+		if (existChannel.getStatus() == ChannelStatusEnum.OFF) {
+			return AjaxResult.error("账号异常");
+		}
 		if(!oldChannel.getParentId().equals(channelId)) {
 			return AjaxResult.error("代理'" + oldChannel.getName() + "'编辑失败");
 		}
@@ -360,7 +370,7 @@ public class ChannelController extends BaseApiController {
 				queryWrapper.eq("t1.certify_status", siteParam.getCertifyStatus());
 			}
 			list = channelService.selectChannelVoList(queryWrapper);
-			
+
 			List<Long> channelIds = new ArrayList<Long>();
 			if(null != list && list.size() > 0) {
 				for(ChannelVO channelVO : list) {
@@ -376,13 +386,13 @@ public class ChannelController extends BaseApiController {
 				QueryWrapper<ChannelOrderDetail> ticketQtyCntQueryWrapper = new QueryWrapper<ChannelOrderDetail>();
 				ticketQtyCntQueryWrapper.in("t1.channel_id", channelIds);
 				qtyCntList = ticketService.listTicketQtyCnt(ticketQtyCntQueryWrapper);
-				
+
 		    	QueryWrapper<UserTicketOrder> ticketSaleCntQueryWrapper = new QueryWrapper<UserTicketOrder>();
 		    	ticketSaleCntQueryWrapper.in("t1.channel_id", channelIds);
 		    	ticketSaleCntQueryWrapper.eq("t1.`status`", 1);
 		    	saleCntList = userTicketOrderService.listTicketSaleCnt(ticketSaleCntQueryWrapper);
 			}
-			
+
 			if(null != list && list.size() > 0) {
 				for(ChannelVO channelVO : list) {
 					if(null != channelVO && null != channelVO.getChannelId()
@@ -413,7 +423,7 @@ public class ChannelController extends BaseApiController {
 	 				}
 				}
 			}
-			
+
 		}
 		return getDataTable(list);
 	}
@@ -443,20 +453,20 @@ public class ChannelController extends BaseApiController {
 	    ChannelOperDataVO channelOperDataVO = channelService.getChannelOperData(channelVO.getChannelNo(), 1);
 	    channelVO.setOperData(channelOperDataVO);
 	    if(null != channelVO && null != channelVO.getChannelId()) {
-	    	
+
 	    	LambdaQueryWrapper<ChannelUserRel> userCntQueryWrapper = new LambdaQueryWrapper<ChannelUserRel>();
 			userCntQueryWrapper.eq(ChannelUserRel::getChannelId, channelVO.getChannelId());
 			int userCnt = channelUserRelService.count(userCntQueryWrapper);
 			channelVO.setUserCnt(userCnt);
-	    	
+
 	    	int ticketQtyCnt = ticketService.getTicketQtyCnt(channelVO.getChannelId());
 	    	channelVO.setOffLineQtyCnt(ticketQtyCnt);
-	    	
+
 	    	TicketCntVO ticketSaleCnt = userTicketOrderService.getTicketSaleCnt(channelVO.getChannelId());
 			channelVO.setOffLineSaleCnt(null != ticketSaleCnt?ticketSaleCnt.getOffLineSaleCnt():0);
 			channelVO.setOnLineSaleCnt(null != ticketSaleCnt?ticketSaleCnt.getOnLineSaleCnt():0);
 	    }
-	   
+
 		return AjaxResult.success(channelVO);
 	}
 
@@ -472,6 +482,10 @@ public class ChannelController extends BaseApiController {
 			return AjaxResult.error("该门店已存在");
 		}
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		Channel existChannel = channelService.getById(channelId);
+		if (existChannel.getStatus() == ChannelStatusEnum.OFF) {
+			return AjaxResult.error("账号异常");
+		}
 
 		Channel channel = mapperFacade.map(channelParam, Channel.class);
 		channel.setParentId(channelId);
@@ -526,6 +540,10 @@ public class ChannelController extends BaseApiController {
 			return AjaxResult.error("门店'" + oldChannel.getName() + "'编辑失败");
 		}
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		Channel existChannel = channelService.getById(channelId);
+		if (existChannel.getStatus() == ChannelStatusEnum.OFF) {
+			return AjaxResult.error("账号异常");
+		}
 		if(!oldChannel.getParentId().equals(channelId)) {
 			return AjaxResult.error("门店'" + oldChannel.getName() + "'编辑失败");
 		}
@@ -583,6 +601,10 @@ public class ChannelController extends BaseApiController {
 		}
 
 		Long parentlId = SecurityUtils.getLoginUser().getChannelId();
+		Channel existChannel = channelService.getById(parentlId);
+		if (existChannel.getStatus() == ChannelStatusEnum.OFF) {
+			return AjaxResult.error("账号异常");
+		}
 		Channel queryChannel = channelService.getById(channel.getChannelId());
 		if(null == queryChannel || null == queryChannel.getChannelId()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);

+ 4 - 3
mp-admin/src/main/java/com/qs/mp/web/controller/api/channel/ChannelWithdrawController.java

@@ -27,6 +27,7 @@ import com.qs.mp.channel.service.IChannelWithdrawService;
 import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.core.redis.RedisCache;
 import com.qs.mp.common.domain.param.BatchLongIdsParam;
+import com.qs.mp.common.enums.ChannelStatusEnum;
 import com.qs.mp.common.utils.StringUtils;
 import com.qs.mp.system.service.ISysConfigService;
 import com.qs.mp.utils.SecurityUtils;
@@ -92,9 +93,9 @@ public class ChannelWithdrawController extends BaseApiController {
         StringUtils.isNotBlank(feeRateValue) ? feeRateValue : FEE_RATE_DEFAULT_VALUE);
     Long channelId = SecurityUtils.getLoginUser().getChannelId();
     Channel channel = channelService.getById(channelId);
-    /*if (channel.getMoney() < 50000) {
-      return AjaxResult.error("账户余额不足500元");
-    }*/
+    if (channel.getStatus() == ChannelStatusEnum.OFF) {
+      return AjaxResult.error("账号异常");
+    }
     if (param.getMoney() > channel.getMoney() ) {
       return AjaxResult.error("提现金额超出了余额");
     }

+ 4 - 2
mp-admin/src/main/java/com/qs/mp/web/controller/api/channel/mall/ChannelOrderController.java

@@ -200,9 +200,11 @@ public class ChannelOrderController extends BaseApiController {
   public AjaxResult settle(@Valid @RequestBody ChannelOrderParam param) {
     Long userId = SecurityUtils.getLoginUser().getUserId();
     Long channelId = SecurityUtils.getLoginUser().getChannelId();
-
+    Channel channel = channelService.getById(channelId);
+    if (channel.getStatus() == ChannelStatusEnum.OFF) {
+      return AjaxResult.error("账号异常");
+    }
     ChannelOrderSettleVO orderSettleVO = new ChannelOrderSettleVO();
-
     // 收货地址,如果用户选了地址,则此处不做处理
     if (null == param.getAddrId() || 0 == param.getAddrId()) {
       //读取默认地址

+ 1 - 59
mp-admin/src/main/java/com/qs/mp/web/controller/api/user/MarketingController.java

@@ -74,65 +74,7 @@ public class MarketingController extends BaseApiController {
             return AjaxResult.error("用户未登录");
         }
 
-
-        String inviteCode = marketingHelpParam.getInviteCode();
-        if (StringUtils.isBlank(inviteCode)) {
-            return AjaxResult.error("邀请码不能为空");
-        }
-
-        Marketing marketing = marketingService.getById(marketingHelpParam.getMarketingId());
-        if (Objects.isNull(marketing)) {
-            return AjaxResult.error("活动不存在");
-        }
-        // 未开启的活动不能助力
-        if (MarketingStatusEnum.ON.getValue().equals(marketing.getIsOn())) {
-            return AjaxResult.error("活动未开启~");
-        }
-        Date now = DateUtils.getNowDate();
-        // 结束的活动不支持助力
-        if (marketing.getTriggerStatus() == 1 || marketing.getEndTime().before(now)) {
-            return AjaxResult.error("活动已过期~");
-        }
-        // 未开始的活动不能助力
-        if (marketing.getStartTime().after(now)) {
-            return AjaxResult.error("活动未开始~");
-        }
-
-
-        // 判断是否已经助力过
-        int count = marketingUserCodeService.count(new LambdaQueryWrapper<MarketingUserCode>()
-                .eq(MarketingUserCode::getUserId, userId)
-                .eq(MarketingUserCode::getMarketingId, marketingHelpParam.getMarketingId()));
-        if (count > 0) {
-            return AjaxResult.error("您已经助力过了");
-        }
-
-        // 邀请码解码,被助力人id
-        Long helpedUserId = MarketingUtils.decodeInviteCode(inviteCode);
-
-        // 生成抽奖码
-        String code = "";
-        while (true) {
-            code = MarketingUtils.generatePrizeCode();
-            // 判断抽奖码是否已经存在
-            int codeCount = marketingUserCodeService.count(new LambdaQueryWrapper<MarketingUserCode>()
-                    .eq(MarketingUserCode::getCode, code));
-            if (codeCount > 0) {
-                continue;
-            }
-            break;
-        }
-
-        MarketingUserCode marketingUserCode = new MarketingUserCode();
-        marketingUserCode.setMarketingId(marketingHelpParam.getMarketingId());
-        marketingUserCode.setCode(code);
-        // 设置被助力人
-        marketingUserCode.setUserId(helpedUserId);
-        // 设置助力人
-        marketingUserCode.setHelpUserId(userId);
-        marketingUserCode.setUserType(UserTypeEnum.ORDINARY.getValue());
-
-        marketingUserCodeService.save(marketingUserCode);
+        marketingService.help(marketingHelpParam, userId);
         return AjaxResult.success("助力成功");
     }
 

+ 5 - 0
mp-admin/src/main/resources/application-dev.yml

@@ -132,3 +132,8 @@ miniprogram:
 export:
     page-size: 200
 
+# 运费默认模板配置
+shipping:
+    user: 4
+    channel: 7
+

+ 6 - 2
mp-admin/src/test/java/com/qs/mp/service/ServiceImplTest.java

@@ -2,11 +2,13 @@ package com.qs.mp.service;
 
 import com.qs.mp.MpApplication;
 import com.qs.mp.admin.service.ITicketBoxSerialService;
+import com.qs.mp.common.utils.DateUtils;
 import com.qs.mp.framework.service.IWxUrlLinkService;
 import com.qs.mp.quartz.task.DayStatTask;
 import com.qs.mp.quartz.task.TicketBoxTask;
 import com.qs.mp.quartz.task.TicketPkgDataTask;
 import java.io.IOException;
+import java.util.Date;
 import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -106,7 +108,7 @@ public class ServiceImplTest {
       System.out.println(randInt);
     }
   */
-    String s = "z";
+    /*String s = "z";
 
     int i = Character.codePointAt(s, 0);
 
@@ -114,7 +116,9 @@ public class ServiceImplTest {
 
     char[] a = Character.toChars(72);
 
-    System.out.println(new String(a));
+    System.out.println(new String(a));*/
+    System.out.println(DateUtils.dateTime());
+    System.out.println(new Date().getTime());
   }
 
   }

+ 7 - 0
mp-common/pom.xml

@@ -22,6 +22,13 @@
 
     <dependencies>
 
+        <!-- redisson -->
+        <dependency>
+            <groupId>org.redisson</groupId>
+            <artifactId>redisson-spring-boot-starter</artifactId>
+            <version>3.16.8</version>
+        </dependency>
+
         <!-- swagger 增强-->
         <dependency>
             <groupId>com.github.xiaoymin</groupId>

+ 29 - 0
mp-common/src/main/java/com/qs/mp/common/core/redis/DistributedLocker.java

@@ -0,0 +1,29 @@
+package com.qs.mp.common.core.redis;
+
+import org.redisson.api.RLock;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Cup
+ * @date 2022/5/18
+ */
+public interface DistributedLocker {
+
+    RLock lock(String lockKey);
+
+    RLock lock(String lockKey, long leaseTime);
+
+    RLock lock(String lockKey, long leaseTime, TimeUnit unit);
+
+    RLock getLock(String lockKey);
+
+    boolean tryLock(String lockKey);
+
+    boolean tryLock(String lockKey, long waitTime, long leaseTime, TimeUnit unit);
+
+    void unlock(String lockKey);
+
+    void unlock(RLock lock);
+
+}

+ 76 - 0
mp-common/src/main/java/com/qs/mp/common/core/redis/RedissonDistributedLocker.java

@@ -0,0 +1,76 @@
+package com.qs.mp.common.core.redis;
+
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Cup
+ * @date 2022/5/18
+ */
+@Component
+public class RedissonDistributedLocker implements DistributedLocker {
+
+    @Autowired
+    private RedissonClient redissonClient;
+
+    @Override
+    public RLock lock(String lockKey) {
+        RLock lock = redissonClient.getLock(lockKey);
+        lock.lock();
+        return lock;
+    }
+
+    @Override
+    public RLock lock(String lockKey, long leaseTime) {
+        RLock lock = redissonClient.getLock(lockKey);
+        lock.lock(leaseTime, TimeUnit.SECONDS);
+        return lock;
+    }
+
+    @Override
+    public RLock lock(String lockKey, long leaseTime, TimeUnit unit) {
+        RLock lock = redissonClient.getLock(lockKey);
+        lock.lock(leaseTime, unit);
+        return lock;
+    }
+
+    @Override
+    public RLock getLock(String lockKey) {
+        return redissonClient.getLock(lockKey);
+    }
+
+    @Override
+    public boolean tryLock(String lockKey) {
+        // leaseTime = -1则会自动续期
+        return tryLock(lockKey, 0, -1, TimeUnit.SECONDS);
+    }
+
+    @Override
+    public boolean tryLock(String lockKey, long waitTime, long leaseTime, TimeUnit unit) {
+        RLock lock = redissonClient.getLock(lockKey);
+        try {
+            return lock.tryLock(waitTime, leaseTime, unit);
+        } catch (InterruptedException e) {
+            return false;
+        }
+    }
+
+    @Override
+    public void unlock(String lockKey) {
+        RLock lock = redissonClient.getLock(lockKey);
+        if(lock.isLocked()){
+            lock.unlock();
+        }
+    }
+
+    @Override
+    public void unlock(RLock lock) {
+        if(lock.isLocked()) {
+            lock.unlock();
+        }
+    }
+}

+ 3 - 1
mp-framework/src/main/java/com/qs/mp/framework/config/SecurityConfig.java

@@ -140,7 +140,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                     "/api/v1/mp/user/exchange/goods/detail",
                     "/api/v1/mp/user/exchange/banner/list",
                     "/api/v1/mp/user/exchange/category/list",
-                    "/api/v1/mp/user/exchange/activity/list"
+                    "/api/v1/mp/user/exchange/activity/list",
+                    "/api/v1/mp/user/marketing/list",
+                    "/api/v1/mp/user/marketing/detail/*"
                 ).permitAll()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()

+ 16 - 0
mp-framework/src/main/java/com/qs/mp/framework/security/filter/JwtAuthenticationTokenFilter.java

@@ -1,5 +1,10 @@
 package com.qs.mp.framework.security.filter;
 
+import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.service.IChannelService;
+import com.qs.mp.common.enums.ChannelStatusEnum;
+import com.qs.mp.common.enums.UserIdentityEnum;
+import com.qs.mp.common.exception.ServiceException;
 import com.qs.mp.common.utils.StringUtils;
 import com.qs.mp.core.domain.LoginUser;
 import com.qs.mp.framework.security.handle.HostHolder;
@@ -32,6 +37,9 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
     @Autowired
     private TokenService tokenService;
 
+    @Autowired
+    private IChannelService channelService;
+
     @Autowired
     private HostHolder hostHolder;
 
@@ -40,6 +48,14 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
             throws ServletException, IOException
     {
         LoginUser loginUser = tokenService.getLoginUser(request);
+        // 票赢天下小程序请求,判断账号的状态
+        if (null != loginUser && loginUser.getIdentity() == UserIdentityEnum.CHANNEL) {
+            Channel channel = channelService.getById(loginUser.getChannelId());
+            if (null == channel || channel.getStatus() == ChannelStatusEnum.OFF) {
+                tokenService.delLoginUser(request);
+                loginUser = null;
+            }
+        }
         if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication()))
         {
             tokenService.verifyToken(loginUser);

+ 2 - 1
mp-framework/src/main/java/com/qs/mp/framework/web/service/SysLoginService.java

@@ -6,6 +6,7 @@ import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.common.constant.Constants;
 import com.qs.mp.common.core.redis.RedisCache;
 import com.qs.mp.common.enums.ChannelRoleEnum;
+import com.qs.mp.common.enums.ChannelStatusEnum;
 import com.qs.mp.common.enums.UserIdentityEnum;
 import com.qs.mp.common.exception.ServiceException;
 import com.qs.mp.common.exception.user.CaptchaException;
@@ -204,7 +205,7 @@ public class SysLoginService
      */
     public ChannelRoleEnum fillChannelInfo(LoginUser loginUser){
     	Channel channel = channelService.getChannelByUserId(loginUser.getUserId());
-        if (null != channel && null != channel.getChannelId()){
+        if (null != channel && ChannelStatusEnum.OFF != channel.getStatus()){
           loginUser.setChannelId(channel.getChannelId());
           loginUser.setChannelNo(channel.getChannelNo());
           if (channel.getLevel() == 0) {

+ 6 - 0
mp-framework/src/main/java/com/qs/mp/framework/web/service/TokenService.java

@@ -99,6 +99,12 @@ public class TokenService
         }
     }
 
+    public void delLoginUser(HttpServletRequest request) {
+        // 获取请求携带的令牌
+        String token = getToken(request);
+        delLoginUser(token);
+    }
+
     /**
      * 创建令牌
      *

+ 8 - 0
mp-service/src/main/java/com/qs/mp/admin/service/IMarketingService.java

@@ -6,6 +6,7 @@ import com.qs.mp.admin.domain.param.MarketingCreateParam;
 import com.qs.mp.admin.domain.param.MarketingQueryParam;
 import com.qs.mp.admin.domain.param.MarketingUpdateParam;
 import com.qs.mp.admin.domain.vo.MarketingListVO;
+import com.qs.mp.user.domain.param.MarketingHelpParam;
 
 import java.util.List;
 
@@ -43,4 +44,11 @@ public interface IMarketingService extends IService<Marketing> {
      * @param id
      */
     void deleteById(Long id);
+
+    /**
+     * 活动助力
+     * @param marketingHelpParam
+     * @param userId
+     */
+    void help(MarketingHelpParam marketingHelpParam, Long userId);
 }

+ 93 - 0
mp-service/src/main/java/com/qs/mp/admin/service/impl/MarketingServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qs.mp.admin.service.impl;
 
+import cn.hutool.core.util.NumberUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -9,11 +10,17 @@ import com.qs.mp.admin.domain.vo.MarketingListVO;
 import com.qs.mp.admin.mapper.MarketingMapper;
 import com.qs.mp.admin.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.enums.MarketingStatusEnum;
 import com.qs.mp.common.enums.TicketPrizeTypeEnum;
+import com.qs.mp.common.enums.UserTypeEnum;
 import com.qs.mp.common.exception.ServiceException;
 import com.qs.mp.common.utils.DateUtils;
 import com.qs.mp.common.utils.bean.BeanUtils;
+import com.qs.mp.user.domain.MarketingUserCode;
+import com.qs.mp.user.domain.param.MarketingHelpParam;
+import com.qs.mp.user.service.IMarketingUserCodeService;
+import com.qs.mp.utils.MarketingUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -52,6 +59,92 @@ public class MarketingServiceImpl extends ServiceImpl<MarketingMapper, Marketing
     @Autowired
     private IMarketingAwardsPrizeService marketingAwardsPrizeService;
 
+    @Autowired
+    private IMarketingUserCodeService marketingUserCodeService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void help(MarketingHelpParam marketingHelpParam, Long userId) {
+        String inviteCode = marketingHelpParam.getInviteCode();
+        if (com.qs.mp.common.utils.StringUtils.isBlank(inviteCode)) {
+            throw new ServiceException("邀请码不能为空");
+        }
+
+        Marketing marketing = this.getById(marketingHelpParam.getMarketingId());
+        if (Objects.isNull(marketing)) {
+            throw new ServiceException("活动不存在");
+        }
+        // 未开启的活动不能助力
+        if (MarketingStatusEnum.ON.getValue().equals(marketing.getIsOn())) {
+            throw new ServiceException("活动未开启~");
+        }
+        Date now = DateUtils.getNowDate();
+        // 结束的活动不支持助力
+        if (marketing.getTriggerStatus() == 1 || marketing.getEndTime().before(now)) {
+            throw new ServiceException("活动已过期~");
+        }
+        // 未开始的活动不能助力
+        if (marketing.getStartTime().after(now)) {
+            throw new ServiceException("活动未开始~");
+        }
+
+
+        // 判断是否已经助力过
+        int count = marketingUserCodeService.count(new LambdaQueryWrapper<MarketingUserCode>()
+                .eq(MarketingUserCode::getUserId, userId)
+                .eq(MarketingUserCode::getMarketingId, marketingHelpParam.getMarketingId()));
+        if (count > 0) {
+            throw new ServiceException("您已经助力过了");
+        }
+
+        // 邀请码解码,被助力人id
+        Long helpedUserId = MarketingUtils.decodeInviteCode(inviteCode);
+
+        // 生成抽奖码
+        String code = "";
+        while (true) {
+            code = MarketingUtils.generatePrizeCode();
+            // 判断抽奖码是否已经存在
+            int codeCount = marketingUserCodeService.count(new LambdaQueryWrapper<MarketingUserCode>()
+                    .eq(MarketingUserCode::getMarketingId,marketing.getId())
+                    .eq(MarketingUserCode::getCode, code));
+            if (codeCount > 0) {
+                continue;
+            }
+            break;
+        }
+
+        MarketingUserCode marketingUserCode = new MarketingUserCode();
+        marketingUserCode.setMarketingId(marketingHelpParam.getMarketingId());
+        marketingUserCode.setCode(code);
+        // 设置被助力人
+        marketingUserCode.setUserId(helpedUserId);
+        // 设置助力人
+        marketingUserCode.setHelpUserId(userId);
+        marketingUserCode.setUserType(UserTypeEnum.ORDINARY.getValue());
+
+
+        // 保存助力信息
+        marketingUserCodeService.save(marketingUserCode);
+
+        // 增加活动参与人数
+        int userCount = marketingUserCodeService.count(new LambdaQueryWrapper<MarketingUserCode>()
+                .eq(MarketingUserCode::getMarketingId, marketing.getId())
+                .eq(MarketingUserCode::getUserType, UserTypeEnum.ORDINARY.getValue())
+                .groupBy(MarketingUserCode::getMarketingId));
+
+        Marketing marketingParam = new Marketing();
+        marketingParam.setId(marketing.getId());
+        marketingParam.setRealNum(userCount);
+        int randomNum = (int) 1 + (int) (Math.random() * 10);
+        marketingParam.setFakeNum(marketing.getFakeNum() + randomNum);
+
+        // 更新活动参与人数
+        this.updateById(marketingParam);
+
+    }
+
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void deleteById(Long id) {