TransferFuncServiceImpl.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. package com.cyksj.service.pay.impl;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import cn.hutool.json.JSONObject;
  6. import com.alipay.api.AlipayClient;
  7. import com.alipay.api.AlipayRequest;
  8. import com.alipay.api.AlipayResponse;
  9. import com.alipay.api.domain.AlipayFundTransUniTransferModel;
  10. import com.alipay.api.domain.Participant;
  11. import com.alipay.api.request.AlipayFundTransUniTransferRequest;
  12. import com.baomidou.mybatisplus.core.toolkit.Assert;
  13. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  14. import com.cyksj.common.EnvCommonService;
  15. import com.cyksj.common.constant.Constant;
  16. import com.cyksj.common.constant.TransferConstant;
  17. import com.cyksj.common.exception.BusinessRuntimeException;
  18. import com.cyksj.common.snowflake.Sequence;
  19. import com.cyksj.common.util.Jsons;
  20. import com.cyksj.common.util.SmsUtil;
  21. import com.cyksj.common.util.StringUtil;
  22. import com.cyksj.config.zfb.AliPayClientFactory;
  23. import com.cyksj.config.zfb.ZfbProductCode;
  24. import com.cyksj.dto.Result;
  25. import com.cyksj.enums.GatewayResponse;
  26. import com.cyksj.mapper.TransferAccountsRecordMapper;
  27. import com.cyksj.mapper.UserMapper;
  28. import com.cyksj.mapper.manage.distribute.DistributeMoneyApplyMapper;
  29. import com.cyksj.mapper.manage.distribute.DistributePointsExchangeMoneyMapper;
  30. import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
  31. import com.cyksj.mapper.shop.YhShopDistributeMoneyApplyMapper;
  32. import com.cyksj.mapper.shop.YhShopMapper;
  33. import com.cyksj.model.entity.*;
  34. import com.cyksj.model.request.ApplyMoneyReq;
  35. import com.cyksj.model.request.TransferAccountsReq;
  36. import com.cyksj.model.request.YhShopApplyMoneyReq;
  37. import com.cyksj.redis.RedisService;
  38. import com.cyksj.service.pay.TransferFuncService;
  39. import com.cyksj.service.sys.SysConfigService;
  40. import com.cyksj.service.user.UserBenefitsService;
  41. import lombok.RequiredArgsConstructor;
  42. import lombok.extern.slf4j.Slf4j;
  43. import org.springframework.stereotype.Service;
  44. import java.math.BigDecimal;
  45. import java.math.RoundingMode;
  46. import java.util.Optional;
  47. /*
  48. *项目名: yhlxj
  49. *文件名: TransferFuncServiceImpl
  50. *创建者: JavaZou
  51. *创建时间:2023/9/20 18:55
  52. */
  53. @Service
  54. @RequiredArgsConstructor
  55. @Slf4j
  56. public class TransferFuncServiceImpl implements TransferFuncService {
  57. private static final Sequence SEQUENCE = new Sequence(0);
  58. private final TransferAccountsRecordMapper transferAccountsRecordMapper;
  59. private final YhShopMapper yhShopMapper;
  60. private final UserMapper userMapper;
  61. private final UserBenefitsService userBenefitsService;
  62. private final YhShopDistributeMoneyApplyMapper yhShopDistributeMoneyApplyMapper;
  63. private final EnvCommonService envCommonService;
  64. private final UserDistributeMapper userDistributeMapper;
  65. private final DistributePointsExchangeMoneyMapper distributePointsExchangeMoneyMapper;
  66. private final DistributeMoneyApplyMapper distributeMoneyApplyMapper;
  67. private final RedisService redisService;
  68. private final SysConfigService sysConfigService;
  69. @Override
  70. public Result distributeApply(ApplyMoneyReq applyMoneyReq) throws Exception {
  71. applyMoneyReq.setMType(DistributeMoneyApply.MType.ds);
  72. String key = String.format(RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getName(), DateTime.now().toDateStr(), applyMoneyReq.getMType(), applyMoneyReq.getUserId());
  73. if (!redisService.setNx(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout())) {
  74. throw BusinessRuntimeException.getInstance("每天仅可提现一次");
  75. }
  76. try {
  77. Result result = commonApplyMoney(applyMoneyReq);
  78. if (result.isFlag()) {
  79. redisService.set(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout());
  80. } else {
  81. redisService.del(key);
  82. }
  83. return result;
  84. } catch (Exception e) {
  85. redisService.del(key);
  86. throw BusinessRuntimeException.getInstance(StringUtil.getErrorMsg(e));
  87. }
  88. }
  89. @Override
  90. public Result yhShopDistributeApply(YhShopApplyMoneyReq applyMoneyReq) throws Exception {
  91. String type = "shop";
  92. String key = String.format(RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getName(), DateTime.now().toDateStr(), type, applyMoneyReq.getUserId());
  93. if (!redisService.setNx(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout())) {
  94. throw BusinessRuntimeException.getInstance("每天仅可提现一次");
  95. }
  96. try {
  97. Result result = yhShopApplyMoney(applyMoneyReq);
  98. if (result.isFlag()) {
  99. redisService.set(key, applyMoneyReq.getUserId(), RedisService.key.APPLY_MONEY_DAY_LIMIT_KEY.getTimeout());
  100. } else {
  101. redisService.del(key);
  102. }
  103. return result;
  104. } catch (Exception e) {
  105. redisService.del(key);
  106. throw BusinessRuntimeException.getInstance(StringUtil.getErrorMsg(e));
  107. }
  108. }
  109. @Override
  110. public AlipayResponse transferAccounts(TransferAccountsReq transferAccountsReq) throws Exception {
  111. Long userId = transferAccountsReq.getUserId();
  112. String account = transferAccountsReq.getAccount();
  113. String name = transferAccountsReq.getName();
  114. BigDecimal money = transferAccountsReq.getMoney();
  115. String type = transferAccountsReq.getType();
  116. BigDecimal points = transferAccountsReq.getPoints();
  117. Integer channelType = transferAccountsReq.getChannelType();
  118. String remark = transferAccountsReq.getRemark();
  119. /* 生成商户转账订单号 */
  120. String donNo = SEQUENCE.nextId().toString();
  121. if (StrUtil.isEmpty(type)) {
  122. type = TransferConstant.ALIPAY;
  123. }
  124. if (!envCommonService.isPrdEnv()) {
  125. name += "xx";
  126. }
  127. Integer scope = transferAccountsReq.getScope();
  128. AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(sysConfigService.getDefaultShopConfigByType("zfb"));
  129. AlipayRequest alipayRequest = aliPayTransferAccountsRequest(donNo, account, name, money, remark);
  130. AlipayResponse response = alipayClient.certificateExecute(alipayRequest);
  131. if (response.isSuccess()) {
  132. log.info("支付宝转账金额:{}至用户:{}成功", money.divide(BigDecimal.valueOf(100)), userId);
  133. saveTransferRecord(userId, donNo, account, name, money, points, type, scope, response.getBody(), null, channelType);
  134. return response;
  135. }
  136. log.info("支付宝转账金额:{}至用户:{}失败", money.divide(BigDecimal.valueOf(100)), userId);
  137. saveTransferRecord(userId, donNo, account, name, money, points, type, scope, response.getBody(), response.getSubMsg(), channelType);
  138. return response;
  139. }
  140. @Override
  141. public Result<String> subApplyMoney(ApplyMoneyReq applyMoneyReq) throws Exception {
  142. applyMoneyReq.setMType(DistributeMoneyApply.MType.sub);
  143. return commonApplyMoney(applyMoneyReq);
  144. }
  145. private AlipayRequest aliPayTransferAccountsRequest(String donNo, String account, String name, BigDecimal money, String remark) {
  146. //支付宝转账
  147. AlipayFundTransUniTransferRequest transUniTransferRequest = new AlipayFundTransUniTransferRequest();
  148. //转账参数
  149. AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
  150. model.setOutBizNo(donNo);
  151. //单位元
  152. model.setTransAmount(money.divide(BigDecimal.valueOf(100)).toString());
  153. model.setProductCode(ZfbProductCode.STD_RED_PACKET.getProductCode());
  154. model.setBizScene(TransferConstant.DIRECT_TRANSFER);
  155. model.setOrderTitle(remark);
  156. //红包业务必传,取值REDPACKET
  157. JSONObject businessParams = new JSONObject();
  158. businessParams.putOpt(TransferConstant.SUB_BIZ_SCENE, TransferConstant.RED_PACKET);
  159. model.setBusinessParams(businessParams.toString());
  160. Participant payeeInfo = new Participant();
  161. payeeInfo.setIdentity(account);
  162. payeeInfo.setIdentityType(TransferConstant.ALIPAY_LOGON_ID);
  163. payeeInfo.setName(name);
  164. model.setPayeeInfo(payeeInfo);
  165. model.setRemark("分销提现转账");
  166. transUniTransferRequest.setBizModel(model);
  167. return transUniTransferRequest;
  168. }
  169. public void saveTransferRecord(Long userId, String donNo, String account, String name, BigDecimal money, BigDecimal points, String type, Integer scope, String body, String error, Integer channelType) throws Exception {
  170. TransferAccountsRecord record = new TransferAccountsRecord();
  171. JSONObject re = Jsons.parseObject(body, JSONObject.class);
  172. JSONObject response = Jsons.parseObject(re.get("alipay_fund_trans_uni_transfer_response"), JSONObject.class);
  173. String transactionId = response.getStr("order_id");
  174. String transDate = response.getStr("trans_date");
  175. record.setUserId(userId);
  176. record.setAccount(account);
  177. record.setName(name);
  178. record.setMoney(money);
  179. record.setType(type);
  180. record.setScope(scope);
  181. Optional.ofNullable(error).ifPresent(msg -> {
  182. record.setErrorMsg(msg);
  183. record.setStatus(0);
  184. });
  185. record.setPoints(points);
  186. record.setTransferOutNo(donNo);
  187. record.setTransactionId(transactionId);
  188. Optional.ofNullable(transDate).ifPresent(transferTime -> record.setTransferTime(DateTime.of(transferTime, "yyyy-MM-dd HH:mm:ss")));
  189. transferAccountsRecordMapper.insert(record);
  190. }
  191. public Result commonApplyMoney(ApplyMoneyReq applyMoneyReq) throws Exception {
  192. Long userId = applyMoneyReq.getUserId();
  193. User user = userMapper.selectById(userId);
  194. if (user == null) {
  195. throw BusinessRuntimeException.getInstance("请先授权登录");
  196. }
  197. if (user.getIsBlack()) throw BusinessRuntimeException.getInstance("系统检测操作异常,请稍后再试");
  198. Boolean isTakeAll = applyMoneyReq.getIsTakeAll();
  199. DistributeMoneyApply.Type type = applyMoneyReq.getType();
  200. if (type == null) type = DistributeMoneyApply.Type.zfb;
  201. if (type == DistributeMoneyApply.Type.zfb) {
  202. if (ObjectUtil.hasEmpty(applyMoneyReq.getAccount(), applyMoneyReq.getRealName())) {
  203. throw BusinessRuntimeException.getInstance("必填项不能为空");
  204. }
  205. if (applyMoneyReq.getAccount().length() > 255 || applyMoneyReq.getRealName().length() > 32) {
  206. throw BusinessRuntimeException.getInstance("请输入正确的账户信息");
  207. }
  208. }
  209. if (type == DistributeMoneyApply.Type.usdt) {
  210. if (StrUtil.isEmpty(applyMoneyReq.getWalletAddr())) {
  211. throw BusinessRuntimeException.getInstance("USDT提现钱包地址不能为空");
  212. }
  213. if (applyMoneyReq.getWalletAddr().length() > 1000) {
  214. throw BusinessRuntimeException.getInstance("请输入正确的钱包地址");
  215. }
  216. if (StrUtil.isNotBlank(applyMoneyReq.getRemark()) && applyMoneyReq.getRemark().length() > 512) {
  217. throw BusinessRuntimeException.getInstance("备注过多");
  218. }
  219. isTakeAll = true;
  220. }
  221. DistributeMoneyApply.MType mType = applyMoneyReq.getMType();
  222. Assert.notNull(mType, "系统异常..");
  223. DistributeMoneyApply distributeMoneyApply = null;
  224. if (type == DistributeMoneyApply.Type.pwdRed) {
  225. distributeMoneyApply = userDistributeMapper.selectRelationBusiness(userId);
  226. isTakeAll = true;
  227. }
  228. // //今日是否已提现
  229. // DistributeMoneyApply apply = distributeMoneyApplyMapper.selectOne(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getUserId, userId).between(DistributeMoneyApply::getCreatedTime, DateUtil.beginOfDay(DateTime.now()), DateUtil.endOfDay(DateTime.now())).last("limit 1"));
  230. // if (apply != null) {
  231. // throw BusinessRuntimeException.getInstance("今日已提现,请明日再进行操作");
  232. // }
  233. BigDecimal userPoints = null;
  234. BigDecimal needSubPoints = null;
  235. BigDecimal needApplyMoney = null;
  236. BigDecimal fourHundred = null;
  237. if (mType == DistributeMoneyApply.MType.ds) {
  238. userPoints = user.getPoints();
  239. DistributePointsExchangeMoney distributePointsExchangeMoney = distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).orderByDesc(DistributePointsExchangeMoney::getPoints).last("limit 1"));
  240. BigDecimal minPoints = BigDecimal.valueOf(distributePointsExchangeMoney.getMinPoints());
  241. BigDecimal ratePoints = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
  242. BigDecimal minMoney = distributePointsExchangeMoney.getMoney();
  243. if (userPoints.compareTo(minPoints) < 0) {
  244. throw BusinessRuntimeException.getInstance("您当前积分未达到积分门槛,无法提现");
  245. }
  246. BigDecimal num = userPoints.divide(ratePoints, 0, RoundingMode.DOWN);
  247. needApplyMoney = num.multiply(minMoney);
  248. needSubPoints = num.multiply(ratePoints);
  249. fourHundred = BigDecimal.valueOf(4 * 100 * 100);
  250. if (isTakeAll == null || !isTakeAll) {
  251. if (needApplyMoney.compareTo(fourHundred) > 0) {
  252. needApplyMoney = fourHundred;
  253. needSubPoints = fourHundred.divide(minMoney).multiply(ratePoints);
  254. }
  255. }
  256. }
  257. if (mType == DistributeMoneyApply.MType.sub) {
  258. needApplyMoney = user.getSubApplyMoney();
  259. if (needApplyMoney.compareTo(BigDecimal.ZERO) <= 0) {
  260. throw BusinessRuntimeException.getInstance("您暂无可提现金额..");
  261. }
  262. }
  263. Integer update = 0;
  264. String zfbRemark = StrUtil.EMPTY;
  265. if (mType == DistributeMoneyApply.MType.ds) {
  266. update = userMapper.subPoints(user.getId(), needSubPoints);
  267. zfbRemark = Constant.APPLY_MONEY_DS;
  268. }
  269. if (mType == DistributeMoneyApply.MType.sub) {
  270. update = userMapper.suUserSubApplyMoney(user.getId(), needApplyMoney);
  271. zfbRemark = Constant.APPLY_MONEY_SUB;
  272. }
  273. if (update == 1) {
  274. distributeMoneyApply = Optional.ofNullable(distributeMoneyApply).orElse(new DistributeMoneyApply());
  275. distributeMoneyApply.setUserId(userId);
  276. distributeMoneyApply.setPoints(needSubPoints);
  277. distributeMoneyApply.setMoney(needApplyMoney);
  278. distributeMoneyApply.setAccount(applyMoneyReq.getAccount());
  279. distributeMoneyApply.setRealName(applyMoneyReq.getRealName());
  280. distributeMoneyApply.setWalletAddr(applyMoneyReq.getWalletAddr());
  281. distributeMoneyApply.setRemark(applyMoneyReq.getRemark());
  282. distributeMoneyApply.setType(applyMoneyReq.getType());
  283. distributeMoneyApply.setMType(applyMoneyReq.getMType());
  284. if (isTakeAll != null && isTakeAll) {
  285. distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.verifying);
  286. } else {
  287. TransferAccountsReq req = new TransferAccountsReq();
  288. req.setMoney(needApplyMoney);
  289. req.setAccount(applyMoneyReq.getAccount());
  290. req.setName(applyMoneyReq.getRealName());
  291. req.setPoints(needSubPoints);
  292. req.setUserId(userId);
  293. req.setChannelType(1);
  294. req.setRemark(zfbRemark);
  295. AlipayResponse alipayResponse = transferAccounts(req);
  296. if (alipayResponse.isSuccess()) {
  297. distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.success);
  298. } else {
  299. distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.fail);
  300. distributeMoneyApply.setReason(alipayResponse.getSubMsg());
  301. if (mType == DistributeMoneyApply.MType.ds){
  302. userBenefitsService.addDistributePoints(userId, distributeMoneyApply.getPoints());
  303. }
  304. if (mType == DistributeMoneyApply.MType.sub) {
  305. userBenefitsService.addDistributeSubMoney(userId, needApplyMoney);
  306. }
  307. if (StrUtil.equals(alipayResponse.getSubCode(), "SECURITY_CHECK_FAILED")) {
  308. return GatewayResponse.FAIL.newBuilder().setMsg("当前支付宝提现人数较多,请稍后再试").toResult();
  309. }
  310. if (alipayResponse.getSubMsg().contains("冻结")) {
  311. return GatewayResponse.FAIL.newBuilder().setMsg("目前财务清账中,48小时后可提现").toResult();
  312. }
  313. if (alipayResponse.getSubMsg().contains("余额不足")) {
  314. return GatewayResponse.FAIL.newBuilder().setMsg("转账失败,请联系客服").toResult();
  315. }
  316. return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
  317. }
  318. }
  319. try {
  320. distributeMoneyApplyMapper.insert(distributeMoneyApply);
  321. //大额提现 超过400
  322. if (envCommonService.isPrdEnv() && distributeMoneyApply.getVerifyStatus() == DistributeMoneyApply.Status.verifying && distributeMoneyApply.getMoney().compareTo(fourHundred) > 0) {
  323. SmsUtil.sendLuoKey2Msg(Constant.ZK_MOBILE, "推广有大额提现申请【银河录像局】");
  324. }
  325. } catch (Exception e) {
  326. userBenefitsService.addDistributePoints(userId, distributeMoneyApply.getPoints());
  327. return GatewayResponse.FAIL.newBuilder().setMsg("网络错误,请重试").toResult();
  328. }
  329. return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply);
  330. }
  331. throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
  332. }
  333. public Result yhShopApplyMoney(YhShopApplyMoneyReq applyMoneyReq) throws Exception {
  334. Long userId = applyMoneyReq.getUserId();
  335. User user = userMapper.selectById(userId);
  336. if (user == null) {
  337. throw BusinessRuntimeException.getInstance("请先授权登录");
  338. }
  339. Boolean isTakeAll = applyMoneyReq.getIsTakeAll();
  340. YhShopDistributeMoneyApply.Type type = applyMoneyReq.getType();
  341. if (type == null) type = YhShopDistributeMoneyApply.Type.zfb;
  342. if (type == YhShopDistributeMoneyApply.Type.zfb) {
  343. if (ObjectUtil.hasEmpty(applyMoneyReq.getAccount(), applyMoneyReq.getRealName())) {
  344. throw BusinessRuntimeException.getInstance("必填项不能为空");
  345. }
  346. if (applyMoneyReq.getAccount().length() > 255 || applyMoneyReq.getRealName().length() > 32) {
  347. throw BusinessRuntimeException.getInstance("请输入正确的账户信息");
  348. }
  349. }
  350. if (type == YhShopDistributeMoneyApply.Type.usdt) {
  351. if (StrUtil.isEmpty(applyMoneyReq.getWalletAddr())) {
  352. throw BusinessRuntimeException.getInstance("USDT提现钱包地址不能为空");
  353. }
  354. if (applyMoneyReq.getWalletAddr().length() > 1000) {
  355. throw BusinessRuntimeException.getInstance("请输入正确的钱包地址");
  356. }
  357. if (StrUtil.isNotBlank(applyMoneyReq.getRemark()) && applyMoneyReq.getRemark().length() > 512) {
  358. throw BusinessRuntimeException.getInstance("备注过多");
  359. }
  360. isTakeAll = true;
  361. }
  362. YhShopDistributeMoneyApply distributeMoneyApply = null;
  363. if (type == YhShopDistributeMoneyApply.Type.pwdRed) {
  364. distributeMoneyApply = yhShopMapper.selectRelationBusiness(userId);
  365. isTakeAll = true;
  366. }
  367. BigDecimal needApplyMoney = user.getYhsMoney();
  368. BigDecimal fourHundred = BigDecimal.valueOf(4 * 10000);
  369. if (isTakeAll == null || !isTakeAll) {
  370. if (needApplyMoney.compareTo(fourHundred) > 0) {
  371. needApplyMoney = fourHundred;
  372. }
  373. }
  374. Integer update = userMapper.subYhsMoney(user.getId(), needApplyMoney);
  375. if (update == 1) {
  376. distributeMoneyApply = Optional.ofNullable(distributeMoneyApply).orElse(new YhShopDistributeMoneyApply());
  377. distributeMoneyApply.setUserId(userId);
  378. distributeMoneyApply.setMoney(needApplyMoney);
  379. distributeMoneyApply.setAccount(applyMoneyReq.getAccount());
  380. distributeMoneyApply.setRealName(applyMoneyReq.getRealName());
  381. distributeMoneyApply.setWalletAddr(applyMoneyReq.getWalletAddr());
  382. distributeMoneyApply.setRemark(applyMoneyReq.getRemark());
  383. distributeMoneyApply.setType(applyMoneyReq.getType());
  384. if (isTakeAll != null && isTakeAll) {
  385. distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.verifying);
  386. } else {
  387. TransferAccountsReq req = new TransferAccountsReq();
  388. req.setMoney(needApplyMoney);
  389. req.setAccount(applyMoneyReq.getAccount());
  390. req.setName(applyMoneyReq.getRealName());
  391. req.setChannelType(2);
  392. req.setUserId(userId);
  393. req.setRemark("小店提现");
  394. AlipayResponse alipayResponse = transferAccounts(req);
  395. if (alipayResponse.isSuccess()) {
  396. distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.success);
  397. } else {
  398. distributeMoneyApply.setVerifyStatus(YhShopDistributeMoneyApply.Status.fail);
  399. distributeMoneyApply.setReason(alipayResponse.getSubMsg());
  400. userBenefitsService.addYhsMoney(userId, distributeMoneyApply.getMoney());
  401. if (StrUtil.equals(alipayResponse.getSubCode(), "SECURITY_CHECK_FAILED")) {
  402. return GatewayResponse.FAIL.newBuilder().setMsg("当前支付宝提现人数较多,请稍后再试").toResult();
  403. }
  404. if (alipayResponse.getSubMsg().contains("冻结")) {
  405. return GatewayResponse.FAIL.newBuilder().setMsg("目前财务清账中,48小时后可提现").toResult();
  406. }
  407. if (alipayResponse.getSubMsg().contains("余额不足")) {
  408. return GatewayResponse.FAIL.newBuilder().setMsg("转账失败,请联系客服").toResult();
  409. }
  410. return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
  411. }
  412. }
  413. try {
  414. yhShopDistributeMoneyApplyMapper.insert(distributeMoneyApply);
  415. //大额提现 超过400
  416. if (envCommonService.isPrdEnv() && distributeMoneyApply.getVerifyStatus() == YhShopDistributeMoneyApply.Status.verifying && distributeMoneyApply.getMoney().compareTo(fourHundred) > 0) {
  417. SmsUtil.sendLuoKey2Msg(Constant.ZK_MOBILE, "小店店铺有大额提现申请【银河录像局】");
  418. }
  419. } catch (Exception e) {
  420. userBenefitsService.addYhsMoney(userId, distributeMoneyApply.getMoney());
  421. return GatewayResponse.FAIL.newBuilder().setMsg("网络错误,请重试").toResult();
  422. }
  423. return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply);
  424. }
  425. throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
  426. }
  427. }