任务 抽奖 签到
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.sqx.modules.discSpinning.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.RedisKeys;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
@@ -16,6 +19,8 @@ import com.sqx.modules.discSpinning.service.DiscSpinningRecordService;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningService;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterRecord;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterRecordService;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterService;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -41,18 +46,23 @@ public class DiscSpinningController {
|
||||
private final CommonInfoService commonRepository;
|
||||
private final OrdersService ordersService;
|
||||
private final TaskCenterService taskCenterService;
|
||||
private final TaskCenterRecordService taskRecordService;
|
||||
private final UserService userService;
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Autowired
|
||||
public DiscSpinningController(CommonInfoService commonRepository, DiscSpinningService discSpinningService,
|
||||
OrdersService ordersService, DiscSpinningRecordService recordService,
|
||||
TaskCenterService taskCenterService, UserService userService) {
|
||||
TaskCenterService taskCenterService, UserService userService, RedisUtils redisUtils,
|
||||
TaskCenterRecordService taskRecordService) {
|
||||
this.commonRepository = commonRepository;
|
||||
this.discSpinningService = discSpinningService;
|
||||
this.ordersService = ordersService;
|
||||
this.recordService = recordService;
|
||||
this.taskCenterService = taskCenterService;
|
||||
this.userService = userService;
|
||||
this.redisUtils = redisUtils;
|
||||
this.taskRecordService = taskRecordService;
|
||||
}
|
||||
|
||||
@PostMapping("/discSpinning/insertDiscSpinning")
|
||||
@@ -143,6 +153,7 @@ public class DiscSpinningController {
|
||||
//任务可抽奖次数
|
||||
map.put("count", taskCenterService.countTaskDisc(userId, source.toString()));
|
||||
} else {
|
||||
//订单可抽奖次数
|
||||
int i = recordService.countDraw(userId);
|
||||
if (drawCount - i > 0) {
|
||||
map.put("count", ordersService.selectOrdersCountStatisticsByDay(userId, drawCount - i));
|
||||
@@ -161,10 +172,11 @@ public class DiscSpinningController {
|
||||
@ApiOperation("抽取大转盘")
|
||||
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @RequestParam(required = false, defaultValue = "1") Integer source) {
|
||||
double amount = 0;
|
||||
Long orderId = null;
|
||||
Long sourceId = null;
|
||||
Integer i = recordService.countDraw(userId);
|
||||
if (source != null && source.equals(1)) {
|
||||
//任务抽奖
|
||||
if (source == null || source.equals(1)) {
|
||||
source = 1;
|
||||
//订单抽奖
|
||||
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
||||
if (i != null && i >= drawCount) {
|
||||
return Result.error("当日可抽奖次数已超限");
|
||||
@@ -174,12 +186,41 @@ public class DiscSpinningController {
|
||||
return Result.error("无可抽奖机会");
|
||||
}
|
||||
amount = orders.getPayMoney().doubleValue();
|
||||
orderId = orders.getOrdersId();
|
||||
} else if (source == null) {
|
||||
source = 1;
|
||||
sourceId = orders.getOrdersId();
|
||||
} else {
|
||||
String redisKey = "";
|
||||
if (source.equals(2)){
|
||||
redisKey = RedisKeys.getDateKey("spinning:amount:taskW") + userId;
|
||||
}else if(source.equals(3)){
|
||||
redisKey = RedisKeys.getDateKey("spinning:amount:taskM") + userId;
|
||||
}
|
||||
Map<Integer, Integer> week = redisUtils.get(redisKey, Map.class);
|
||||
for (Map.Entry<Integer, Integer> entry : week.entrySet()) {
|
||||
Integer value = entry.getValue();
|
||||
if (value > 1) {
|
||||
value = value - 1;
|
||||
week.put(entry.getKey(), value);
|
||||
break;
|
||||
} else {
|
||||
TaskCenterRecord centerRecord = new TaskCenterRecord();
|
||||
centerRecord.setUserId(userId);
|
||||
centerRecord.setTaskId(entry.getKey().longValue());
|
||||
if(source.equals(2)){
|
||||
centerRecord.setSourceId(entry.getKey().longValue());
|
||||
}
|
||||
centerRecord.setName(source.equals(2) ? "周任务奖励" : "月任务奖励");
|
||||
centerRecord.setType(9);
|
||||
centerRecord.setNumber(1);
|
||||
centerRecord.setCreateTime(DateUtil.now());
|
||||
taskRecordService.save(centerRecord);
|
||||
week.remove(entry.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
redisUtils.set(redisKey,week,DateUtils.todayAfterSecond());
|
||||
}
|
||||
return new Result().put("data",
|
||||
discSpinningService.draws(i == null ? 1 : i + 1, amount, orderId, userId, source));
|
||||
discSpinningService.draws(i == null ? 1 : i + 1, amount, sourceId, userId, source));
|
||||
}
|
||||
|
||||
@ApiOperation("大转盘奖项领取")
|
||||
@@ -191,9 +232,11 @@ public class DiscSpinningController {
|
||||
discSpinningService.receiveAsync(record);
|
||||
});
|
||||
UserEntity userInfo = userService.queryByUserId(record.getUserId());
|
||||
int res = 0;
|
||||
if (StringUtils.isNotBlank(userInfo.getZhiFuBao()) && StringUtils.isNotBlank(userInfo.getZhiFuBaoName())) {
|
||||
res = 1;
|
||||
int res = 1;
|
||||
if (receive.getType().equals(2)) {
|
||||
if (StringUtils.isBlank(userInfo.getZhiFuBao()) && StringUtils.isBlank(userInfo.getZhiFuBaoName())) {
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
return Result.success().put("data", res);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
|
||||
//主键
|
||||
private Long id;
|
||||
|
||||
private Long orderId;
|
||||
private Long sourceId;
|
||||
|
||||
private Long userId;
|
||||
//描述
|
||||
@@ -46,11 +46,11 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
|
||||
public DiscSpinningRecord() {
|
||||
}
|
||||
|
||||
public DiscSpinningRecord(String name, Long orderId, Long userId, Integer type, BigDecimal number,
|
||||
public DiscSpinningRecord(String name, Long sourceId, Long userId, Integer type, BigDecimal number,
|
||||
String drawDay, String createTime, Integer source) {
|
||||
this.name = name;
|
||||
this.userId = userId;
|
||||
this.orderId = orderId;
|
||||
this.sourceId = sourceId;
|
||||
this.type = type;
|
||||
this.number = number;
|
||||
this.drawDay = drawDay;
|
||||
|
||||
@@ -8,5 +8,7 @@ import java.util.Map;
|
||||
public interface DiscSpinningRecordService extends IService<DiscSpinningRecord> {
|
||||
|
||||
Integer countDraw(Long userId);
|
||||
//当月的 月记录 已抽 抽奖次数
|
||||
Integer countSourceRecord(Long sourceId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.sqx.modules.discSpinning.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.modules.discSpinning.dao.DiscSpinningRecordDao;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningRecordService;
|
||||
import com.sqx.modules.userSign.entity.UserSignRecord;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@@ -21,5 +24,13 @@ public class DiscSpinningRecordServiceImpl extends ServiceImpl<DiscSpinningRecor
|
||||
public Integer countDraw(Long userId) {
|
||||
return discSpinningRecordDao.countDraw(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countSourceRecord(Long sourceId) {
|
||||
QueryWrapper<DiscSpinningRecord> recordQuery = new QueryWrapper<>();
|
||||
recordQuery.eq("source_id", sourceId);
|
||||
recordQuery.gt("create_time", DateUtil.beginOfMonth(new Date()));
|
||||
return discSpinningRecordDao.selectCount(recordQuery);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, Integer source) {
|
||||
public DiscSpinningRecord draws(int drawCount, double orderAmount, Long sourceId, Long userId, Integer source) {
|
||||
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null);
|
||||
List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", source).orderByAsc("odds"));
|
||||
|
||||
@@ -221,7 +221,7 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
||||
}
|
||||
}
|
||||
|
||||
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), orderId, userId, result.getType(),
|
||||
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), sourceId, userId, result.getType(),
|
||||
result.getNumber(), DateUtils.formatYMD(new Date()), DateUtils.format(new Date()), source);
|
||||
recordService.save(record);
|
||||
return record;
|
||||
|
||||
Reference in New Issue
Block a user