This commit is contained in:
777
2026-01-14 17:31:25 +08:00
parent 7fdf6eefad
commit 235059c96a
5 changed files with 53 additions and 19 deletions

View File

@@ -6,7 +6,7 @@ CREATE TABLE `cai_user_login`
`mobile` varchar(100) NOT NULL COMMENT '账户明细说明',
`password` varchar(100) NOT NULL COMMENT '账户明细说明',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `user_id` (`user_id`) USING BTREE
) ENGINE = InnoDB
@@ -14,3 +14,12 @@ CREATE TABLE `cai_user_login`
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci
ROW_FORMAT = DYNAMIC COMMENT ='123记录';
INSERT INTO `cai_prize_info` (`id`, `prize_name`, `prize_desc`, `prize_img`, `win_probability`, `guarantee_draws`,
`min_win_draws`, `stock`, `prize_type`, `prize_price`, `auto_give`, `create_time`,
`update_time`)
VALUES (1, '谢谢惠顾', '谢谢惠顾', 'test/2026/01/06/0d6bafa0bb1841eabd745f0bf495640c.png', 0.0000, 0, 0, 0, 1, 0, 1,
'2026-01-06 15:33:11', '2026-01-14 16:53:47');

View File

@@ -7,6 +7,7 @@ import com.ruoyi.cai.domain.PrizeOnline;
import com.ruoyi.cai.domain.PrizeWinningRecord;
import com.ruoyi.cai.dto.app.draw.resp.*;
import com.ruoyi.cai.lottery.DrawService;
import com.ruoyi.cai.lottery.LotteryService;
import com.ruoyi.cai.service.PrizeOnlineService;
import com.ruoyi.cai.service.PrizeWinningRecordService;
import com.ruoyi.common.core.domain.PageQuery;
@@ -33,6 +34,8 @@ public class DrawController {
private PrizeOnlineService prizeOnlineService;
@Autowired
private PrizeWinningRecordService prizeWinningRecordService;
@Autowired
private LotteryService lotteryService;
@GetMapping("/baseConfig")
@Operation(summary = "获取抽奖相关的基础信息")

View File

@@ -83,6 +83,9 @@ public class PrizeInfoController extends BaseController {
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody PrizeInfo bo) {
if(bo.getId() == 1){
return R.fail("无法编辑系统内置谢谢惠顾");
}
return toAjax(prizeInfoService.updateById(bo));
}
@@ -96,6 +99,10 @@ public class PrizeInfoController extends BaseController {
@DeleteMapping("/{ids}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(prizeInfoService.removeBatchByIds(Arrays.asList(ids), true));
List<Long> idArray = Arrays.asList(ids);
if(idArray.contains(1L)){
return R.fail("无法删除系统内置谢谢惠顾");
}
return toAjax(prizeInfoService.removeBatchByIds(idArray, true));
}
}

View File

@@ -34,8 +34,6 @@ import java.util.concurrent.locks.ReentrantLock;
@Slf4j
public class LotteryService {
// 固定配置
private static final Long THANKS_PRIZE_ID = 0L;
private static final String USER_DRAW_COUNT_KEY = "user:draw:count:%s";
private static final long USER_DRAW_COUNT_EXPIRE = 7 * 24 * 60 * 60; // 用户累计抽数缓存过期时间7天
private static final double RANDOM_MAX = 10000; // 概率放大倍数,提升随机数精度
@@ -69,14 +67,14 @@ public class LotteryService {
if(user == null){
throw new ServiceException("用户不存在");
}
boolean openDraw = drawService.getOpenDraw(user.getGender());
if(!openDraw){
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
}
boolean select = GenderEnum.isSelect(user.getGender());
if(select){
throw new ServiceException("请选择性别后在抽奖");
}
boolean openDraw = drawService.getOpenDraw(user.getGender());
if(!openDraw){
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
}
Account account = accountService.getByUserId(user.getId());
Integer drawPoint = drawService.getDrawPoint(user.getGender());
if(account.getPoints() < drawPoint){
@@ -120,10 +118,23 @@ public class LotteryService {
int currentContinuousDraws = getContinuousDraws(userId);
int newContinuousDraws = currentContinuousDraws + 1;
log.info("用户{}当前累计抽数:{},本次抽数:{}", userId, currentContinuousDraws, newContinuousDraws);
// 步骤2获取有奖品列表(启用状态,排除谢谢惠顾)
// 步骤2获取有奖品列表
List<PrizeOnline> validPrizes = prizeOnlineService.selectPrizeOnlineList(user.getGender());
if (validPrizes.isEmpty()) {
throw new ServiceException("无有效奖品,请刷新页面后再次抽奖");
throw new ServiceException("无有效奖品,请刷新后再次抽奖");
}
// 找出系统内置谢谢惠顾
PrizeOnline thankPrize = null;
for (int i = 0; i < validPrizes.size(); i++) {
PrizeOnline validPrize = validPrizes.get(i);
if(validPrize.getPrizeId() == 1){
thankPrize = validPrize;
validPrizes.remove(i);
break;
}
}
if(thankPrize == null){
throw new ServiceException("奖品库异常,请刷新后再次抽奖");
}
// 步骤3执行抽奖规则保底→最低抽数过滤→概率抽奖
PrizeOnline winPrize = null;
@@ -236,13 +247,10 @@ public class LotteryService {
if (cacheCount != null) {
return cacheCount;
}
// 2. 缓存未命中,从数据库查询最后一次累计抽数
// Integer dbCount = userDrawRecordMapper.selectLastContinuousDraws(userId);
Integer dbCount = 0;
int finalCount = dbCount == null ? 0 : dbCount;
// 3. 存入缓存(设置过期时间)
bucket.set(finalCount, USER_DRAW_COUNT_EXPIRE, java.util.concurrent.TimeUnit.SECONDS);
return finalCount;
// 3. 存入缓存
// bucket.set(0, USER_DRAW_COUNT_EXPIRE, java.util.concurrent.TimeUnit.SECONDS);
bucket.set(0);
return 0;
}
@Autowired

View File

@@ -45,18 +45,25 @@ public class PrizeOnlineServiceImpl extends ServiceImpl<PrizeOnlineMapper,PrizeO
throw new ServiceException("奖品必须为9个");
}
boolean hasNone = false;
int bigNum = 0;
List<Long> prizeIds = new ArrayList<>();
for (PrizeOnline prizeOnline : bo) {
prizeOnline.setGender(gender);
if(PrizeTypeEnum.NONE.getCode().equals(prizeOnline.getPrizeType())){
if(prizeOnline.getPrizeId() != null && prizeOnline.getPrizeId() == 1){
hasNone = true;
}
if(PrizeTypeEnum.GOOD.getCode().equals(prizeOnline.getPrizeType())){
bigNum++;
}
if(prizeOnline.getId() != null){
prizeIds.add(prizeOnline.getId());
}
}
if(!hasNone){
throw new ServiceException("奖品必须包含谢谢惠顾");
throw new ServiceException("奖品必须包含内置的谢谢惠顾");
}
if(bigNum > 1){
throw new ServiceException("奖品只能有1个大奖");
}
List<PrizeOnline> dbList = this.selectPrizeOnlineList(gender);
List<Long> dbIds = dbList.stream().map(PrizeOnline::getId).collect(Collectors.toList());