抽奖到账机制优化
This commit is contained in:
@@ -28,7 +28,8 @@ public class DataLimitUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认 当月5次
|
* 默认 当月5次
|
||||||
* @param key 名称 sys:data:名称
|
*
|
||||||
|
* @param key 名称 sys:data:名称
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String key) {
|
public static boolean isAccessAllowed(String key) {
|
||||||
@@ -51,8 +52,9 @@ public class DataLimitUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认月 month/月/自然月
|
* 默认月 month/月/自然月
|
||||||
* @param key 名称 sys:data:名称
|
*
|
||||||
* @param count 次数限制
|
* @param key 名称 sys:data:名称
|
||||||
|
* @param count 次数限制
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String key, Integer count) {
|
public static boolean isAccessAllowed(String key, Integer count) {
|
||||||
@@ -74,8 +76,9 @@ public class DataLimitUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认 5次
|
* 默认 5次
|
||||||
|
*
|
||||||
* @param key 名称 sys:data:名称
|
* @param key 名称 sys:data:名称
|
||||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String key, String timeFormat) {
|
public static boolean isAccessAllowed(String key, String timeFormat) {
|
||||||
@@ -95,10 +98,19 @@ public class DataLimitUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAllowed(String key, int seconds) {
|
||||||
|
String redisKey = generateRedisKey(key);
|
||||||
|
if (!redisUtils.hasKey(key)) {
|
||||||
|
redisUtils.set(redisKey, 1, seconds);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key 名称 sys:data:名称
|
* @param key 名称 sys:data:名称
|
||||||
* @param count 次数限制
|
* @param count 次数限制
|
||||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isAccessAllowed(String key, Integer count, String timeFormat) {
|
public static boolean isAccessAllowed(String key, Integer count, String timeFormat) {
|
||||||
@@ -127,7 +139,7 @@ public class DataLimitUtil {
|
|||||||
Date now = DateUtil.beginOfDay(DateUtil.date());
|
Date now = DateUtil.beginOfDay(DateUtil.date());
|
||||||
Date expireDate = null;
|
Date expireDate = null;
|
||||||
if ("day".equals(timePeriod)) {
|
if ("day".equals(timePeriod)) {
|
||||||
expireDate = DateUtil.endOfDay(now);
|
expireDate = DateUtil.endOfDay(now);
|
||||||
} else if ("week".equals(timePeriod)) {
|
} else if ("week".equals(timePeriod)) {
|
||||||
expireDate = DateUtil.endOfWeek(now);
|
expireDate = DateUtil.endOfWeek(now);
|
||||||
} else if ("month".equals(timePeriod)) {
|
} else if ("month".equals(timePeriod)) {
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
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;
|
||||||
import com.sqx.common.utils.DateUtils;
|
import com.sqx.common.utils.*;
|
||||||
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.annotation.Login;
|
||||||
import com.sqx.modules.app.service.UserService;
|
import com.sqx.modules.app.service.UserService;
|
||||||
import com.sqx.modules.common.service.CommonInfoService;
|
import com.sqx.modules.common.service.CommonInfoService;
|
||||||
@@ -167,6 +164,7 @@ public class DiscSpinningController {
|
|||||||
@ApiImplicitParam(name = "source", value = "1 普通转盘 2 周任务转盘 3 月任务转盘", dataTypeClass = Integer.class),
|
@ApiImplicitParam(name = "source", value = "1 普通转盘 2 周任务转盘 3 月任务转盘", dataTypeClass = Integer.class),
|
||||||
})
|
})
|
||||||
@ApiOperation("抽取大转盘")
|
@ApiOperation("抽取大转盘")
|
||||||
|
@Debounce(interval = 3000, value = "#userId")
|
||||||
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @RequestParam(required = false, defaultValue = "1") Integer source) {
|
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @RequestParam(required = false, defaultValue = "1") Integer source) {
|
||||||
double amount = 0;
|
double amount = 0;
|
||||||
Long sourceId = null;
|
Long sourceId = null;
|
||||||
@@ -219,11 +217,16 @@ public class DiscSpinningController {
|
|||||||
}
|
}
|
||||||
redisUtils.set(redisKey, week, DateUtils.todayAfterSecond());
|
redisUtils.set(redisKey, week, DateUtils.todayAfterSecond());
|
||||||
}
|
}
|
||||||
DiscSpinningRecord draws = discSpinningService.draws(i == null ? 1 : i + 1, amount, sourceId, userId, source);
|
if (source == 1 && sourceId == null) {
|
||||||
|
throw new RuntimeException("异常请求");
|
||||||
executor.schedule(() -> discSpinningService.receive1(draws), 4, TimeUnit.SECONDS);
|
}
|
||||||
|
if (DataLimitUtil.isAllowed(RedisKeys.getDateKey("spinning:draw:") + sourceId, 120)) {
|
||||||
return new Result().put("data", draws);
|
DiscSpinningRecord draws = discSpinningService.draws(i == null ? 1 : i + 1, amount, sourceId, userId, source);
|
||||||
|
executor.schedule(() -> discSpinningService.receive1(draws), 4, TimeUnit.SECONDS);
|
||||||
|
return new Result().put("data", draws);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("异常请求");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("大转盘奖项领取")
|
@ApiOperation("大转盘奖项领取")
|
||||||
@@ -234,6 +237,5 @@ public class DiscSpinningController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ public interface DiscSpinningService extends IService<DiscSpinning> {
|
|||||||
//提现
|
//提现
|
||||||
void withdrawAsync(UserEntity userInfo, Double money, String title);
|
void withdrawAsync(UserEntity userInfo, Double money, String title);
|
||||||
|
|
||||||
Result receive1(DiscSpinningRecord receive);
|
//领取
|
||||||
|
void receive1(DiscSpinningRecord receive);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||||||
cashOut.setState(2);
|
cashOut.setState(2);
|
||||||
cashOut.setRefund("提现失败,请检查支付宝账号与收款人姓名后,重试。");
|
cashOut.setRefund("提现失败,请检查支付宝账号与收款人姓名后,重试。");
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||||
userInfo.getUserId(), null, null, title, 4, 2, 1,
|
userInfo.getUserId(), null, null, title, 4, 2, 1,
|
||||||
new BigDecimal(money), "现金红包自动提现" + money + "元", 1);
|
new BigDecimal(money), "现金红包自动提现" + money + "元", 1);
|
||||||
@@ -254,22 +254,17 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result receive1(DiscSpinningRecord receive) {
|
public void receive1(DiscSpinningRecord receive) {
|
||||||
|
if (recordService.countDraw(receive.getUserId()) > 10) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
DiscSpinningRecord record = recordService.getById(receive.getId());
|
DiscSpinningRecord record = recordService.getById(receive.getId());
|
||||||
if (record.getTargetId() != null) {
|
if (record.getTargetId() != null) {
|
||||||
return Result.error("不可重复领取");
|
return;
|
||||||
}
|
}
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
receiveAsync(record);
|
receiveAsync(record);
|
||||||
});
|
});
|
||||||
UserEntity userInfo = userService.queryByUserId(record.getUserId());
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user