소스 검색

修改抽奖内容

码头薯片 5 달 전
부모
커밋
f01cc412d4

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/recovery/controller/WxUserLotteryController.java

@@ -28,7 +28,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
  * @date 2024-12-17
  */
 @RestController
-@RequestMapping("/recovery/lottery")
+@RequestMapping("/recovery/user/lottery")
 public class WxUserLotteryController extends BaseController
 {
     @Autowired

+ 6 - 6
ruoyi-wx/src/main/java/com/ruoyi/wx/web/domain/vo/LotteryVo.java

@@ -11,7 +11,7 @@ public class LotteryVo {
     /**
      * 抽奖数
      */
-    private Integer LotteryNum;
+    private String lotteryType;
 
     public List<String> getLotteryCodes() {
         return lotteryCodes;
@@ -21,19 +21,19 @@ public class LotteryVo {
         this.lotteryCodes = lotteryCodes;
     }
 
-    public Integer getLotteryNum() {
-        return LotteryNum;
+    public String getLotteryType() {
+        return lotteryType;
     }
 
-    public void setLotteryNum(Integer lotteryNum) {
-        LotteryNum = lotteryNum;
+    public void setLotteryType(String lotteryNum) {
+        lotteryType = lotteryNum;
     }
 
     @Override
     public String toString() {
         return "LotteryVo{" +
                 "LotteryCode='" + lotteryCodes + '\'' +
-                ", LotteryNum='" + LotteryNum + '\'' +
+                ", LotteryNum='" + lotteryType + '\'' +
                 '}';
     }
 }

+ 11 - 2
ruoyi-wx/src/main/java/com/ruoyi/wx/web/service/impl/WxLotteryUserServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.wx.web.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.framework.recovery.domain.WxUserLottery;
@@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 @Service
@@ -24,13 +26,17 @@ public class WxLotteryUserServiceImpl implements IWxLotteryUserService {
         String wxOpenid = SecurityUtils.getLoginWxUser().getWxUser().getWxOpenid();
         lottery.setOpenId(wxOpenid);
         List<WxUserLottery> userLotteries = wxUserLotteryMapper.selectWxUserLotteryList(lottery);
+        if (CollectionUtil.isEmpty(userLotteries)) {
+            return new LotteryVo();
+        }
         List<String> lotteryIds = new ArrayList<>();
         for (WxUserLottery userLottery : userLotteries) {
             lotteryIds.add(userLottery.getLotteryNum());
         }
+        // TODO 修改返回参数为List<LotteryVo>
         LotteryVo result = new LotteryVo();
         result.setLotteryCodes(lotteryIds);
-        result.setLotteryNum(lotteryIds.size());
+        result.setLotteryType("1");
         return result;
     }
 
@@ -44,7 +50,7 @@ public class WxLotteryUserServiceImpl implements IWxLotteryUserService {
         if (total > 10) {
             throw new ServiceException("超出抽奖数量阈值");
         }
-        List<WxUserLottery> dto = new ArrayList<>();
+        // 构建抽奖记录
         for (int i = 0 ; i < lotteryDto.getNum() ; i++) {
             WxUserLottery info = new WxUserLottery();
             info.setOpenId(wxOpenid);
@@ -52,7 +58,10 @@ public class WxLotteryUserServiceImpl implements IWxLotteryUserService {
             lotteryCode = lotteryCode + i;
             info.setLotteryNum(lotteryCode);
             info.setLotteryType(lotteryDto.getType());
+            info.setCreateDate(new Date());
+            wxUserLotteryMapper.insertWxUserLottery(info);
         }
+
         return null;
     }
 }