|
@@ -1,5 +1,6 @@
|
|
package com.qs.mp.admin.service.impl;
|
|
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.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
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.mapper.MarketingMapper;
|
|
import com.qs.mp.admin.service.*;
|
|
import com.qs.mp.admin.service.*;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
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.MarketingStatusEnum;
|
|
import com.qs.mp.common.enums.TicketPrizeTypeEnum;
|
|
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.exception.ServiceException;
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
import com.qs.mp.common.utils.bean.BeanUtils;
|
|
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.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -52,6 +59,92 @@ public class MarketingServiceImpl extends ServiceImpl<MarketingMapper, Marketing
|
|
@Autowired
|
|
@Autowired
|
|
private IMarketingAwardsPrizeService marketingAwardsPrizeService;
|
|
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
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void deleteById(Long id) {
|
|
public void deleteById(Long id) {
|