Sfoglia il codice sorgente

添加“根据活动类型判断是否可以抽奖”接口

wangzhijun 1 settimana fa
parent
commit
295f2ecb9a

+ 32 - 0
nightFragrance-admin/src/main/java/com/ylx/web/controller/lottery/LotteryController.java

@@ -0,0 +1,32 @@
+package com.ylx.web.controller.lottery;
+
+import com.ylx.common.core.domain.R;
+import com.ylx.lottery.domain.dto.IsLotteryDTO;
+import com.ylx.lottery.domain.vo.IsLotteryVO;
+import com.ylx.lottery.service.LotteryCountLogService;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@RestController
+@RequestMapping("/lottery")
+public class LotteryController {
+
+    @Resource
+    private LotteryCountLogService lotteryCountLogService;
+
+    @ApiOperation("根据活动类型判断是否可以抽奖")
+    @PostMapping("/isLottery")
+    public R<IsLotteryVO> isLottery(@Validated @RequestBody IsLotteryDTO dto) {
+        IsLotteryVO vo = this.lotteryCountLogService.isLottery(dto);
+        return R.ok(vo);
+    }
+
+}

+ 6 - 0
nightFragrance-massage/src/main/java/com/ylx/lottery/domain/LotteryCountLog.java

@@ -43,4 +43,10 @@ public class LotteryCountLog extends BaseEntity {
     @Excel(name = "同步状态 0-未同步到本地生活 1-已同步到本地生活")
     @Excel(name = "同步状态 0-未同步到本地生活 1-已同步到本地生活")
     private Integer status;
     private Integer status;
 
 
+    @Excel(name = "类型(1.按摩订单 2.积分订单 3.评论有礼)")
+    private Integer type;
+
+    @Excel(name = "是否弹窗抽奖(0 .没有 1.有)")
+    private Integer isLottery;
+
 }
 }

+ 17 - 0
nightFragrance-massage/src/main/java/com/ylx/lottery/domain/dto/IsLotteryDTO.java

@@ -0,0 +1,17 @@
+package com.ylx.lottery.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+@Data
+public class IsLotteryDTO implements Serializable {
+    private static final long serialVersionUID = -8430222377384281190L;
+
+    @NotNull(message = "类型不能为空")
+    @ApiModelProperty(value = "类型:1.按摩订单 2.积分订单 3.评论有礼", required = true)
+    private Integer type;
+
+}

+ 16 - 0
nightFragrance-massage/src/main/java/com/ylx/lottery/domain/vo/IsLotteryVO.java

@@ -0,0 +1,16 @@
+package com.ylx.lottery.domain.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class IsLotteryVO implements Serializable {
+
+    private static final long serialVersionUID = -8430222377384281190L;
+
+    @ApiModelProperty("是否可以抽奖:0.没有 1有")
+    private Integer isLottery;
+
+}

+ 4 - 0
nightFragrance-massage/src/main/java/com/ylx/lottery/service/LotteryCountLogService.java

@@ -3,6 +3,8 @@ package com.ylx.lottery.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ylx.lottery.domain.LotteryCountLog;
 import com.ylx.lottery.domain.LotteryCountLog;
+import com.ylx.lottery.domain.dto.IsLotteryDTO;
+import com.ylx.lottery.domain.vo.IsLotteryVO;
 import com.ylx.lottery.domain.vo.LotteryStatVO;
 import com.ylx.lottery.domain.vo.LotteryStatVO;
 
 
 import java.util.List;
 import java.util.List;
@@ -10,4 +12,6 @@ import java.util.List;
 public interface LotteryCountLogService extends IService<LotteryCountLog> {
 public interface LotteryCountLogService extends IService<LotteryCountLog> {
 
 
     List<LotteryStatVO> selectSumByGroup(LambdaQueryWrapper<LotteryCountLog> queryWrapper);
     List<LotteryStatVO> selectSumByGroup(LambdaQueryWrapper<LotteryCountLog> queryWrapper);
+
+    IsLotteryVO isLottery(IsLotteryDTO dto);
 }
 }

+ 60 - 0
nightFragrance-massage/src/main/java/com/ylx/lottery/service/impl/LotteryCountLogServiceImpl.java

@@ -1,14 +1,26 @@
 package com.ylx.lottery.service.impl;
 package com.ylx.lottery.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 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.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ylx.common.core.domain.model.WxLoginUser;
+import com.ylx.common.exception.ServiceException;
+import com.ylx.common.utils.SecurityUtils;
 import com.ylx.lottery.domain.LotteryCountLog;
 import com.ylx.lottery.domain.LotteryCountLog;
+import com.ylx.lottery.domain.dto.IsLotteryDTO;
+import com.ylx.lottery.domain.vo.IsLotteryVO;
 import com.ylx.lottery.domain.vo.LotteryStatVO;
 import com.ylx.lottery.domain.vo.LotteryStatVO;
 import com.ylx.lottery.mapper.LotteryCountLogMapper;
 import com.ylx.lottery.mapper.LotteryCountLogMapper;
 import com.ylx.lottery.service.LotteryCountLogService;
 import com.ylx.lottery.service.LotteryCountLogService;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 
+import java.util.Date;
 import java.util.List;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 @Service
 @Service
 public class LotteryCountLogServiceImpl extends ServiceImpl<LotteryCountLogMapper, LotteryCountLog> implements LotteryCountLogService {
 public class LotteryCountLogServiceImpl extends ServiceImpl<LotteryCountLogMapper, LotteryCountLog> implements LotteryCountLogService {
@@ -17,4 +29,52 @@ public class LotteryCountLogServiceImpl extends ServiceImpl<LotteryCountLogMappe
     public List<LotteryStatVO> selectSumByGroup(LambdaQueryWrapper<LotteryCountLog> queryWrapper) {
     public List<LotteryStatVO> selectSumByGroup(LambdaQueryWrapper<LotteryCountLog> queryWrapper) {
         return this.baseMapper.selectSumByGroup(queryWrapper);
         return this.baseMapper.selectSumByGroup(queryWrapper);
     }
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public IsLotteryVO isLottery(IsLotteryDTO dto) {
+
+        IsLotteryVO vo = new IsLotteryVO();
+
+        // 1. 获取当前登录用户
+        WxLoginUser loginUser = SecurityUtils.getWxLoginUser();
+        if (ObjectUtil.isNull(loginUser)) {
+            throw new ServiceException("用户未登录或登录已过期");
+        }
+
+        String userId = loginUser.getId();
+        if (StrUtil.isBlank(userId)) {
+            throw new ServiceException("用户ID不合法");
+        }
+
+        // 2. 构建查询条件 (用于查找未弹窗的记录)
+        LambdaQueryWrapper<LotteryCountLog> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.select(LotteryCountLog::getId)
+                .eq(LotteryCountLog::getType, dto.getType())
+                .eq(LotteryCountLog::getUserId, userId)
+                .eq(LotteryCountLog::getIsLottery, 0) // 只查未弹窗的
+                .eq(LotteryCountLog::getIsDelete, 0);
+
+        // 3.提取 ID 列表
+        List<Long> logIds = this.baseMapper.selectList(queryWrapper).stream()
+                .map(LotteryCountLog::getId)
+                .collect(Collectors.toList());
+
+        // 4. 设置返回结果
+        boolean hasChance = CollUtil.isNotEmpty(logIds);
+        vo.setIsLottery(hasChance ? 1 : 0);
+
+        // 5. 如果有记录,批量更新状态为“已弹窗”
+        if (CollUtil.isNotEmpty(logIds)) {
+            LambdaUpdateWrapper<LotteryCountLog> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.in(LotteryCountLog::getId, logIds)
+                    .set(LotteryCountLog::getIsLottery, 1)
+                    .set(LotteryCountLog::getUpdateTime, new Date());
+
+            this.update(updateWrapper);
+        }
+
+        return vo;
+    }
+
 }
 }

+ 6 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/TCommentUserServiceImpl.java

@@ -123,6 +123,9 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
                             lotteryCountLog.setIsDelete("0");
                             lotteryCountLog.setIsDelete("0");
                             // 同步状态 0-未同步到本地生活
                             // 同步状态 0-未同步到本地生活
                             lotteryCountLog.setStatus(0);
                             lotteryCountLog.setStatus(0);
+
+                            lotteryCountLog.setIsLottery(0);
+                            lotteryCountLog.setType(3);
                             lotteryCountLogService.save(lotteryCountLog);
                             lotteryCountLogService.save(lotteryCountLog);
                         }
                         }
                     } else {
                     } else {
@@ -156,6 +159,9 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
                             lotteryCountLog.setIsDelete("0");
                             lotteryCountLog.setIsDelete("0");
                             // 同步状态 0-未同步到本地生活
                             // 同步状态 0-未同步到本地生活
                             lotteryCountLog.setStatus(0);
                             lotteryCountLog.setStatus(0);
+
+                            lotteryCountLog.setIsLottery(0);
+                            lotteryCountLog.setType(3);
                             lotteryCountLogService.save(lotteryCountLog);
                             lotteryCountLogService.save(lotteryCountLog);
                         }
                         }
                     }
                     }