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