大转盘抽奖

任务中心
This commit is contained in:
2024-12-20 14:44:53 +08:00
parent 4363e91fa7
commit 8b6a67e17a
7 changed files with 62 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
package com.sqx.modules.discSpinning.controller; package com.sqx.modules.discSpinning.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.annotation.Debounce; import com.sqx.common.annotation.Debounce;
@@ -105,7 +106,7 @@ public class DiscSpinningController {
@GetMapping("/app/discSpinning/selectDiscSpinning") @GetMapping("/app/discSpinning/selectDiscSpinning")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "`1`普通转盘 `2`任务转盘", dataTypeClass = String.class, paramType = "body"), @ApiImplicitParam(name = "type", value = "1 普通转盘 2 周任务转盘 3 月任务转盘", dataTypeClass = String.class, paramType = "body"),
}) })
@ApiOperation("查询大转盘") @ApiOperation("查询大转盘")
public Result selectDiscSpinning(@RequestParam(required = false, defaultValue = "1") Integer type) { public Result selectDiscSpinning(@RequestParam(required = false, defaultValue = "1") Integer type) {
@@ -114,12 +115,11 @@ public class DiscSpinningController {
} }
//14232
@Login @Login
@GetMapping("/app/discSpinning/drawCount") @GetMapping("/app/discSpinning/drawCount")
@ApiOperation("获取大转盘抽奖次数") @ApiOperation("获取大转盘抽奖次数")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "source", value = "`task`任务拉起抽奖 或者 `order` 订单拉起抽奖", dataTypeClass = String.class, paramType = "body"), @ApiImplicitParam(name = "source", value = "`1` 订单拉起抽奖 `2` 周任务拉起抽奖 `3` 月任务拉起抽奖", dataTypeClass = String.class, paramType = "body"),
}) })
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "{\"sum\":\"总抽奖次数\",\"count\":\"剩余抽奖次数\"}"), @ApiResponse(code = 200, message = "{\"sum\":\"总抽奖次数\",\"count\":\"剩余抽奖次数\"}"),
@@ -128,9 +128,9 @@ public class DiscSpinningController {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue()); int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
map.put("sum", drawCount); map.put("sum", drawCount);
if (maps != null && maps.containsKey("source") && "task".equals(maps.get("source"))) { if (maps != null && maps.containsKey("source") && !"1".equals(maps.get("source"))) {
//任务可抽奖次数 //任务可抽奖次数
map.put("count", taskCenterService.countTaskDisc(userId)); map.put("count", taskCenterService.countTaskDisc(userId,maps.get("source").toString()));
} else { } else {
int i = recordService.countDraw(userId); int i = recordService.countDraw(userId);
if (drawCount - i > 0) { if (drawCount - i > 0) {
@@ -145,28 +145,33 @@ public class DiscSpinningController {
@Login @Login
@GetMapping("/app/discSpinning/draw") @GetMapping("/app/discSpinning/draw")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "source", value = "`task`任务拉起抽奖 或者 `order` 订单拉起抽奖", dataTypeClass = String.class, paramType = "body"), @ApiImplicitParam(name = "source", value = "1 普通转盘 2 周任务转盘 3 月任务转盘", dataTypeClass = String.class, paramType = "body"),
}) })
@ApiOperation("抽取大转盘") @ApiOperation("抽取大转盘")
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @Nullable @ApiIgnore @RequestBody Map maps) { public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @Nullable @ApiIgnore @RequestBody Map maps) {
double amount = 0; double amount = 0;
int discType = 1;
Long orderId = null; Long orderId = null;
Integer i = recordService.countDraw(userId); Integer i = recordService.countDraw(userId);
if (maps == null || !maps.containsKey("source") || !"task".equals(maps.get("source"))) { if (maps == null || !maps.containsKey("source") || !"1".equals(maps.get("source"))) {
//任务抽奖 //任务抽奖
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue()); int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
if (i != null && i >= drawCount) { if (i != null && i >= drawCount) {
return Result.error("当日可抽奖次数已超限"); return Result.error("当日可抽奖次数已超限");
} }
Orders orders = ordersService.selectOrdersByDay(userId); Orders orders = ordersService.selectOrdersByDay(userId);
amount = orders.getPayMoney().doubleValue();
orderId = orders.getOrdersId();
if (orders == null) { if (orders == null) {
return Result.error("无可抽奖机会"); return Result.error("无可抽奖机会");
} }
amount = orders.getPayMoney().doubleValue();
orderId = orders.getOrdersId();
}
if (CollectionUtil.isNotEmpty(maps) && maps.containsKey("source")) {
discType = Integer.parseInt(maps.get("source").toString());
} }
return new Result().put("data", return new Result().put("data",
discSpinningService.draws(i == null ? 1 : i + 1, amount, orderId, userId, maps == null || maps.get("source") == null ? "order" : maps.get("source").toString())); discSpinningService.draws(i == null ? 1 : i + 1, amount, orderId, userId, discType));
} }
@ApiOperation("大转盘奖项领取") @ApiOperation("大转盘奖项领取")

View File

@@ -25,8 +25,6 @@ public class DiscSpinning extends Model<DiscSpinning> {
private Integer type; private Integer type;
//数值 //数值
private BigDecimal number; private BigDecimal number;
//红包金额比例
private BigDecimal ratio;
//中奖概率 //中奖概率
private BigDecimal odds; private BigDecimal odds;
//创建时间 //创建时间

View File

@@ -47,7 +47,7 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
} }
public DiscSpinningRecord(String name, Long orderId, Long userId, Integer type, BigDecimal number, public DiscSpinningRecord(String name, Long orderId, Long userId, Integer type, BigDecimal number,
String drawDay, String createTime, String source) { String drawDay, String createTime, Integer source) {
this.name = name; this.name = name;
this.userId = userId; this.userId = userId;
this.orderId = orderId; this.orderId = orderId;
@@ -55,8 +55,20 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
this.number = number; this.number = number;
this.drawDay = drawDay; this.drawDay = drawDay;
this.createTime = createTime; this.createTime = createTime;
if (StringUtils.isNotBlank(source)) { if (source != null) {
this.source = source; switch (source) {
case 1:
this.source = "order";
break;
case 2:
this.source = "taskW";
break;
case 3:
this.source = "taskM";
break;
default:
this.source = source.toString();
}
} }
} }
} }

View File

@@ -8,7 +8,7 @@ import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
public interface DiscSpinningService extends IService<DiscSpinning> { public interface DiscSpinningService extends IService<DiscSpinning> {
//抽奖 //抽奖
DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, String source); DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, Integer source);
//领奖 //领奖
void receiveAsync(DiscSpinningRecord receive); void receiveAsync(DiscSpinningRecord receive);

View File

@@ -167,9 +167,9 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
@Override @Override
@Transactional @Transactional
public DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, String source) { public DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, Integer source) {
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null); DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null);
List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", "order".equals(source) ? 1 : 2).orderByAsc("odds")); List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", source).orderByAsc("odds"));
Random random = new Random(); Random random = new Random();
double randomDouble; double randomDouble;
@@ -212,12 +212,14 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
} }
result = new DiscSpinning(prize.getName(), 2, new BigDecimal(resultAmount).setScale(2, RoundingMode.HALF_UP)); result = new DiscSpinning(prize.getName(), 2, new BigDecimal(resultAmount).setScale(2, RoundingMode.HALF_UP));
break; break;
} else {
if (source != 1) {
result = prize;
}
} }
// else {
// result = prize;
// }
} }
} }
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), orderId, userId, result.getType(), DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), orderId, userId, result.getType(),
result.getNumber(), DateUtils.formatYMD(new Date()), DateUtils.format(new Date()), source); result.getNumber(), DateUtils.formatYMD(new Date()), DateUtils.format(new Date()), source);
recordService.save(record); recordService.save(record);

View File

@@ -12,6 +12,6 @@ public interface TaskCenterService extends IService<TaskCenter> {
Result taskReceive(Long userId, Long id); Result taskReceive(Long userId, Long id);
int countTaskDisc(Long userId); int countTaskDisc(Long userId,String type);
} }

View File

@@ -19,6 +19,7 @@ import com.sqx.modules.taskCenter.service.TaskCenterRewardService;
import com.sqx.modules.taskCenter.service.TaskCenterService; import com.sqx.modules.taskCenter.service.TaskCenterService;
import com.sqx.modules.userSign.entity.UserSignRecord; import com.sqx.modules.userSign.entity.UserSignRecord;
import com.sqx.modules.userSign.service.UserSignRecordService; import com.sqx.modules.userSign.service.UserSignRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -226,7 +227,10 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
} }
@Override @Override
public int countTaskDisc(Long userId) { public int countTaskDisc(Long userId, String type) {
if (StringUtils.isBlank(type) || "1".equals(type)) {
return 0;
}
//月 签到记录 //月 签到记录
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>(); QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
signWrapper.eq("user_id", userId); signWrapper.eq("user_id", userId);
@@ -245,16 +249,27 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber(); countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
} }
} else { } else {
if (dayOrderNum > 2) { if ("2".equals(type) && taskCenter.getNumber().intValue() > 1 && taskCenter.getNumber().intValue() < 8) {
if (signCount - taskCenter.getNumber().intValue() >= -1 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) { if (dayOrderNum > 2) {
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber(); if (signCount - taskCenter.getNumber().intValue() >= -1 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
}
} else {
if (signCount - taskCenter.getNumber().intValue() >= 0 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
}
} }
} else { } else if ("3".equals(type) && taskCenter.getNumber().intValue() > 7 && taskCenter.getNumber().intValue() < 32) {
if (signCount - taskCenter.getNumber().intValue() >= 0 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) { if (dayOrderNum > 2) {
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber(); if (signCount - taskCenter.getNumber().intValue() >= -1 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
}
} else {
if (signCount - taskCenter.getNumber().intValue() >= 0 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
}
} }
} }
} }
} }
} }