From bf6989e1f9cc614cf0439f048280cbcdb78d4009 Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期五, 29 八月 2025 02:12:03 +0800
Subject: [PATCH] 提交本地代码

---
 framework/src/main/java/cn/lili/modules/lmk/service/impl/PrizeServiceImpl.java |  104 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 92 insertions(+), 12 deletions(-)

diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/PrizeServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/PrizeServiceImpl.java
index 2da8595..60f23e6 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/PrizeServiceImpl.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/PrizeServiceImpl.java
@@ -7,14 +7,16 @@
 import cn.lili.common.security.context.UserContext;
 import cn.lili.common.utils.StringUtils;
 import cn.lili.modules.lmk.domain.entity.*;
+import cn.lili.modules.lmk.domain.form.AddPrizeNumForm;
 import cn.lili.modules.lmk.domain.query.PrizeRecordTimeQuery;
+import cn.lili.modules.lmk.domain.vo.PrizeDetailVO;
 import cn.lili.modules.lmk.domain.vo.PrizeProbabilityVO;
 import cn.lili.modules.lmk.domain.vo.PrizeRecordTimeVO;
 import cn.lili.modules.lmk.enums.general.*;
 import cn.lili.modules.lmk.service.*;
 import cn.lili.mybatis.BaseEntity;
 import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
-import cn.lili.rocketmq.tags.CommentTagsEnum;
+import cn.lili.utils.COSUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -37,7 +39,6 @@
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.util.*;
-import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -55,6 +56,8 @@
     private final RedissonClient redissonClient;
     private final RocketmqCustomProperties rocketmqCustomProperties;
     private final RocketMQTemplate rocketMQTemplate;
+    private final COSUtil cosUtil;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Result prize(String prizeId) {
@@ -167,20 +170,20 @@
         refPrizes = activityRefPrizeService.list(prizeRefQuery);
         canPrizeMap = refPrizes.stream().filter(item -> {
             return item.getRemainNum() > 0;
-        }).collect(Collectors.toMap(ActivityRefPrize::getPrizeId, Function.identity()));
+        }).collect(Collectors.toMap(ActivityRefPrize::getId, Function.identity()));
         prizeRecordTimeQuery = new PrizeRecordTimeQuery();
         prizeRecordTimeQuery.setStartTime(beginTime);
         prizeRecordTimeQuery.setEndTime(endTime);
         prizeRecordTimeQuery.setRecordActivityId(prizeId);
         prizeRecordListByTime = prizeRecordService.getPrizeRecordListByTime(prizeRecordTimeQuery);
-        prizeRecordListByTime.stream().filter(item->{
-            return item.getPrizeId() != null;
+        prizeRecordListByTime.stream().filter(item -> {
+            return item.getActivityPrizeRefId() != null;
         }).forEach(item -> {
-            ActivityRefPrize activityRefPrize = canPrizeMap.get(Long.parseLong(item.getPrizeId()));
+            ActivityRefPrize activityRefPrize = canPrizeMap.get(item.getActivityPrizeRefId());
             if (activityRefPrize != null) {
                 //绉婚櫎褰撴棩涓婇檺鐨勫鍝佸苟涓旀坊鍔犲埌涓嶈兘鎶藉鍟嗗搧涓幓
                 if (activityRefPrize.getMaxPreDay() <= item.getTotal()) {
-                    canPrizeMap.remove(Long.parseLong(item.getPrizeId()));
+                    canPrizeMap.remove(item.getActivityPrizeRefId());
                 }
             }
         });
@@ -204,7 +207,7 @@
         BigDecimal probabilityBegin = BigDecimal.ZERO;
         for (ActivityRefPrize item : refPrizeList) {
             PrizeProbabilityVO prizeProbabilityVO = new PrizeProbabilityVO();
-            prizeProbabilityVO.setPrizeId(item.getPrizeId());
+            prizeProbabilityVO.setActivityPrizeRefId(item.getId());
             BigDecimal multiply = item.getPrizeProbability().multiply(BigDecimal.valueOf(100));
             BigDecimal[][] position = {{probabilityBegin, multiply.add(probabilityBegin)}};
             prizeProbabilityVO.setProbability(position);
@@ -217,7 +220,7 @@
             BigDecimal minP = prizeProbabilityVO.getProbability()[0][0];
             BigDecimal maxP = prizeProbabilityVO.getProbability()[0][1];
             if (bigDecimal.compareTo(minP) > 0 && bigDecimal.compareTo(maxP) <= 0) {
-                prizeWon = prizeProbabilityVO.getPrizeId();
+                prizeWon = prizeProbabilityVO.getActivityPrizeRefId();
                 break;
             }
         }
@@ -263,7 +266,7 @@
         if (!update) {
             throw new ServiceException("褰撳墠娲诲姩澶伀鐖嗕簡璇风◢鍚庡啀璇�");
         }
-        PrizeDraw prizeDraw = prizeDrawService.getById(prizeWon);
+        PrizeDraw prizeDraw = prizeDrawService.getById(activityRefPrize.getPrizeId());
         //鍐欏叆鎶藉璁板綍
         PrizeRecord prizeRecord = new PrizeRecord();
         prizeRecord.setUserId(Long.parseLong(userId));
@@ -277,7 +280,7 @@
         prizeRecord.setPrizeNumId(Long.parseLong(waitUserPrize.getId()));
         prizeRecord.setActivityPrizeRefId(Long.parseLong(activityRefPrize.getId()));
         prizeRecord.setDistributeStatus(PrizeDistributeStatusEnum.WAIT.name());
-        prizeRecord.setPrizeId(prizeWon);
+        prizeRecord.setPrizeId(activityRefPrize.getPrizeId());
         prizeRecord.setPrizeName(prizeDraw.getPrizeName());
         prizeRecord.setPrizeActivityCover(prizeActivity.getActivityCover());
         prizeRecord.setPrizeImg(prizeDraw.getPrizeImg());
@@ -329,6 +332,13 @@
         if (activity == null) {
             throw new RuntimeException("褰撳墠娲诲姩涓嶅瓨鍦�");
         }
+        Date activityEndtime = activity.getEndTime();
+        if (new Date().after(activityEndtime)) {
+            throw new ServiceException("褰撳墠娲诲姩宸茬粡缁撴潫");
+        }
+        if (!PrizeActivityStatusEnum.ON.name().equals(activity.getEnableStatus())) {
+            throw new ServiceException("娲诲姩杩樻病鏈夊惎鐢�");
+        }
         //鑾峰彇鐢ㄦ埛鎶藉娆℃暟
         Integer prizeNum = activity.getPrizeNum();
         //鍔犻攣鍒ゆ柇娣诲姞绯荤粺璧犻�佹鏁�
@@ -376,7 +386,7 @@
         if (useNum >= maxPrize) {
             return Result.ok().data(0);
         } else {
-            return Result.ok().data(userPrizeNum>maxPrize?maxPrize-useNum:notUseNum);
+            return Result.ok().data(userPrizeNum > maxPrize ? maxPrize - useNum : notUseNum);
         }
     }
 
@@ -408,6 +418,76 @@
 
     @Override
     public Result prizeInfo(String prizeActivityId) {
+        if (StringUtils.isBlank(prizeActivityId)) {
+            return Result.ok().data(0);
+        }
+        PrizeDetailVO data = prizeActivityService.prizeInfo(prizeActivityId);
+        String activityCover = data.getActivityCover();
+        if (StringUtils.isNotBlank(activityCover) && !activityCover.contains("http")) {
+            data.setActivityCover(cosUtil.getPreviewUrl(activityCover));
+        }
+        data.getPrizeInfoVOS().forEach(info -> {
+            String prizeImg = info.getPrizeImg();
+            String prizeCover = info.getPrizeCover();
+            if (StringUtils.isNotBlank(prizeImg) && !prizeImg.contains("http")) {
+                info.setPrizeImg(cosUtil.getPreviewUrl(prizeImg));
+            }
+            if (StringUtils.isNotBlank(prizeCover) && !prizeCover.contains("http")) {
+                info.setPrizeCover(cosUtil.getPreviewUrl(prizeCover));
+            }
+        });
+        return Result.ok().data(data);
+    }
+
+    @Override
+    public Result grantRecord(String prizeActivityId) {
+        return prizeDrawService.grantRecord(prizeActivityId);
+    }
+
+    @Override
+    public Result addPrizeNum(AddPrizeNumForm addPrizeNumForm) {
+        PrizeActivity activity = prizeActivityService.getById(addPrizeNumForm.getPrizeActivityId());
+        if (activity == null) {
+            throw new ServiceException("褰撳墠娲诲姩涓嶅瓨鍦�");
+        }
+        if (!PrizeActivityStatusEnum.ON.name().equals(activity.getEnableStatus())) {
+            throw new ServiceException("褰撳墠娲诲姩娌″紑鍚�");
+        }
+        Date date = new Date();
+        //娲诲姩缁撴潫涓嶉渶瑕佹坊鍔�
+        if (date.after(activity.getEndTime())) {
+            throw new ServiceException("褰撳墠娲诲姩宸茬粨鏉�");
+        }
+        Integer maxPrize = activity.getMaxPrize();
+        String userId = addPrizeNumForm.getUserId();
+        List<PrizeNumber> prizeNumberList = getPrizeNumberList(activity.getId(), userId);
+        if (prizeNumberList.size() >= maxPrize) {
+            throw new ServiceException("鎶藉娆℃暟宸茶揪鍒颁笂闄愪簡");
+        }
+        PrizeUserActionEnum actionEnum = PrizeUserActionEnum.select(addPrizeNumForm.getAddType());
+        if (actionEnum == null) {
+            throw new ServiceException("褰撳墠绫诲瀷涓嶅瓨鍦�");
+        }
+       Boolean check ;
+         //todo 杩涜鏁版嵁鏍¢獙
+        switch (actionEnum) {
+            case BUY:
+                System.err.println("BUY");
+                break;
+            case SHARE:
+                //鐩存帴鑾峰緱鎶藉娆℃暟
+                System.err.println("SHARE");
+                break;
+            case SEE_SHOP:
+                System.err.println("SEE_SHOP");
+                break;
+            case SEE_VIDEO:
+                System.err.println("SEE_VIDEO");
+                break;
+            default:
+
+                break;
+        }
         return null;
     }
 }

--
Gitblit v1.8.0