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