任务 抽奖 签到
This commit is contained in:
parent
4750dca914
commit
f4e93e748e
|
|
@ -1,5 +1,6 @@
|
|||
package com.sqx.common.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
|
@ -159,4 +160,17 @@ public class DateUtils {
|
|||
DateTime dateTime = new DateTime(date);
|
||||
return dateTime.plusYears(years).toDate();
|
||||
}
|
||||
|
||||
|
||||
//获取当日剩余秒数
|
||||
public static long todayAfterSecond() {
|
||||
Date now = new Date();
|
||||
// 获取当天结束时间(即当天23:59:59对应的Date对象)
|
||||
Date endOfDay = DateUtil.endOfDay(now);
|
||||
// 计算时间差(单位为毫秒)
|
||||
long diffMillis = endOfDay.getTime() - now.getTime();
|
||||
// 将毫秒转换为秒
|
||||
long diffSeconds = diffMillis / 1000;
|
||||
return diffSeconds;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,5 @@ import java.util.List;
|
|||
@Mapper
|
||||
public interface TaskCenterDao extends BaseMapper<TaskCenter> {
|
||||
|
||||
//大转盘任务
|
||||
List<TaskCenter> queryTaskDiscCenter();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,15 @@ package com.sqx.modules.taskCenter.dao;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterReward;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface TaskCenterRewardDao extends BaseMapper<TaskCenterReward> {
|
||||
|
||||
@Select("SELECT type,number FROM `task_center_reward` where task_id = #{taskId}")
|
||||
Map<Integer, Integer> getRewardMap(Long taskId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,10 @@ public class TaskCenterRecord extends Model<TaskCenterRecord> {
|
|||
private Long id;
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
@ApiModelProperty("任务Id")
|
||||
@ApiModelProperty("任务Id 周任务转盘奖励时 该值为 user_sign_record的id")
|
||||
private Long taskId;
|
||||
@ApiModelProperty("来源Id 目前仅周任务使用")
|
||||
private Long sourceId;
|
||||
@ApiModelProperty("奖励名称")
|
||||
private String name;
|
||||
@ApiModelProperty("奖励类型 1 金币 2 现金 3 4 5 9转盘")
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ import java.util.Map;
|
|||
|
||||
public interface TaskCenterRewardService extends IService<TaskCenterReward> {
|
||||
|
||||
Map<Integer, Integer> getRewardMap(Long taskId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,13 @@ import java.util.Map;
|
|||
|
||||
public interface TaskCenterService extends IService<TaskCenter> {
|
||||
|
||||
//查询任务中心
|
||||
Result queryTaskCenter(Long userId);
|
||||
|
||||
//任务领取
|
||||
Result taskReceive(Long userId, Long id);
|
||||
|
||||
//获取大转盘抽奖次数
|
||||
int countTaskDisc(Long userId,String type);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,5 +15,9 @@ import java.util.Map;
|
|||
public class TaskCenterRewardServiceImpl extends ServiceImpl<TaskCenterRewardDao, TaskCenterReward> implements TaskCenterRewardService {
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> getRewardMap(Long taskId) {
|
||||
return baseMapper.getRewardMap(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,21 @@
|
|||
package com.sqx.modules.taskCenter.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningRecordService;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.taskCenter.dao.TaskCenterDao;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenter;
|
||||
|
|
@ -25,9 +32,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter> implements TaskCenterService {
|
||||
|
|
@ -44,62 +49,89 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private DiscSpinningRecordService discSpinningRecordService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
|
||||
@Override
|
||||
public Result queryTaskCenter(Long userId) {
|
||||
//任务
|
||||
List<TaskCenter> taskPage = baseMapper.selectList(new QueryWrapper<TaskCenter>().eq("shows", 1).orderByAsc("sort", "type"));
|
||||
List<TaskCenter> resultTask = new ArrayList<>();
|
||||
boolean todaySign = true;
|
||||
//月 签到记录
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = signRecordService.count(signWrapper);
|
||||
TaskCenter reTaskCenter = null;
|
||||
Integer signCount = null;
|
||||
for (TaskCenter s : taskPage) {
|
||||
Map<Integer, Integer> rewardMap = taskCenterRewardService.getRewardMap(s.getId());
|
||||
if (CollectionUtil.isEmpty(rewardMap)) {
|
||||
continue;
|
||||
}
|
||||
switch (s.getType()) {
|
||||
//签到任务
|
||||
case 2:
|
||||
//日任务
|
||||
if (s.getNumber().equals(1)) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
if (dayOrderNum < 3) {
|
||||
s.setDiscNumber(dayOrderNum);
|
||||
s.setNumber(3);
|
||||
// s.setDisabled(false);
|
||||
todaySign = false;
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setNumber(null);
|
||||
// s.setDisabled(false);
|
||||
} else {
|
||||
s.setDiscNumber(0);
|
||||
s.setNumber(null);
|
||||
s.setJumpType(0);
|
||||
}
|
||||
} else {
|
||||
if (todaySign) {
|
||||
if ((signCount < (s.getNumber().intValue() - 1))) {
|
||||
s.setDiscNumber(signCount);
|
||||
s.setNumber(null);
|
||||
s.setDisabled(false);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
//周任务
|
||||
if (s.getNumber() > 1 && s.getNumber() < 8) {
|
||||
if (rewardMap.containsKey(9)) {
|
||||
//抽奖次数
|
||||
Map<Integer, Integer> taskWCount = signRecordService.getTaskWCount(userId, rewardMap.get(9));
|
||||
if (CollectionUtil.isNotEmpty(taskWCount)) {
|
||||
for (Integer value : taskWCount.values()) {
|
||||
if (value > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((signCount < s.getNumber().intValue())) {
|
||||
s.setDiscNumber(signCount);
|
||||
Integer wSignCount = signRecordService.getWSignCount(userId);
|
||||
if (wSignCount == null || wSignCount + (todaySign ? 1 : 0) < s.getNumber()) {
|
||||
s.setDiscNumber(wSignCount == null ? 0 : wSignCount);
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
} else {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
}
|
||||
}
|
||||
|
||||
//月任务
|
||||
else if (s.getNumber() > 7 && s.getNumber() < 32) {
|
||||
if (signCount == null) {
|
||||
signCount = signRecordService.getUserSignCount(userId);
|
||||
}
|
||||
if (signCount + (todaySign ? 1 : 0) < s.getNumber()) {
|
||||
s.setDiscNumber(signCount);
|
||||
s.setDisabled(false);
|
||||
} else {
|
||||
if (rewardMap.containsKey(9)) {
|
||||
Integer spinningCount = discSpinningRecordService.countSourceRecord(s.getId());
|
||||
if (spinningCount == null || spinningCount > 0) {
|
||||
break;
|
||||
} else {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
//一次性任务
|
||||
|
|
@ -110,32 +142,29 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
s.setDiscNumber(sumOrderNum);
|
||||
s.setNumber(s.getNumber());
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), null) > 0) {
|
||||
reTaskCenter = s;
|
||||
continue;
|
||||
} else {
|
||||
s.setDiscNumber(0);
|
||||
s.setNumber(null);
|
||||
s.setJumpType(0);
|
||||
}
|
||||
} else if (s.getDetail().contains("绑定支付宝")) {
|
||||
UserEntity userInfo = userService.queryByUserId(userId);
|
||||
if (StringUtils.isNotBlank(userInfo.getZhiFuBao()) && StringUtils.isNotBlank(userInfo.getZhiFuBaoName())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
resultTask.add(s);
|
||||
}
|
||||
if (reTaskCenter != null) {
|
||||
taskPage.remove(reTaskCenter);
|
||||
}
|
||||
return Result.success().put("data", taskPage);
|
||||
return Result.success().put("data", resultTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result taskReceive(Long userId, Long id) {
|
||||
TaskCenter taskCenter = baseMapper.selectById(id);
|
||||
//月 签到记录
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = signRecordService.count(signWrapper);
|
||||
|
||||
if (taskCenter.getType().equals(2)) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
|
|
@ -143,7 +172,7 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
UserSignRecord yesterday = signRecordService.getOne(new QueryWrapper<UserSignRecord>().eq("user_id", userId).eq("sign_day",
|
||||
DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd")));
|
||||
UserSignRecord signRecord = new UserSignRecord();
|
||||
if (yesterday != null && yesterday.getDay() != null) {
|
||||
if (yesterday != null && yesterday.getDay() != null && yesterday.getDay() != 7) {
|
||||
signRecord.setDay(yesterday.getDay() + 1);
|
||||
} else {
|
||||
signRecord.setDay(1);
|
||||
|
|
@ -158,22 +187,6 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
return Result.error("不可重复领取");
|
||||
}
|
||||
signRecordService.save(signRecord);
|
||||
} else {
|
||||
if (dayOrderNum > 2) {
|
||||
if (signCount < (taskCenter.getNumber().intValue() - 1)) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
if (recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
} else {
|
||||
if (signCount < taskCenter.getNumber().intValue()) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
if (recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (taskCenter.getType().equals(3) && taskCenter.getId().equals(1L)) {
|
||||
Integer sumOrderNum = ordersService.countOrderNum(userId, null);
|
||||
|
|
@ -228,49 +241,59 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
|
||||
@Override
|
||||
public int countTaskDisc(Long userId, String type) {
|
||||
int countTaskDisc = 0;
|
||||
Integer signCount = null;
|
||||
if (StringUtils.isBlank(type) || "1".equals(type)) {
|
||||
return 0;
|
||||
}
|
||||
//月 签到记录
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = signRecordService.count(signWrapper);
|
||||
|
||||
//TaskCenter的number为大转盘次数
|
||||
List<TaskCenter> taskCenters = baseMapper.queryTaskDiscCenter();
|
||||
int countTaskDisc = 0;
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
QueryWrapper<TaskCenter> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type", 2);
|
||||
if ("2".equals(type)) {
|
||||
queryWrapper.gt("number", 1);
|
||||
queryWrapper.lt("number", 8);
|
||||
} else if ("3".equals(type)) {
|
||||
queryWrapper.gt("number", 7);
|
||||
queryWrapper.lt("number", 32);
|
||||
}
|
||||
List<TaskCenter> taskCenters = baseMapper.selectList(queryWrapper);
|
||||
for (TaskCenter taskCenter : taskCenters) {
|
||||
if (taskCenter.getType().equals(2)) {
|
||||
if (taskCenter.getNumber().equals(1)) {
|
||||
if (dayOrderNum > 2 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") < 1) {
|
||||
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
|
||||
}
|
||||
} else {
|
||||
if ("2".equals(type) && taskCenter.getNumber().intValue() > 1 && taskCenter.getNumber().intValue() < 8) {
|
||||
if (dayOrderNum > 2) {
|
||||
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 if ("3".equals(type) && taskCenter.getNumber().intValue() > 7 && taskCenter.getNumber().intValue() < 32) {
|
||||
if (dayOrderNum > 2) {
|
||||
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();
|
||||
}
|
||||
Map<Integer, Integer> rewardMap = taskCenterRewardService.getRewardMap(taskCenter.getId());
|
||||
if (CollectionUtil.isEmpty(rewardMap)) {
|
||||
continue;
|
||||
}
|
||||
Map<Integer, Integer> taskWRedisMap = new HashMap<>();
|
||||
if ("2".equals(type)) {
|
||||
//抽奖次数
|
||||
Map<Integer, Integer> taskWCount = signRecordService.getTaskWCount(userId, rewardMap.get(9));
|
||||
if (CollectionUtil.isNotEmpty(taskWCount)) {
|
||||
for (Map.Entry<Integer, Integer> entry : taskWCount.entrySet()) {
|
||||
Integer key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
if (value > 0) {
|
||||
countTaskDisc = countTaskDisc + value;
|
||||
taskWRedisMap.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(taskWRedisMap)) {
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:amount:taskW") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
}
|
||||
} else if ("3".equals(type)) {
|
||||
if (signCount == null) {
|
||||
signCount = signRecordService.getUserSignCount(userId);
|
||||
}
|
||||
if (signCount >= taskCenter.getNumber()) {
|
||||
if (rewardMap.containsKey(9)) {
|
||||
Integer spinningCount = discSpinningRecordService.countSourceRecord(taskCenter.getId());
|
||||
countTaskDisc = countTaskDisc + (spinningCount == null ? 0 : spinningCount);
|
||||
if (countTaskDisc > 0) {
|
||||
taskWRedisMap.put(taskCenter.getId().intValue(), countTaskDisc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(taskWRedisMap)) {
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:amount:taskM") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
}
|
||||
}
|
||||
}
|
||||
return countTaskDisc;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import com.sqx.modules.userSign.entity.UserSignRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface UserSignRecordDao extends BaseMapper<UserSignRecord> {
|
||||
//周 抽奖次数
|
||||
Map<Integer,Integer> getTaskWCount(long userId, int wCount,String time);
|
||||
//周 签到 次数 连续签到
|
||||
Integer getWSignCount(long userId,String time);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,19 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
import com.sqx.modules.userSign.dto.UserSignDTO;
|
||||
import com.sqx.modules.userSign.entity.UserSignRecord;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface UserSignRecordService extends IService<UserSignRecord> {
|
||||
|
||||
UserSignDTO getUserSignData(long userId);
|
||||
|
||||
//获取当月签到次数
|
||||
int getUserSignCount(long userId);
|
||||
//周 剩余抽奖次数
|
||||
Map<Integer,Integer> getTaskWCount(long userId, int wCount);
|
||||
//周 签到 次数
|
||||
Integer getWSignCount(long userId);
|
||||
|
||||
String[] getUserSignAwardConfig();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
|
|
@ -120,6 +121,27 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
|||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserSignCount(long userId) {
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = baseMapper.selectCount(signWrapper);
|
||||
return signCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer,Integer> getTaskWCount(long userId,int wCount) {
|
||||
Date thirtyDaysAgo = DateUtil.offsetDay(new Date(), -30);
|
||||
return baseMapper.getTaskWCount(userId,wCount,DateUtil.format(thirtyDaysAgo, "yyyy-MM-dd")+" 00:00:00");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getWSignCount(long userId) {
|
||||
return baseMapper.getWSignCount(userId, DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd") + " 00:00:00");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUserSignAwardConfig() {
|
||||
CommonInfo config = commonInfoDao.findOne(918);
|
||||
|
|
|
|||
|
|
@ -279,25 +279,21 @@
|
|||
|
||||
|
||||
<select id="selectOrdersCountStatisticsByDay" resultType="Integer">
|
||||
SELECT
|
||||
count(*)
|
||||
FROM
|
||||
orders
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.order_id
|
||||
WHERE
|
||||
orders.user_id = #{userId}
|
||||
SELECT count(*)
|
||||
FROM orders
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.source_id
|
||||
WHERE orders.user_id = #{userId}
|
||||
AND orders.`status` = 1
|
||||
AND orders.`pay_way` = 9
|
||||
AND orders.create_time > DATE_FORMAT( CURDATE(), '%Y-%m-%d 00:00:00' )
|
||||
AND orders.create_time > DATE_FORMAT(CURDATE(), '%Y-%m-%d 00:00:00')
|
||||
AND record.order_id IS NULL
|
||||
ORDER BY
|
||||
orders.create_time
|
||||
ORDER BY orders.create_time
|
||||
</select>
|
||||
|
||||
<select id="selectOrdersByDay" resultType="com.sqx.modules.orders.entity.Orders">
|
||||
SELECT orders.*
|
||||
FROM orders
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.order_id
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.source_id
|
||||
WHERE orders.user_id = #{userId}
|
||||
AND orders.`status` = 1
|
||||
AND orders.`pay_way` = 9
|
||||
|
|
|
|||
|
|
@ -2,13 +2,4 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sqx.modules.taskCenter.dao.TaskCenterDao">
|
||||
|
||||
|
||||
<select id="queryTaskDiscCenter" resultType="com.sqx.modules.taskCenter.entity.TaskCenter">
|
||||
SELECT task.*,
|
||||
reward.number as discNumber
|
||||
FROM task_center_reward reward
|
||||
INNER JOIN task_center task ON reward.task_id = task.id and task.shows = 1
|
||||
where reward.type = 9
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sqx.modules.userSign.dao.UserSignRecordDao">
|
||||
|
||||
<select id="getTaskWCount" resultType="Map">
|
||||
SELECT
|
||||
sign.id,
|
||||
#{wCount} - COUNT(CASE WHEN cenRecord.id IS NULL and record.source_id IS NOT NULL THEN 1 END) AS record_count
|
||||
|
||||
FROM
|
||||
user_sign_record sign
|
||||
LEFT JOIN task_center_record cenRecord on sign.id = cenRecord.source_id
|
||||
LEFT JOIN disc_spinning_record spRecord ON sign.id = spRecord.source_id
|
||||
WHERE
|
||||
sign.`DAY` = 7;
|
||||
AND sign.user_id = #{userId}
|
||||
and sign.create_time > #{time}
|
||||
order by sign.create_time asc
|
||||
</select>
|
||||
|
||||
<select id="getWSignCount" resultType="Integer">
|
||||
SELECT `day`
|
||||
FROM user_sign_record
|
||||
WHERE user_id = #{userId}
|
||||
and create_time > #{time}
|
||||
ORDER BY create_time desc
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue