From 0c51a577db337520452022d9d6a22b720ef858d4 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期二, 31 十二月 2024 14:13:01 +0800 Subject: [PATCH] 全部代码、数据库提交 --- xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java | 272 ++++++++++++++++++++++++++++++------------------------ 1 files changed, 152 insertions(+), 120 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 a6529a8..4897ea1 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 @@ -16,6 +16,7 @@ import com.xinquan.common.core.utils.WebUtils; import com.xinquan.common.core.utils.page.CollUtils; import com.xinquan.common.core.utils.page.PageDTO; +import com.xinquan.common.core.web.domain.BaseModel; import com.xinquan.common.log.enums.BusinessType; import com.xinquan.common.redis.service.RedisService; import com.xinquan.common.security.service.TokenService; @@ -80,6 +81,7 @@ @Autowired private RedisService redisService; + @PostMapping("/withdrawList") @ApiOperation(value = "提现列表-分页", tags = {"管理后台-提现管理"}) public R<PageDTO<AppUserWithdraw>> withdrawList(@RequestBody OrderListDTO courseDTO) { @@ -98,13 +100,20 @@ if (collect.isEmpty())collect.add(-1L); wrapper.in(AppUserWithdraw::getAppUserId,collect); } - if (courseDTO.getPaymentStatus()!=null && courseDTO.getPaymentStatus()==1){ - wrapper.eq(AppUserWithdraw::getWithdrawStatus,0); - }else if (courseDTO.getPaymentStatus()!=null &&(courseDTO.getPaymentStatus()==2 || courseDTO.getPaymentStatus()==3)){ + if (StringUtils.hasLength(courseDTO.getPaymentStatus()) ){ List<Integer> integers = new ArrayList<>(); - integers.add(1); - integers.add(2); - wrapper.in(AppUserWithdraw::getWithdrawStatus,integers); + if (courseDTO.getPaymentStatus().contains("1")){ + integers.add(0); + } + if (courseDTO.getPaymentStatus().contains("2")){ + integers.add(1); + } + if (courseDTO.getPaymentStatus().contains("3")){ + integers.add(2); + } + if (!integers.isEmpty()){ + wrapper.in(AppUserWithdraw::getWithdrawStatus,integers); + } } if (StringUtils.hasLength(courseDTO.getTime())){ String startTime =null; @@ -112,8 +121,9 @@ String[] split = courseDTO.getTime().split(" - "); startTime = split[0]+" 00:00:00"; endTime = split[1]+" 23:59:59"; - wrapper.between(AppUserWithdraw::getWithdrawTime,startTime,endTime); + wrapper.between(AppUserWithdraw::getCreateTime,startTime,endTime); } + wrapper.orderByDesc(BaseModel::getCreateTime); Page<AppUserWithdraw> list = withdrawService.page(new Page<>(courseDTO.getPageCurr(), courseDTO.getPageSize()), wrapper); if (CollUtils.isEmpty(list.getRecords())) { return R.ok(PageDTO.empty(list)); @@ -147,13 +157,20 @@ if (collect.isEmpty())collect.add(-1L); wrapper.in(AppUserWithdraw::getAppUserId,collect); } - if (courseDTO.getPaymentStatus()!=null && courseDTO.getPaymentStatus()==1){ - wrapper.eq(AppUserWithdraw::getId,0); - }else if (courseDTO.getPaymentStatus()!=null &&(courseDTO.getPaymentStatus()==2 || courseDTO.getPaymentStatus()==3)){ + if (StringUtils.hasLength(courseDTO.getPaymentStatus()) ){ List<Integer> integers = new ArrayList<>(); - integers.add(1); - integers.add(2); - wrapper.in(AppUserWithdraw::getWithdrawStatus,integers); + if (courseDTO.getPaymentStatus().contains("1")){ + integers.add(0); + } + if (courseDTO.getPaymentStatus().contains("2")){ + integers.add(1); + } + if (courseDTO.getPaymentStatus().contains("3")){ + integers.add(2); + } + if (!integers.isEmpty()){ + wrapper.in(AppUserWithdraw::getWithdrawStatus,integers); + } } if (StringUtils.hasLength(courseDTO.getTime())){ String startTime =null; @@ -231,19 +248,26 @@ if (collect.isEmpty())collect.add(-1L); wrapper.in(AppUserWithdraw::getAppUserId,collect); } - if (courseDTO.getOrderFrom()!=null && courseDTO.getOrderFrom()!=5){ + if (StringUtils.hasLength(courseDTO.getOrderFrom()) && (!courseDTO.getOrderFrom().contains("5"))){ wrapper.eq(AppUserWithdraw::getId,0); } - if (courseDTO.getPayType()!=null && courseDTO.getPayType()!=4){ + if (StringUtils.hasLength(courseDTO.getPayType()) && (!courseDTO.getPayType().contains("4"))){ wrapper.eq(AppUserWithdraw::getId,0); } - if (courseDTO.getPaymentStatus()!=null && courseDTO.getPaymentStatus()==1){ - wrapper.eq(AppUserWithdraw::getId,0); - }else if (courseDTO.getPaymentStatus()!=null &&(courseDTO.getPaymentStatus()==2 || courseDTO.getPaymentStatus()==3)){ + if (StringUtils.hasLength(courseDTO.getPaymentStatus()) ){ List<Integer> integers = new ArrayList<>(); - integers.add(1); - integers.add(2); - wrapper.in(AppUserWithdraw::getWithdrawStatus,integers); + if (courseDTO.getPaymentStatus().contains("1")){ + integers.add(0); + } + if (courseDTO.getPaymentStatus().contains("2")){ + integers.add(1); + } + if (courseDTO.getPaymentStatus().contains("3")||courseDTO.getPaymentStatus().contains("4")){ + integers.add(2); + } + if (!integers.isEmpty()){ + wrapper.in(AppUserWithdraw::getWithdrawStatus,integers); + } } if (StringUtils.hasLength(courseDTO.getTime())){ String startTime =null; @@ -262,7 +286,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) throws Exception { + public synchronized R withdraw(Long bankId,String money) throws Exception { LoginUser loginUser = tokenService.getLoginUser(); if (loginUser==null){ @@ -274,7 +298,9 @@ return R.fail("提现金额不能超过钱包余额"); } AppUserBank byId1 = appUserBankService.getById(bankId); - + if (!Objects.equals(byId1.getAppUserId(), userId)){ + return R.fail("银行卡不属于当前登录用户"); + } byId.setBalance(byId.getBalance().subtract(new BigDecimal(money))); BigDecimal bigDecimal = new BigDecimal(money); AppUserWithdraw appUserWithdraw = new AppUserWithdraw(); @@ -285,10 +311,9 @@ appUserWithdraw.setWithdrawStatus(0); // todo 提现流水号 String s = UuidUtils.generateUuid(); - String replace = s.replace("-", ""); - + String replace = s.replace("-", "").substring(0, 16); // 商户余额充值到用户余额 - appUserWithdraw.setCode("CZ"+replace); + appUserWithdraw.setCode("TX"+replace); appUserWithdraw.setWithdrawTime(LocalDateTime.now()); appUserWithdraw.setCreateTime(LocalDateTime.now()); // 先扣去余额 @@ -296,7 +321,6 @@ appUserWalletRecord.setAppUserId(userId); appUserWalletRecord.setChangeType(2); 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()); @@ -305,18 +329,26 @@ return R.fail("银行卡信息或持卡人信息有误,请核对后输入"); } // 从商户余额分账到用户分账接收方 - JSONObject jsonObject = JuHeFuUtil.balancePay(appUserWithdraw.getCode(), byId.getFenzhangId(), bigDecimal1 + "" + JSONObject jsonObject = JuHeFuUtil.balancePay("CZ"+replace, 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")); } + JSONObject jsonObject2 = JuHeFuUtil.balanceWithdraw("TX"+replace, bigDecimal1+"", byId.getFenzhangId(), + "https://xq.xqzhihui.com/api/user/client/app-user-withdraw/base/callbackA"); + if (jsonObject2.getString("error_msg")!=null){ + return R.fail("系统繁忙,5分钟后重试"); + } + System.err.println("执行完毕====="); + appUserWithdraw.setCode("TX"+replace); appUserService.updateById(byId); - appUserWalletRecordService.save(appUserWalletRecord); withdrawService.save(appUserWithdraw); + appUserWalletRecord.setOrderId(appUserWithdraw.getId()); + appUserWalletRecordService.save(appUserWalletRecord); return R.ok(); } - private static final String AES_KEY = "cb0a181ac97395c6942be19315fc0727"; + private static final String AES_KEY = "6d548eb01bad44bbbb4a23743e733103"; public static String decrypt(String strToDecrypt) { try { SecretKeySpec secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES"); @@ -327,96 +359,96 @@ 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/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) { -- Gitblit v1.7.1