提现频率限制3分钟
This commit is contained in:
parent
a120d6acb0
commit
7725dcb352
|
|
@ -1,8 +1,10 @@
|
|||
package com.sqx.modules.pay.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
|
|
@ -13,6 +15,7 @@ import com.alipay.api.request.AlipayFundTransUniTransferRequest;
|
|||
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
|
||||
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
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;
|
||||
|
|
@ -47,6 +50,7 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
|
@ -100,6 +104,8 @@ public class CashController {
|
|||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private SysUserMoneyService sysUserMoneyService;
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(true);
|
||||
|
||||
@RequestMapping(value = "/sendMsgByUserId", method = RequestMethod.GET)
|
||||
|
|
@ -523,7 +529,28 @@ public class CashController {
|
|||
if (StringUtils.isBlank(msg)) {
|
||||
return Result.error("请输入验证码");
|
||||
}
|
||||
return cashOutService.withdraw(userId, money, msg, true);
|
||||
String intervalKey = StrUtil.format("user:withdraw:interval:limit:user:{}", userId);
|
||||
String lockKey = StrUtil.format("user:withdraw:interval:limit:user:lock:{}", userId);
|
||||
if (redisUtils.hasKey(lockKey)) {
|
||||
return Result.error("提现请求处理中,请等待!");
|
||||
}
|
||||
if (redisUtils.hasKey(intervalKey)) {
|
||||
return Result.error("提现请求过于频繁,请稍后再试!");
|
||||
}
|
||||
redisUtils.set(lockKey, true, 30);
|
||||
Result ret = Result.error();
|
||||
try {
|
||||
ret = cashOutService.withdraw(userId, money, msg, true);
|
||||
int code = Convert.toInt(ret.get("code"),-1);
|
||||
if(code == 0){
|
||||
redisUtils.set(intervalKey, true, 60 * 3);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("提现异常", e);
|
||||
} finally {
|
||||
redisUtils.delete(lockKey);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
|
|
@ -18,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/5/15
|
||||
|
|
@ -38,6 +43,9 @@ public class AppCashController {
|
|||
private PayDetailsService payDetailsService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
|
||||
public AppCashController(CommonInfoService commonInfoService, RedisService redisService) {
|
||||
this.commonInfoService = commonInfoService;
|
||||
|
|
@ -67,14 +75,36 @@ public class AppCashController {
|
|||
@Debounce(interval = 3000, value = "#userId")
|
||||
@ApiOperation("发起提现 余额 金钱")
|
||||
public Result withdraw(@RequestAttribute("userId") Long userId, Double amount) {
|
||||
String intervalKey = StrUtil.format("user:withdraw:interval:limit:user:{}", userId);
|
||||
String lockKey = StrUtil.format("user:withdraw:interval:limit:user:lock:{}", userId);
|
||||
if (redisUtils.hasKey(lockKey)) {
|
||||
return Result.error("提现请求处理中,请等待!");
|
||||
}
|
||||
if (redisUtils.hasKey(intervalKey)) {
|
||||
return Result.error("提现请求过于频繁,请稍后再试!");
|
||||
}
|
||||
boolean canCash = redisService.isCanCash(userId);
|
||||
if (!canCash) {
|
||||
CommonInfo info = commonInfoService.findOne(928);
|
||||
if ("1".equals(info.getValue())) {
|
||||
redisUtils.delete(lockKey);
|
||||
return Result.error("您未观看激励广告,清先观看");
|
||||
}
|
||||
}
|
||||
return cashOutService.withdraw(userId, amount, null, false);
|
||||
redisUtils.set(intervalKey, true, 30);
|
||||
Result ret = Result.error();
|
||||
try {
|
||||
ret = cashOutService.withdraw(userId, amount, null, false);
|
||||
int code = Convert.toInt(ret.get("code"),-1);
|
||||
if(code == 0){
|
||||
redisUtils.set(intervalKey, true, 60 * 3);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("提现异常", e);
|
||||
} finally {
|
||||
redisUtils.delete(lockKey);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Login
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import com.github.pagehelper.PageHelper;
|
|||
import com.github.pagehelper.PageInfo;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.dao.MsgDao;
|
||||
import com.sqx.modules.app.dao.UserDao;
|
||||
|
|
@ -58,7 +57,6 @@ import weixin.popular.bean.message.templatemessage.TemplateMessageItem;
|
|||
import weixin.popular.bean.message.templatemessage.TemplateMessageResult;
|
||||
import weixin.popular.support.TokenManager;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.websocket.SendResult;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
|
@ -112,9 +110,6 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
|||
@Autowired
|
||||
private WuyouPay wuyouPay;
|
||||
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
public CashOutServiceImpl(UserInfoService userInfoService) {
|
||||
this.userInfoService = userInfoService;
|
||||
}
|
||||
|
|
@ -497,10 +492,6 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
|||
@Override
|
||||
@Transactional
|
||||
public Result withdraw(Long userId, Double money, String msg, boolean isSys) {
|
||||
boolean isExist = redisUtils.hasKey(StrUtil.format("user:withdraw:interval:limit:user:{}", userId));
|
||||
if(isExist){
|
||||
return Result.error("提现太频繁,请稍后再试!");
|
||||
}
|
||||
if (money == null || money <= 0.00) {
|
||||
return Result.error("请不要输入小于0的数字,请输入正确的提现金额!");
|
||||
}
|
||||
|
|
@ -641,7 +632,6 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
|||
baseMapper.insert(cashOut);
|
||||
userMoneyService.updateAmount(2, userId, money);
|
||||
}
|
||||
redisUtils.set(StrUtil.format("user:withdraw:interval:limit:user:{}", userId), 1, 60 * 3);
|
||||
return Result.success("提现成功,将在三个工作日内到账,请耐心等待!");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue