Kaynağa Gözat

提现次数每日限制

zoujiajian 2 yıl önce
ebeveyn
işleme
8b4fc4f55e

+ 1 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -838,6 +838,7 @@ public class RedisService {
         MIDJOURNEY_RELAX_LIMIT("midjourney:relax:limit:", "midjourney relax次数", 60 * 60 * 48L),
         MIDJOURNEY_EXPIRE_TIME("midjourney:expire:time:", "midjourney expire time", 60 * 60 * 48L),
         MIDJOURNEY_USER("midjourney:user:", "midjourney user", 60 * 60 * 2L),
+        APPLY_MONEY_DAY_LIMIT_KEY("apply_money_day_limit_key:%s:%s:%s", "每日提现次数限制", 60 * 60 * 24L),
 
         ;
 

+ 122 - 88
netflix-service/src/main/java/com/cyksj/service/pay/impl/TransferFuncServiceImpl.java

@@ -34,6 +34,7 @@ import com.cyksj.model.entity.*;
 import com.cyksj.model.request.ApplyMoneyReq;
 import com.cyksj.model.request.TransferAccountsReq;
 import com.cyksj.model.request.YhShopApplyMoneyReq;
+import com.cyksj.redis.RedisService;
 import com.cyksj.service.pay.TransferFuncService;
 import com.cyksj.service.user.UserBenefitsService;
 import lombok.RequiredArgsConstructor;
@@ -74,102 +75,38 @@ public class TransferFuncServiceImpl implements TransferFuncService {
 
 	private final DistributeMoneyApplyMapper distributeMoneyApplyMapper;
 
+	private final RedisService redisService;
+
 	@Override
 	public Result distributeApply(ApplyMoneyReq applyMoneyReq) throws Exception {
 		applyMoneyReq.setMType(DistributeMoneyApply.MType.ds);
-		return commonApplyMoney(applyMoneyReq);
+		String key = String.format(RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getName(), DateTime.now().toDateStr(), applyMoneyReq.getMType(), applyMoneyReq.getUserId());
+		if (!redisService.setNx(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout())) {
+			throw BusinessRuntimeException.getInstance("每天仅可提现一次");
+		}
+		Result result = commonApplyMoney(applyMoneyReq);
+		if (result.isFlag()) {
+			redisService.set(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout());
+		} else {
+			redisService.del(key);
+		}
+		return result;
 	}
 
 	@Override
 	public Result yhShopDistributeApply(YhShopApplyMoneyReq applyMoneyReq) throws Exception {
-		Long userId = applyMoneyReq.getUserId();
-		User user = userMapper.selectById(userId);
-		if (user == null) {
-			throw BusinessRuntimeException.getInstance("请先授权登录");
-		}
-		Boolean isTakeAll = applyMoneyReq.getIsTakeAll();
-		YhShopDistributeMoneyApply.Type type = applyMoneyReq.getType();
-		if (type == null) type = YhShopDistributeMoneyApply.Type.zfb;
-		if (type == YhShopDistributeMoneyApply.Type.zfb) {
-			if (ObjectUtil.hasEmpty(applyMoneyReq.getAccount(), applyMoneyReq.getRealName())) {
-				throw BusinessRuntimeException.getInstance("必填项不能为空");
-			}
-			if (applyMoneyReq.getAccount().length() > 255 || applyMoneyReq.getRealName().length() > 32) {
-				throw BusinessRuntimeException.getInstance("请输入正确的账户信息");
-			}
-		}
-		if (type == YhShopDistributeMoneyApply.Type.usdt) {
-			if (StrUtil.isEmpty(applyMoneyReq.getWalletAddr())) {
-				throw BusinessRuntimeException.getInstance("USDT提现钱包地址不能为空");
-			}
-			if (applyMoneyReq.getWalletAddr().length() > 1000) {
-				throw BusinessRuntimeException.getInstance("请输入正确的钱包地址");
-			}
-			if (StrUtil.isNotBlank(applyMoneyReq.getRemark()) && applyMoneyReq.getRemark().length() > 512) {
-				throw BusinessRuntimeException.getInstance("备注过多");
-			}
-			isTakeAll = true;
-
-		}
-		YhShopDistributeMoneyApply distributeMoneyApply = null;
-		if (type == YhShopDistributeMoneyApply.Type.pwdRed) {
-			distributeMoneyApply = yhShopMapper.selectRelationBusiness(userId);
-			isTakeAll = true;
-		}
-
-		BigDecimal needApplyMoney = user.getYhsMoney();
-		BigDecimal fourHundred = BigDecimal.valueOf(4 * 10000);
-		if (isTakeAll == null || !isTakeAll) {
-			if (needApplyMoney.compareTo(fourHundred) > 0) {
-				needApplyMoney = fourHundred;
-			}
+		String type = "shop";
+		String key = String.format(RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getName(), DateTime.now().toDateStr(), type, applyMoneyReq.getUserId());
+		if (!redisService.setNx(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout())) {
+			throw BusinessRuntimeException.getInstance("每天仅可提现一次");
 		}
-		Integer update = userMapper.subYhsMoney(user.getId(), needApplyMoney);
-		if (update == 1) {
-			distributeMoneyApply = Optional.ofNullable(distributeMoneyApply).orElse(new YhShopDistributeMoneyApply());
-			distributeMoneyApply.setUserId(userId);
-			distributeMoneyApply.setMoney(needApplyMoney);
-			distributeMoneyApply.setAccount(applyMoneyReq.getAccount());
-			distributeMoneyApply.setRealName(applyMoneyReq.getRealName());
-			distributeMoneyApply.setWalletAddr(applyMoneyReq.getWalletAddr());
-			distributeMoneyApply.setRemark(applyMoneyReq.getRemark());
-			distributeMoneyApply.setType(applyMoneyReq.getType());
-			if (isTakeAll != null && isTakeAll) {
-				distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.verifying);
-			} else {
-				TransferAccountsReq req = new TransferAccountsReq();
-				req.setMoney(needApplyMoney);
-				req.setAccount(applyMoneyReq.getAccount());
-				req.setName(applyMoneyReq.getRealName());
-				req.setChannelType(2);
-				req.setUserId(userId);
-				req.setRemark("小店提现");
-				AlipayResponse alipayResponse = transferAccounts(req);
-				if (alipayResponse.isSuccess()) {
-					distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.success);
-				} else {
-					distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.fail);
-					distributeMoneyApply.setReason(alipayResponse.getSubMsg());
-					userBenefitsService.addYhsMoney(userId, distributeMoneyApply.getMoney());
-					if (StrUtil.equals(alipayResponse.getSubCode(), "SECURITY_CHECK_FAILED")) {
-						return GatewayResponse.FAIL.newBuilder().setMsg("当前支付宝提现人数较多,请稍后再试").toResult();
-					}
-					return GatewayResponse.FAIL.newBuilder().setMsg("目前财务清账中,48小时后可提现").toResult();
-				}
-			}
-			try {
-				yhShopDistributeMoneyApplyMapper.insert(distributeMoneyApply);
-				//大额提现 超过400
-				if (envCommonService.isPrdEnv() && distributeMoneyApply.getVerifyStatus() == YhShopDistributeMoneyApply.Status.verifying && distributeMoneyApply.getMoney().compareTo(fourHundred) > 0) {
-					SmsUtil.sendLuoKey2Msg(Constant.ZK_MOBILE, "小店店铺有大额提现申请【银河录像局】");
-				}
-			} catch (Exception e) {
-				userBenefitsService.addYhsMoney(userId, distributeMoneyApply.getMoney());
-				return GatewayResponse.FAIL.newBuilder().setMsg("网络错误,请重试").toResult();
-			}
-			return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply);
+		Result result = yhShopApplyMoney(applyMoneyReq);
+		if (result.isFlag()) {
+			redisService.set(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout());
+		} else {
+			redisService.del(key);
 		}
-		throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
+		return result;
 	}
 
 	@Override
@@ -381,7 +318,10 @@ public class TransferFuncServiceImpl implements TransferFuncService {
 					if (StrUtil.equals(alipayResponse.getSubCode(), "SECURITY_CHECK_FAILED")) {
 						return GatewayResponse.FAIL.newBuilder().setMsg("当前支付宝提现人数较多,请稍后再试").toResult();
 					}
-					return GatewayResponse.FAIL.newBuilder().setMsg("目前财务清账中,48小时后可提现").toResult();
+					if (alipayResponse.getSubMsg().contains("冻结")) {
+						return GatewayResponse.FAIL.newBuilder().setMsg("目前财务清账中,48小时后可提现").toResult();
+					}
+					return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
 				}
 			}
 			try {
@@ -398,4 +338,98 @@ public class TransferFuncServiceImpl implements TransferFuncService {
 		}
 		throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
 	}
+
+	public Result yhShopApplyMoney(YhShopApplyMoneyReq applyMoneyReq) throws Exception {
+		Long userId = applyMoneyReq.getUserId();
+		User user = userMapper.selectById(userId);
+		if (user == null) {
+			throw BusinessRuntimeException.getInstance("请先授权登录");
+		}
+		Boolean isTakeAll = applyMoneyReq.getIsTakeAll();
+		YhShopDistributeMoneyApply.Type type = applyMoneyReq.getType();
+		if (type == null) type = YhShopDistributeMoneyApply.Type.zfb;
+		if (type == YhShopDistributeMoneyApply.Type.zfb) {
+			if (ObjectUtil.hasEmpty(applyMoneyReq.getAccount(), applyMoneyReq.getRealName())) {
+				throw BusinessRuntimeException.getInstance("必填项不能为空");
+			}
+			if (applyMoneyReq.getAccount().length() > 255 || applyMoneyReq.getRealName().length() > 32) {
+				throw BusinessRuntimeException.getInstance("请输入正确的账户信息");
+			}
+		}
+		if (type == YhShopDistributeMoneyApply.Type.usdt) {
+			if (StrUtil.isEmpty(applyMoneyReq.getWalletAddr())) {
+				throw BusinessRuntimeException.getInstance("USDT提现钱包地址不能为空");
+			}
+			if (applyMoneyReq.getWalletAddr().length() > 1000) {
+				throw BusinessRuntimeException.getInstance("请输入正确的钱包地址");
+			}
+			if (StrUtil.isNotBlank(applyMoneyReq.getRemark()) && applyMoneyReq.getRemark().length() > 512) {
+				throw BusinessRuntimeException.getInstance("备注过多");
+			}
+			isTakeAll = true;
+
+		}
+		YhShopDistributeMoneyApply distributeMoneyApply = null;
+		if (type == YhShopDistributeMoneyApply.Type.pwdRed) {
+			distributeMoneyApply = yhShopMapper.selectRelationBusiness(userId);
+			isTakeAll = true;
+		}
+
+		BigDecimal needApplyMoney = user.getYhsMoney();
+		BigDecimal fourHundred = BigDecimal.valueOf(4 * 10000);
+		if (isTakeAll == null || !isTakeAll) {
+			if (needApplyMoney.compareTo(fourHundred) > 0) {
+				needApplyMoney = fourHundred;
+			}
+		}
+		Integer update = userMapper.subYhsMoney(user.getId(), needApplyMoney);
+		if (update == 1) {
+			distributeMoneyApply = Optional.ofNullable(distributeMoneyApply).orElse(new YhShopDistributeMoneyApply());
+			distributeMoneyApply.setUserId(userId);
+			distributeMoneyApply.setMoney(needApplyMoney);
+			distributeMoneyApply.setAccount(applyMoneyReq.getAccount());
+			distributeMoneyApply.setRealName(applyMoneyReq.getRealName());
+			distributeMoneyApply.setWalletAddr(applyMoneyReq.getWalletAddr());
+			distributeMoneyApply.setRemark(applyMoneyReq.getRemark());
+			distributeMoneyApply.setType(applyMoneyReq.getType());
+			if (isTakeAll != null && isTakeAll) {
+				distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.verifying);
+			} else {
+				TransferAccountsReq req = new TransferAccountsReq();
+				req.setMoney(needApplyMoney);
+				req.setAccount(applyMoneyReq.getAccount());
+				req.setName(applyMoneyReq.getRealName());
+				req.setChannelType(2);
+				req.setUserId(userId);
+				req.setRemark("小店提现");
+				AlipayResponse alipayResponse = transferAccounts(req);
+				if (alipayResponse.isSuccess()) {
+					distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.success);
+				} else {
+					distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.fail);
+					distributeMoneyApply.setReason(alipayResponse.getSubMsg());
+					userBenefitsService.addYhsMoney(userId, distributeMoneyApply.getMoney());
+					if (StrUtil.equals(alipayResponse.getSubCode(), "SECURITY_CHECK_FAILED")) {
+						return GatewayResponse.FAIL.newBuilder().setMsg("当前支付宝提现人数较多,请稍后再试").toResult();
+					}
+					if (alipayResponse.getSubMsg().contains("冻结")) {
+						return GatewayResponse.FAIL.newBuilder().setMsg("目前财务清账中,48小时后可提现").toResult();
+					}
+					return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
+				}
+			}
+			try {
+				yhShopDistributeMoneyApplyMapper.insert(distributeMoneyApply);
+				//大额提现 超过400
+				if (envCommonService.isPrdEnv() && distributeMoneyApply.getVerifyStatus() == YhShopDistributeMoneyApply.Status.verifying && distributeMoneyApply.getMoney().compareTo(fourHundred) > 0) {
+					SmsUtil.sendLuoKey2Msg(Constant.ZK_MOBILE, "小店店铺有大额提现申请【银河录像局】");
+				}
+			} catch (Exception e) {
+				userBenefitsService.addYhsMoney(userId, distributeMoneyApply.getMoney());
+				return GatewayResponse.FAIL.newBuilder().setMsg("网络错误,请重试").toResult();
+			}
+			return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply);
+		}
+		throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
+	}
 }