This commit is contained in:
777
2026-01-07 11:30:24 +08:00
parent 56129fb865
commit 20c5908f34
7 changed files with 91 additions and 37 deletions

View File

@@ -5,7 +5,6 @@ import com.ruoyi.cai.domain.PointChangeLog;
import com.ruoyi.cai.domain.PrizeOnline;
import com.ruoyi.cai.domain.User;
import com.ruoyi.cai.enums.GenderEnum;
import com.ruoyi.cai.enums.SystemConfigEnum;
import com.ruoyi.cai.manager.IdManager;
import com.ruoyi.cai.manager.SystemConfigManager;
import com.ruoyi.cai.service.AccountService;
@@ -17,7 +16,6 @@ import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -63,20 +61,30 @@ public class LotteryService {
return systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.MEN_DRAW_POINT);
}
public boolean getOpenDraw(Integer gender){
if(GenderEnum.WOMEN.getCode().equals(gender)){
return systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_DRAW_WOMEN);
}else if(GenderEnum.MAN.getCode().equals(gender)){
return systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_DRAW_MAN);
}
return false;
}
/**
* 用户抽奖(核心方法,优化后)
* @param userId 用户ID
* @return 中奖奖品
*/
public PrizeOnline draw(Long userId) {
boolean openDraw = systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_DRAW);
if(!openDraw){
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
}
User user = userService.getById(userId);
if(user == null){
throw new ServiceException("用户不存在");
}
boolean openDraw = this.getOpenDraw(user.getGender());
if(!openDraw){
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
}
boolean select = GenderEnum.isSelect(user.getGender());
if(select){
throw new ServiceException("请选择性别后在抽奖");