buyer-api/src/main/java/cn/lili/controller/lmk/PrizeController.java
@@ -63,11 +63,11 @@ /** * 增加抽奖次数 * * @param prizeActivityId * @param addPrizeNumForm * @return */ @PostMapping("/addPrizeNum/{prizeActivityId}") public Result addPrizeNum(@PathVariable String prizeActivityId, @RequestBody AddPrizeNumForm addPrizeNumForm) { return prizeService.grantRecord(prizeActivityId); @PostMapping("/addPrizeNum") public Result addPrizeNum( @RequestBody AddPrizeNumForm addPrizeNumForm) { return prizeService.addPrizeNum(addPrizeNumForm); } } framework/src/main/java/cn/lili/modules/lmk/domain/entity/PrizeActivity.java
@@ -1,5 +1,6 @@ package cn.lili.modules.lmk.domain.entity; import cn.lili.modules.lmk.enums.general.PrizeActivityStatusEnum; import cn.lili.mybatis.BaseEntity; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -55,7 +56,9 @@ private String activityCover; @TableField("enable_status") /** 是否开启活动 */ /** 是否开启活动 * @see PrizeActivityStatusEnum * */ private String enableStatus; @TableField("popup") framework/src/main/java/cn/lili/modules/lmk/domain/form/AddPrizeNumForm.java
@@ -16,6 +16,8 @@ *抽奖活动id */ private String prizeActivityId; /** * 其他扩展参数JSON格式的字符串用于校验数据的有效性 */ private String extend; } framework/src/main/java/cn/lili/modules/lmk/enums/general/PrizeUserActionEnum.java
@@ -10,10 +10,20 @@ /** * 获取优惠卷的方式 */ SYSTEM("系统赠送"), BUY("购买"), SHARE("分享"), SEE_SHOP("看商城"), SEE_VIDEO("看视频"); SYSTEM("系统赠送",1), BUY("购买",1), SHARE("分享",1), SEE_SHOP("看商城",1), SEE_VIDEO("看视频",1); private final String description; private final Integer sendNumber; public static PrizeUserActionEnum select(String name) { for (PrizeUserActionEnum prizeUserActionEnum : values()) { if (prizeUserActionEnum.name().equals(name)) { return prizeUserActionEnum; } } return null; } } framework/src/main/java/cn/lili/modules/lmk/service/PrizeService.java
@@ -1,7 +1,9 @@ package cn.lili.modules.lmk.service; import cn.lili.base.Result; import cn.lili.modules.lmk.domain.form.AddPrizeNumForm; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; public interface PrizeService { @@ -14,4 +16,6 @@ Result grantRecord( String prizeActivityId); Result addPrizeNum(AddPrizeNumForm addPrizeNumForm); } framework/src/main/java/cn/lili/modules/lmk/service/impl/PrizeServiceImpl.java
@@ -7,6 +7,7 @@ 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; @@ -56,6 +57,7 @@ private final RocketmqCustomProperties rocketmqCustomProperties; private final RocketMQTemplate rocketMQTemplate; private final COSUtil cosUtil; @Override @Transactional(rollbackFor = Exception.class) public Result prize(String prizeId) { @@ -441,4 +443,51 @@ 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; } }