|
|
@@ -19,6 +19,7 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.snowflake.Sequence;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.SmsUtil;
|
|
|
+import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.config.zfb.AliPayClientFactory;
|
|
|
import com.cyksj.config.zfb.ZfbProductCode;
|
|
|
import com.cyksj.dto.Result;
|
|
|
@@ -34,7 +35,9 @@ 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.sys.SysConfigService;
|
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -74,102 +77,50 @@ public class TransferFuncServiceImpl implements TransferFuncService {
|
|
|
|
|
|
private final DistributeMoneyApplyMapper distributeMoneyApplyMapper;
|
|
|
|
|
|
+ private final RedisService redisService;
|
|
|
+
|
|
|
+ private final SysConfigService sysConfigService;
|
|
|
+
|
|
|
@Override
|
|
|
public Result distributeApply(ApplyMoneyReq applyMoneyReq) throws Exception {
|
|
|
applyMoneyReq.setMType(DistributeMoneyApply.MType.ds);
|
|
|
- return commonApplyMoney(applyMoneyReq);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result yhShopDistributeApply(YhShopApplyMoneyReq applyMoneyReq) throws Exception {
|
|
|
- Long userId = applyMoneyReq.getUserId();
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- if (user == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("请先授权登录");
|
|
|
+ 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("每天仅可提现一次");
|
|
|
}
|
|
|
- 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("备注过多");
|
|
|
+ try {
|
|
|
+ Result result = commonApplyMoney(applyMoneyReq);
|
|
|
+ if (result.isFlag()) {
|
|
|
+ redisService.set(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout());
|
|
|
+ } else {
|
|
|
+ redisService.del(key);
|
|
|
}
|
|
|
- isTakeAll = true;
|
|
|
-
|
|
|
- }
|
|
|
- YhShopDistributeMoneyApply distributeMoneyApply = null;
|
|
|
- if (type == YhShopDistributeMoneyApply.Type.pwdRed) {
|
|
|
- distributeMoneyApply = yhShopMapper.selectRelationBusiness(userId);
|
|
|
- isTakeAll = true;
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ redisService.del(key);
|
|
|
+ throw BusinessRuntimeException.getInstance(StringUtil.getErrorMsg(e));
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- BigDecimal needApplyMoney = user.getYhsMoney();
|
|
|
- BigDecimal fourHundred = BigDecimal.valueOf(4 * 10000);
|
|
|
- if (isTakeAll == null || !isTakeAll) {
|
|
|
- if (needApplyMoney.compareTo(fourHundred) > 0) {
|
|
|
- needApplyMoney = fourHundred;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public Result yhShopDistributeApply(YhShopApplyMoneyReq applyMoneyReq) throws Exception {
|
|
|
+ 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);
|
|
|
+ try {
|
|
|
+ Result result = yhShopApplyMoney(applyMoneyReq);
|
|
|
+ if (result.isFlag()) {
|
|
|
+ redisService.set(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout());
|
|
|
} 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();
|
|
|
- }
|
|
|
+ redisService.del(key);
|
|
|
}
|
|
|
- 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);
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ redisService.del(key);
|
|
|
+ throw BusinessRuntimeException.getInstance(StringUtil.getErrorMsg(e));
|
|
|
}
|
|
|
- throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -191,7 +142,7 @@ public class TransferFuncServiceImpl implements TransferFuncService {
|
|
|
name += "xx";
|
|
|
}
|
|
|
Integer scope = transferAccountsReq.getScope();
|
|
|
- AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(ShopConfig.DISTRIBUTE_ZFB_DEFAULT_APP_ID);
|
|
|
+ AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(sysConfigService.getDefaultShopConfigByType("zfb"));
|
|
|
|
|
|
AlipayRequest alipayRequest = aliPayTransferAccountsRequest(donNo, account, name, money, remark);
|
|
|
|
|
|
@@ -381,7 +332,13 @@ 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();
|
|
|
+ }
|
|
|
+ if (alipayResponse.getSubMsg().contains("余额不足")) {
|
|
|
+ return GatewayResponse.FAIL.newBuilder().setMsg("转账失败,请联系客服").toResult();
|
|
|
+ }
|
|
|
+ return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
|
@@ -398,4 +355,101 @@ 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();
|
|
|
+ }
|
|
|
+ if (alipayResponse.getSubMsg().contains("余额不足")) {
|
|
|
+ return GatewayResponse.FAIL.newBuilder().setMsg("转账失败,请联系客服").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("系统异常,请重新提交提现申请");
|
|
|
+ }
|
|
|
}
|