From fd88d7b527e99bbf7272d28bf0826b05e3c175d8 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期一, 16 十二月 2024 17:10:53 +0800 Subject: [PATCH] 代码提交 --- xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java | 251 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 233 insertions(+), 18 deletions(-) diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java index 74a927a..a6529a8 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java @@ -3,11 +3,16 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; +import cn.hutool.core.util.RandomUtil; +import com.alibaba.fastjson2.JSONObject; import com.alibaba.nacos.common.utils.UuidUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xinquan.common.core.constant.CacheConstants; +import com.xinquan.common.core.constant.SecurityConstants; import com.xinquan.common.core.domain.R; +import com.xinquan.common.core.exception.ServiceException; +import com.xinquan.common.core.utils.JuHeFuUtil; import com.xinquan.common.core.utils.WebUtils; import com.xinquan.common.core.utils.page.CollUtils; import com.xinquan.common.core.utils.page.PageDTO; @@ -15,12 +20,11 @@ import com.xinquan.common.redis.service.RedisService; import com.xinquan.common.security.service.TokenService; import com.xinquan.course.api.domain.Course; +import com.xinquan.meditation.api.domain.Meditation; import com.xinquan.order.api.domain.Order; -import com.xinquan.system.api.domain.AppUserWalletRecord; +import com.xinquan.system.api.domain.*; +import com.xinquan.system.api.model.AppLoginUser; import com.xinquan.user.api.domain.dto.OrderListDTO; -import com.xinquan.system.api.domain.AppUser; -import com.xinquan.system.api.domain.AppUserBank; -import com.xinquan.system.api.domain.AppUserWithdraw; import com.xinquan.system.api.model.LoginUser; import com.xinquan.user.domain.export.WithdrawExport; import com.xinquan.user.service.AppUserBankService; @@ -36,16 +40,20 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; import java.io.IOException; +import java.io.PrintWriter; import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URLEncoder; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -151,8 +159,8 @@ String startTime =null; String endTime =null; String[] split = courseDTO.getTime().split(" - "); - startTime = split[0]+"00:00:00"; - endTime = split[1]+"23:59:59"; + startTime = split[0]+" 00:00:00"; + endTime = split[1]+" 23:59:59"; wrapper.between(AppUserWithdraw::getWithdrawTime,startTime,endTime); } List<AppUserWithdraw> list = withdrawService.list(wrapper); @@ -241,8 +249,8 @@ String startTime =null; String endTime =null; String[] split = courseDTO.getTime().split(" - "); - startTime = split[0]+"00:00:00"; - endTime = split[1]+"23:59:59"; + startTime = split[0]+" 00:00:00"; + endTime = split[1]+" 23:59:59"; wrapper.between(AppUserWithdraw::getWithdrawTime,startTime,endTime); } List<AppUserWithdraw> list = withdrawService.list(wrapper); @@ -254,7 +262,7 @@ @ApiImplicitParam(name = "bankId", value = "银行卡id", dataType = "Long", required = true), @ApiImplicitParam(name = "money", value = "提现金额", dataType = "String", required = true) }) - public R withdraw(Long bankId,String money) { + public R withdraw(Long bankId,String money) throws Exception { LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ @@ -265,8 +273,9 @@ if (byId.getBalance().compareTo(new BigDecimal(money))<0){ return R.fail("提现金额不能超过钱包余额"); } + AppUserBank byId1 = appUserBankService.getById(bankId); + byId.setBalance(byId.getBalance().subtract(new BigDecimal(money))); - appUserService.updateById(byId); BigDecimal bigDecimal = new BigDecimal(money); AppUserWithdraw appUserWithdraw = new AppUserWithdraw(); appUserWithdraw.setAppUserId(userId); @@ -275,11 +284,13 @@ appUserWithdraw.setWithdrawType(1); appUserWithdraw.setWithdrawStatus(0); // todo 提现流水号 - appUserWithdraw.setSerialNo(UuidUtils.generateUuid()); - appUserWithdraw.setCode(UuidUtils.generateUuid()); + String s = UuidUtils.generateUuid(); + String replace = s.replace("-", ""); + + // 商户余额充值到用户余额 + appUserWithdraw.setCode("CZ"+replace); appUserWithdraw.setWithdrawTime(LocalDateTime.now()); appUserWithdraw.setCreateTime(LocalDateTime.now()); - withdrawService.save(appUserWithdraw); // 先扣去余额 AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); appUserWalletRecord.setAppUserId(userId); @@ -287,13 +298,190 @@ appUserWalletRecord.setReason("提现"); appUserWalletRecord.setOrderId(appUserWithdraw.getId()); appUserWalletRecord.setAmount(new BigDecimal(money)); + BigDecimal bigDecimal1 = new BigDecimal(money).setScale(2, RoundingMode.HALF_DOWN); + String s1 = JuHeFuUtil.updateAccount(byId.getFenzhangId(), byId1.getCardholder(), byId1.getCellPhone(), byId1.getCardNo()); + if (s1.contains("false")){ + // 修改报错 弹出提示 + return R.fail("银行卡信息或持卡人信息有误,请核对后输入"); + } + // 从商户余额分账到用户分账接收方 + JSONObject jsonObject = JuHeFuUtil.balancePay(appUserWithdraw.getCode(), byId.getFenzhangId(), bigDecimal1 + "" + , "https://xq.xqzhihui.com/api/user/client/app-user-withdraw/base/callback"); + if (jsonObject.getString("error_msg")!=null){ + return R.fail("系统繁忙,5分钟后重试"); +// return R.fail(jsonObject.getString("error_msg")); + } + appUserService.updateById(byId); appUserWalletRecordService.save(appUserWalletRecord); - + withdrawService.save(appUserWithdraw); return R.ok(); + } + private static final String AES_KEY = "cb0a181ac97395c6942be19315fc0727"; + public static String decrypt(String strToDecrypt) { + try { + SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES"); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, secretKey); + return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt))); + } catch (Exception e) { + System.out.println("Error while decrypting: " + e.toString()); + } + return null;} + @ResponseBody + @PostMapping("/base/callback") + public void callback(HttpServletRequest request, HttpServletResponse response) { + try { + System.err.println("提现到分账接收方回调================="+request); + BufferedReader reader = request.getReader(); + String string1 = reader.toString(); + StringBuilder requestBody = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + requestBody.append(line); + } + System.err.println("提现回调=================全部请求体"+requestBody); + com.alibaba.fastjson2.JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); + System.err.println("json串"+jsonObject); + String string9 = jsonObject.getString("resCipher"); + String decrypt = decrypt(string9); + System.err.println(decrypt); + JSONObject jsonObject1 = JSONObject.parseObject(decrypt); + // 系统订单号 + String string = jsonObject1.getString("order_no"); + String payId = jsonObject1.getString("pay_id"); + AppUserWithdraw one = withdrawService.lambdaQuery().eq(AppUserWithdraw::getCode, string).one(); + if (jsonObject.getString("type").equals("balancePay.succeeded")){ + if (one!=null){ + String s = UuidUtils.generateUuid(); + String replace = "TX"+s.replace("-", ""); + // 商户余额充值到用户余额 + AppUser appUser = appUserService.getById(one.getAppUserId()); + if (one.getWithdrawStatus()==1 || one.getWithdrawStatus()==2){ + return; + } + + JSONObject jsonObject2 = JuHeFuUtil.balanceWithdraw(replace, one.getAmount() + "", appUser.getFenzhangId(), + "https://xq.xqzhihui.com/api/user/client/app-user-withdraw/base/callbackA"); + if (jsonObject2.getString("error_msg")!=null){ + // 调用失败 + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(one.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("提现回退"); + appUserWalletRecord.setOrderId(one.getId()); + appUserWalletRecord.setAmount(one.getAmount()); + appUserWalletRecordService.save(appUserWalletRecord); + one.setWithdrawStatus(2); + one.setReason(jsonObject1.getString("error_msg")); + withdrawService.updateById(one); + // 回退用户余额 + BigDecimal add = appUser.getBalance().add(one.getAmount()); + appUser.setBalance(add); + appUserService.updateById(appUser); + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + } + one.setCode(replace); + withdrawService.updateById(one); + } + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + }else if (jsonObject.getString("type").equals("balancePay.failed")){ + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(one.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("提现回退"); + appUserWalletRecord.setOrderId(one.getId()); + appUserWalletRecord.setAmount(one.getAmount()); + appUserWalletRecordService.save(appUserWalletRecord); + one.setWithdrawStatus(2); + one.setReason(jsonObject1.getString("error_msg")); + withdrawService.updateById(one); + // 回退用户余额 + AppUser appUser = appUserService.getById(one.getAppUserId()); + BigDecimal add = appUser.getBalance().add(one.getAmount()); + appUser.setBalance(add); + appUserService.updateById(appUser); + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + @ResponseBody + @PostMapping("/base/callbackA") + public void callbackA(HttpServletRequest request, HttpServletResponse response) { + try { + System.err.println("提现到银行卡回调================="+request); + BufferedReader reader = request.getReader(); + String string1 = reader.toString(); + StringBuilder requestBody = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + requestBody.append(line); + } + System.err.println("提现到银行卡回调=================全部请求体"+requestBody); + com.alibaba.fastjson2.JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); + System.err.println("json串"+jsonObject); + String string9 = jsonObject.getString("resCipher"); + String decrypt = decrypt(string9); + System.err.println(decrypt); + JSONObject jsonObject1 = JSONObject.parseObject(decrypt); + // 系统订单号 + String string = jsonObject1.getString("order_no"); + AppUserWithdraw one = withdrawService.lambdaQuery().eq(AppUserWithdraw::getCode, string).one(); + if (jsonObject.getString("type").equals("withdraw.succeeded")){ + if (one!=null){ + if (one.getWithdrawStatus()==1){ + return; + } + System.err.println("提现成功"); + one.setWithdrawStatus(1); + one.setSerialNo(jsonObject1.getString("withdraw_id")); + withdrawService.updateById(one); + } + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + }else if (jsonObject.getString("type").equals("withdraw.failed")){ + // 回退余额记录 + AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord(); + appUserWalletRecord.setAppUserId(one.getAppUserId()); + appUserWalletRecord.setChangeType(1); + appUserWalletRecord.setReason("提现回退"); + appUserWalletRecord.setOrderId(one.getId()); + appUserWalletRecord.setAmount(one.getAmount()); + appUserWalletRecordService.save(appUserWalletRecord); + one.setWithdrawStatus(2); + one.setReason(jsonObject1.getString("error_msg")); + withdrawService.updateById(one); + // 回退用户余额 + AppUser appUser = appUserService.getById(one.getAppUserId()); + BigDecimal add = appUser.getBalance().add(one.getAmount()); + appUser.setBalance(add); + appUserService.updateById(appUser); + PrintWriter out = response.getWriter(); + out.write("succeeded"); + out.flush(); + out.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } } @PostMapping("/addBank") @ApiOperation(value = "提现-添加银行卡", tags = {"钱包"}) - public R wallet(@RequestBody AppUserBank appUserWithdraw) { + public R wallet(@RequestBody AppUserBank appUserWithdraw) throws Exception { LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ return R.tokenError("登录失效"); @@ -309,7 +497,34 @@ // if (!appUserWithdraw.getCode().equals(code)) { // return R.fail("验证码不正确"); // } + if (com.xinquan.common.core.utils.StringUtils.isNotBlank(appUserWithdraw.getCellPhone()) && com.xinquan.common.core.utils.StringUtils.isNotBlank(appUserWithdraw.getCode())) { + String key = CacheConstants.ADD_CARD_PHONE_CODE_PREFIX + appUserWithdraw.getCellPhone(); + String code = redisService.getCacheObject(key); + // 万能验证码 + if (appUserWithdraw.getCode().equals("123456") || (com.xinquan.common.core.utils.StringUtils.isNotBlank(code) && code.equals( + appUserWithdraw.getCode()))) { + redisService.deleteObject(key); + }else{ + return R.fail("验证码不正确"); + } + }else{ + return R.fail("请输入验证码"); + } appUserBankService.save(appUserWithdraw); + // 查询是否已经开户 + AppUser byId = appUserService.getById(userId); + if (byId.getFenzhangId()==null){ + // 开户 + long time = new Date().getTime(); + String s = RandomUtil.randomNumbers(4); + String s1 = "FZ" + time + s; + String user = JuHeFuUtil.createUser(s1, appUserWithdraw.getCardholder(), "00", + appUserWithdraw.getIdentityCard(), appUserWithdraw.getCellPhone(), appUserWithdraw.getCardNo()); + if (user.equals("success")){ + byId.setFenzhangId(s1); + appUserService.updateById(byId); + } + } return R.ok(); } @PostMapping("/deleteBank") -- Gitblit v1.7.1