From 5c6b1469792343d30781074c18880259498109b4 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 09 一月 2025 18:11:37 +0800
Subject: [PATCH] 修改bug
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WithdrawalRequestsController.java | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 153 insertions(+), 2 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WithdrawalRequestsController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WithdrawalRequestsController.java
index 56fdfc4..7522ff0 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WithdrawalRequestsController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WithdrawalRequestsController.java
@@ -1,8 +1,32 @@
package com.ruoyi.account.controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.ruoyi.account.api.model.AppUser;
+import com.ruoyi.account.api.model.BalanceChangeRecord;
+import com.ruoyi.account.api.model.WithdrawalRequests;
+import com.ruoyi.account.dto.WithQuery;
+import com.ruoyi.account.dto.WithdrawalRequestsDTO;
+import com.ruoyi.account.service.AppUserService;
+import com.ruoyi.account.service.BalanceChangeRecordService;
+import com.ruoyi.account.service.WithdrawalRequestsService;
+import com.ruoyi.account.util.payment.TransferUtil;
+import com.ruoyi.account.util.payment.model.AccountBalanceQueryResult;
+import com.ruoyi.account.util.payment.model.SinglePay;
+import com.ruoyi.account.util.payment.model.SinglePayCallbackResult;
+import com.ruoyi.account.util.payment.model.SinglePayResult;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
/**
* <p>
@@ -14,7 +38,134 @@
*/
@RestController
@RequestMapping("/withdrawal-requests")
+@Api(tags = "提现申请")
public class WithdrawalRequestsController {
+ @Resource
+ private WithdrawalRequestsService withdrawalRequestsService;
+ @Resource
+ private AppUserService appUserService;
+
+ @Resource
+ private BalanceChangeRecordService balanceChangeRecordService;
+
+ /**
+ * 提现申请
+ */
+ @PostMapping("/withdrawalApply")
+ @ApiOperation(value = "提现申请", tags = {"提现申请-小程序"})
+ public AjaxResult withdrawalApply(@RequestBody WithdrawalRequestsDTO params){
+ withdrawalRequestsService.withdrawalApply(params);
+ return AjaxResult.success();
+ }
+
+
+
+
+ @PostMapping("/page")
+ @ApiOperation(value = "提现申请列表", tags = {"后台"})
+ public R<IPage<WithdrawalRequests>> page(@RequestBody WithQuery withQuery){
+ IPage<WithdrawalRequests> withdrawalRequestsIPage = withdrawalRequestsService.pageList(withQuery);
+ for (WithdrawalRequests record : withdrawalRequestsIPage.getRecords()) {
+ record.setIdStr(record.getId().toString());
+ }
+ return R.ok(withdrawalRequestsIPage);
+ }
+
+
+
+
+
+ @PostMapping("/auth")
+ @ApiOperation(value = "提现申请审批", tags = {"后台"})
+ public R auth(@RequestParam("id") Long id,@ApiParam("2'审核通过',3'审核拒绝'") @RequestParam("auditStatus") Integer auditStatus){
+ WithdrawalRequests withdrawal = withdrawalRequestsService.getById(id);
+ BigDecimal withdrawalAmount = withdrawal.getWithdrawalAmount();
+ if(withdrawal.getAuditStatus() != 1){
+ return R.fail("不能重复审核");
+ }
+ if (auditStatus==2){
+ //先检查账户余额是否充足
+ AccountBalanceQueryResult accountBalanceQueryResult = TransferUtil.accountBalanceQuery();
+ if(null == accountBalanceQueryResult){
+ return R.fail("查询账户余额出错");
+ }
+ Double useAbleSettAmount = accountBalanceQueryResult.getUseAbleSettAmount();
+ if(useAbleSettAmount < withdrawal.getArrivalAmount().doubleValue()){
+ return R.fail("账户可用余额不足,请先补充账户余额");
+ }
+ //执行转账操作
+ if(withdrawal.getWithdrawalMethod() == 2){
+ //银行卡转账
+ SinglePay singlePay = new SinglePay();
+ singlePay.setTradeMerchantNo("");
+ singlePay.setMerchantOrderNo(withdrawal.getId().toString());
+ singlePay.setReceiverAccountNoEnc(withdrawal.getBankCardNumber());
+ singlePay.setReceiverNameEnc(withdrawal.getAccountHolder());
+ singlePay.setReceiverAccountType(201);
+ singlePay.setPaidAmount(withdrawal.getArrivalAmount().doubleValue());
+ singlePay.setPaidDesc("账户余额提现");
+ singlePay.setPaidUse("205");
+ singlePay.setCallbackUrl("/account/withdrawal-requests/withdrawalCallback");
+ SinglePayResult singlePayResult = TransferUtil.singlePay(singlePay);
+ if(null == singlePayResult){
+ return R.fail("转账失败");
+ }
+ withdrawal.setStatus(1);
+ }else{
+ //微信转账
+ }
+ }
+ if(3 == auditStatus){
+ //回退扣除的金额,添加明细记录
+ //修改用户的可提现金额
+ AppUser appUser = appUserService.getById(withdrawal.getAppUserId());
+ BigDecimal withdrawableAmount = appUser.getWithdrawableAmount();
+ BigDecimal withdrawnAmount = appUser.getWithdrawnAmount();
+ BigDecimal balance = appUser.getBalance();
+ appUser.setWithdrawableAmount(withdrawableAmount.add(withdrawalAmount).setScale(2, RoundingMode.HALF_EVEN));
+ appUser.setWithdrawnAmount(withdrawnAmount.subtract(withdrawalAmount).setScale(2, RoundingMode.HALF_EVEN));
+ appUser.setBalance(appUser.getBalance().add(withdrawalAmount).setScale(2, RoundingMode.HALF_EVEN));
+ appUserService.updateById(appUser);
+ //添加变动明细
+ BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
+ balanceChangeRecord.setAppUserId(appUser.getId());
+ balanceChangeRecord.setOrderId(withdrawal.getId());
+ balanceChangeRecord.setChangeType(2);
+ balanceChangeRecord.setBeforeAmount(balance);
+ balanceChangeRecord.setChangeAmount(withdrawalAmount);
+ balanceChangeRecord.setAfterAmount(appUser.getBalance());
+ balanceChangeRecord.setDelFlag(0);
+ balanceChangeRecord.setCreateTime(LocalDateTime.now());
+ balanceChangeRecordService.save(balanceChangeRecord);
+ }
+ withdrawal.setAuditStatus(auditStatus);
+ withdrawalRequestsService.updateById(withdrawal);
+ return R.ok();
+ }
+
+
+ /**
+ * 提现审核通过后转账回调通知
+ * @param singlePayCallbackResult
+ */
+ @ResponseBody
+ @PostMapping("/withdrawalCallback")
+ public Object withdrawalCallback(@RequestBody SinglePayCallbackResult singlePayCallbackResult){
+ Integer status = singlePayCallbackResult.getStatus();
+ if(203 == status){
+ String merchantOrderNo = singlePayCallbackResult.getMerchantOrderNo();
+ WithdrawalRequests withdrawalRequests = withdrawalRequestsService.getById(merchantOrderNo);
+ if(1 == withdrawalRequests.getStatus()){
+ withdrawalRequests.setStatus(2);
+ withdrawalRequests.setArrivalTime(LocalDateTime.now());
+ withdrawalRequestsService.updateById(withdrawalRequests);
+ }
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("statusCode", 2001);
+ return jsonObject;
+ }
+ return new JSONObject();
+ }
}
--
Gitblit v1.7.1