|
@@ -2,20 +2,23 @@ package org.dromara.backstage.payment.controller;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
|
import jakarta.validation.constraints.NotNull;
|
|
import jakarta.validation.constraints.NotNull;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.backstage.business.errfill.ErrFillBusiness;
|
|
import org.dromara.backstage.business.errfill.ErrFillBusiness;
|
|
|
-import org.dromara.backstage.business.payments.strategy.impl.PaymentsStrategyContent;
|
|
|
|
|
|
|
+import org.dromara.backstage.business.payments.PayOrderBusiness;
|
|
|
|
|
+import org.dromara.backstage.business.payments.strategy.PaymentsStrategyContent;
|
|
|
import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
|
import org.dromara.backstage.consumption.domain.bo.ConsumptionBo;
|
|
import org.dromara.backstage.consumption.domain.bo.ConsumptionBo;
|
|
|
import org.dromara.backstage.payment.domain.bo.PtBagBo;
|
|
import org.dromara.backstage.payment.domain.bo.PtBagBo;
|
|
|
|
|
+import org.dromara.backstage.payment.domain.bo.PurseInOutBo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtBagVo;
|
|
import org.dromara.backstage.payment.domain.vo.PtBagVo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
import org.dromara.backstage.payment.service.IPtBagService;
|
|
import org.dromara.backstage.payment.service.IPtBagService;
|
|
|
import org.dromara.backstage.payment.service.IPtUserAccountService;
|
|
import org.dromara.backstage.payment.service.IPtUserAccountService;
|
|
|
-import org.dromara.backstage.payment.service.impl.PtBagServiceImpl;
|
|
|
|
|
import org.dromara.common.core.constant.Constants;
|
|
import org.dromara.common.core.constant.Constants;
|
|
|
import org.dromara.common.core.domain.R;
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.enums.CreditTypeEnum;
|
|
import org.dromara.common.core.enums.CreditTypeEnum;
|
|
@@ -36,8 +39,8 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.text.MessageFormat;
|
|
import java.text.MessageFormat;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 账户钱包
|
|
* 账户钱包
|
|
@@ -49,6 +52,7 @@ import java.util.Optional;
|
|
|
@Validated
|
|
@Validated
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
@RestController
|
|
@RestController
|
|
|
|
|
+@Slf4j
|
|
|
@RequestMapping("/payment/ptBag")
|
|
@RequestMapping("/payment/ptBag")
|
|
|
public class PtBagController extends BaseController {
|
|
public class PtBagController extends BaseController {
|
|
|
|
|
|
|
@@ -58,13 +62,14 @@ public class PtBagController extends BaseController {
|
|
|
private final PaymentsStrategyContent paymentsStrategyContent;
|
|
private final PaymentsStrategyContent paymentsStrategyContent;
|
|
|
private final ErrFillBusiness errFillBusiness;
|
|
private final ErrFillBusiness errFillBusiness;
|
|
|
private final IPtBagService bagService;
|
|
private final IPtBagService bagService;
|
|
|
|
|
+ private final PayOrderBusiness payOrderBusiness;
|
|
|
|
|
|
|
|
//根据userId查询账户余额
|
|
//根据userId查询账户余额
|
|
|
// @SaCheckPermission("payment:ptBag:query")
|
|
// @SaCheckPermission("payment:ptBag:query")
|
|
|
@GetMapping("/selectSelfAccountBalance")
|
|
@GetMapping("/selectSelfAccountBalance")
|
|
|
public R<String> selectAccountBalanceByIds() {
|
|
public R<String> selectAccountBalanceByIds() {
|
|
|
String userIds = String.valueOf(LoginHelper.getUserId());
|
|
String userIds = String.valueOf(LoginHelper.getUserId());
|
|
|
- return R.ok("",ptBagService.selectAccountBalanceByIds(userIds));
|
|
|
|
|
|
|
+ return R.ok("", ptBagService.selectAccountBalanceByIds(userIds));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -141,14 +146,25 @@ public class PtBagController extends BaseController {
|
|
|
@Log(title = "账户钱包", businessType = BusinessType.UPDATE)
|
|
@Log(title = "账户钱包", businessType = BusinessType.UPDATE)
|
|
|
@RepeatSubmit()
|
|
@RepeatSubmit()
|
|
|
@PostMapping("/recharge")
|
|
@PostMapping("/recharge")
|
|
|
- public R<PtBagVo> recharge(@Validated(EditGroup.class) @RequestBody PtBagBo bo) {
|
|
|
|
|
|
|
+ public R<PtBagVo> recharge(@Validated(EditGroup.class) @RequestBody PurseInOutBo bo) {
|
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
|
- PtBagBo commissionBo = computeCommission(bo);
|
|
|
|
|
- if (commissionBo != null) {
|
|
|
|
|
- paymentsStrategyContent.createOrder(commissionBo);
|
|
|
|
|
|
|
+ PurseInOutBo commissionBo = computeCommission(bo);
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (commissionBo != null) {
|
|
|
|
|
+ R<Object> commissionResult = payOrderBusiness.createNormalOrder(bo);
|
|
|
|
|
+ if (commissionResult.getCode() != R.SUCCESS) {
|
|
|
|
|
+ return R.fail(commissionResult.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ R<Object> result = payOrderBusiness.createNormalOrder(bo);
|
|
|
|
|
+ if (result.getCode() == R.SUCCESS) {
|
|
|
|
|
+ return R.ok((PtBagVo) result.getData());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.fail(result.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return R.fail(e.getMessage());
|
|
|
}
|
|
}
|
|
|
- PtBagVo vo = paymentsStrategyContent.createOrder(bo);
|
|
|
|
|
- return R.ok(vo);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -158,7 +174,7 @@ public class PtBagController extends BaseController {
|
|
|
@Log(title = "账户钱包", businessType = BusinessType.UPDATE)
|
|
@Log(title = "账户钱包", businessType = BusinessType.UPDATE)
|
|
|
@RepeatSubmit()
|
|
@RepeatSubmit()
|
|
|
@PostMapping("/refund")
|
|
@PostMapping("/refund")
|
|
|
- public R<PtBagVo> refund(@Validated(EditGroup.class) @RequestBody PtBagBo bo) {
|
|
|
|
|
|
|
+ public R<PtBagVo> refund(@Validated(EditGroup.class) @RequestBody PurseInOutBo bo) {
|
|
|
//校验钱包余额是否充足
|
|
//校验钱包余额是否充足
|
|
|
PtBagVo bagVo = bagService.queryByUserBagCode(bo.getUserId(), bo.getBagCode());
|
|
PtBagVo bagVo = bagService.queryByUserBagCode(bo.getUserId(), bo.getBagCode());
|
|
|
if (bagVo.getBalance().compareTo(bo.getReceiptMoney()) < 0) {
|
|
if (bagVo.getBalance().compareTo(bo.getReceiptMoney()) < 0) {
|
|
@@ -167,8 +183,16 @@ public class PtBagController extends BaseController {
|
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
|
//退款是记支出,所以金额设置为负数
|
|
//退款是记支出,所以金额设置为负数
|
|
|
bo.setReceiptMoney(bo.getReceiptMoney().negate());
|
|
bo.setReceiptMoney(bo.getReceiptMoney().negate());
|
|
|
- PtBagVo vo = paymentsStrategyContent.createOrder(bo);
|
|
|
|
|
- return R.ok(vo);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ R<Object> result = payOrderBusiness.createNormalOrder(bo);
|
|
|
|
|
+ if (result.getCode() == R.SUCCESS) {
|
|
|
|
|
+ return R.ok((PtBagVo) result.getData());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.fail(result.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return R.fail(e.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -178,20 +202,38 @@ public class PtBagController extends BaseController {
|
|
|
@Log(title = "批量账户充值", businessType = BusinessType.UPDATE)
|
|
@Log(title = "批量账户充值", businessType = BusinessType.UPDATE)
|
|
|
@RepeatSubmit()
|
|
@RepeatSubmit()
|
|
|
@PostMapping("/recharge/{userIds}")
|
|
@PostMapping("/recharge/{userIds}")
|
|
|
- public R<Void> batchRecharge(@Validated(EditGroup.class) @RequestBody PtBagBo bo, @PathVariable Long[] userIds) {
|
|
|
|
|
|
|
+ public R<String> batchRecharge(@Validated(EditGroup.class) @RequestBody PurseInOutBo bo, @PathVariable Long[] userIds) {
|
|
|
|
|
+ // TODO 2024-10-30 09:49:36 luoyibo 这里最好是提前处理下工作站信息
|
|
|
|
|
+ List<String> resultList = new ArrayList<>();
|
|
|
|
|
+ int succesCount = 0;
|
|
|
|
|
+ int errorCount = 0;
|
|
|
BigDecimal doValue = bo.getReceiptMoney();
|
|
BigDecimal doValue = bo.getReceiptMoney();
|
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
|
for (Long userId : userIds) {
|
|
for (Long userId : userIds) {
|
|
|
bo.setUserId(userId);
|
|
bo.setUserId(userId);
|
|
|
bo.setReceiptMoney(doValue);
|
|
bo.setReceiptMoney(doValue);
|
|
|
- PtBagBo commissionBo = computeCommission(bo);
|
|
|
|
|
- if (commissionBo != null) {
|
|
|
|
|
- paymentsStrategyContent.createOrder(commissionBo);
|
|
|
|
|
|
|
+ PurseInOutBo commissionBo = computeCommission(bo);
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (commissionBo != null) {
|
|
|
|
|
+ R<Object> commissionResult = payOrderBusiness.createNormalOrder(bo);
|
|
|
|
|
+ if (commissionResult.getCode() != R.SUCCESS) {
|
|
|
|
|
+ resultList.add(MessageFormat.format("[收管理费失败]-[管理费信息:{0}]-[错误信息:{1}]", JSONUtil.toJsonStr(bo), commissionResult.getData().toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ R<Object> result = payOrderBusiness.createNormalOrder(bo);
|
|
|
|
|
+ if (result.getCode() == R.SUCCESS) {
|
|
|
|
|
+ succesCount++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ errorCount++;
|
|
|
|
|
+ resultList.add(MessageFormat.format("[充值失败]-[充值信息:{0}]-[错误信息:{1}]", JSONUtil.toJsonStr(bo), result.getData().toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ errorCount++;
|
|
|
|
|
+ resultList.add(MessageFormat.format("[充值失败]-[充值信息:{0}]-[错误信息:{1}]", JSONUtil.toJsonStr(bo), e.getMessage()));
|
|
|
}
|
|
}
|
|
|
- paymentsStrategyContent.createOrder(bo);
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ resultList.forEach(log::error);
|
|
|
|
|
+ return R.ok(MessageFormat.format("批量充值完成,成功[{0}]条,失败[{1}]条", succesCount, errorCount));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -201,16 +243,37 @@ public class PtBagController extends BaseController {
|
|
|
@Log(title = "账户批量退款", businessType = BusinessType.UPDATE)
|
|
@Log(title = "账户批量退款", businessType = BusinessType.UPDATE)
|
|
|
@RepeatSubmit()
|
|
@RepeatSubmit()
|
|
|
@PostMapping("/refund/{userIds}")
|
|
@PostMapping("/refund/{userIds}")
|
|
|
- public R<Void> batchRefund(@Validated(EditGroup.class) @RequestBody PtBagBo bo, @PathVariable Long[] userIds) {
|
|
|
|
|
|
|
+ public R<Void> batchRefund(@Validated(EditGroup.class) @RequestBody PurseInOutBo bo, @PathVariable Long[] userIds) {
|
|
|
|
|
+ List<String> resultList = new ArrayList<>();
|
|
|
|
|
+ int succesCount = 0;
|
|
|
|
|
+ int errorCount = 0;
|
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
|
- BigDecimal doValue = bo.getReceiptMoney().negate();
|
|
|
|
|
|
|
+ BigDecimal doValue = bo.getReceiptMoney();
|
|
|
|
|
+ //退款是记支出,所以金额设置为负数
|
|
|
|
|
+ bo.setReceiptMoney(doValue.negate());
|
|
|
for (Long userId : userIds) {
|
|
for (Long userId : userIds) {
|
|
|
- //退款是记支出,所以金额设置为负数
|
|
|
|
|
- bo.setReceiptMoney(doValue);
|
|
|
|
|
bo.setUserId(userId);
|
|
bo.setUserId(userId);
|
|
|
- paymentsStrategyContent.createOrder(bo);
|
|
|
|
|
|
|
+ PtBagVo bagVo = bagService.queryByUserBagCode(userId, bo.getBagCode());
|
|
|
|
|
+ if (bagVo.getBalance().compareTo(doValue) < 0) {
|
|
|
|
|
+ errorCount++;
|
|
|
|
|
+ resultList.add(MessageFormat.format("[退款失败]-[退款信息:{0}]-[错误信息:余额不足,当前余额:{1}]",JSONUtil.toJsonStr(bo), bagVo.getBalance()));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ try {
|
|
|
|
|
+ R<Object> result = payOrderBusiness.createNormalOrder(bo);
|
|
|
|
|
+ if (result.getCode() == R.SUCCESS) {
|
|
|
|
|
+ succesCount++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ errorCount++;
|
|
|
|
|
+ resultList.add(MessageFormat.format("[退款失败]-[退款信息:{0}]-[错误信息:{1}]", JSONUtil.toJsonStr(bo), result.getData().toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ errorCount++;
|
|
|
|
|
+ resultList.add(MessageFormat.format("[退款失败]-[退款信息:{0}]-[错误信息:{1}]", JSONUtil.toJsonStr(bo), e.getMessage()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ resultList.forEach(log::error);
|
|
|
|
|
+ return R.ok(MessageFormat.format("批量退款完成,成功[{0}]条,失败[{1}]条", succesCount, errorCount));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -248,7 +311,7 @@ public class PtBagController extends BaseController {
|
|
|
/**
|
|
/**
|
|
|
* 计算管理费
|
|
* 计算管理费
|
|
|
*/
|
|
*/
|
|
|
- private PtBagBo computeCommission(PtBagBo bo) {
|
|
|
|
|
|
|
+ private PurseInOutBo computeCommission(PurseInOutBo bo) {
|
|
|
if (bo.getTakeCommission().equals(Constants.TAKE_COMMISSION)) {
|
|
if (bo.getTakeCommission().equals(Constants.TAKE_COMMISSION)) {
|
|
|
Long cardType = bo.getCardTypeId();
|
|
Long cardType = bo.getCardTypeId();
|
|
|
if (bo.getCardTypeId() == null) {
|
|
if (bo.getCardTypeId() == null) {
|
|
@@ -257,10 +320,11 @@ public class PtBagController extends BaseController {
|
|
|
}
|
|
}
|
|
|
bo.setCardTypeId(cardType);
|
|
bo.setCardTypeId(cardType);
|
|
|
//如果要收管理费,则计算管理费
|
|
//如果要收管理费,则计算管理费
|
|
|
- BigDecimal commission = cardService.computeCommission(bo);
|
|
|
|
|
|
|
+ PtBagBo bagBo = BeanUtil.copyProperties(bo, PtBagBo.class);
|
|
|
|
|
+ BigDecimal commission = cardService.computeCommission(bagBo);
|
|
|
if (commission.compareTo(BigDecimal.ZERO) > 0) {
|
|
if (commission.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
//如果管理费>0,是要入资金收支记录的
|
|
//如果管理费>0,是要入资金收支记录的
|
|
|
- PtBagBo commissionBo = new PtBagBo();
|
|
|
|
|
|
|
+ PurseInOutBo commissionBo = new PurseInOutBo();
|
|
|
BeanUtil.copyProperties(bo, commissionBo);
|
|
BeanUtil.copyProperties(bo, commissionBo);
|
|
|
commissionBo.setReceiptMoney(commission);
|
|
commissionBo.setReceiptMoney(commission);
|
|
|
commissionBo.setCreditType(CreditTypeEnum.COMMISSION_CHARGE);
|
|
commissionBo.setCreditType(CreditTypeEnum.COMMISSION_CHARGE);
|