From 9598cacfc8e0a32392522e27db650d9fa57a129e Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Thu, 13 Feb 2025 15:16:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/i18n/messages_en_US.properties | 2 ++ .../resources/i18n/messages_zh_CN.properties | 2 ++ .../wfc/user/controller/UOrderController.java | 5 ++++ .../org/wfc/user/service/IUOrderService.java | 2 ++ .../user/service/impl/UOrderServiceImpl.java | 27 +++++++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/wfc-common/wfc-common-core/src/main/resources/i18n/messages_en_US.properties b/wfc-common/wfc-common-core/src/main/resources/i18n/messages_en_US.properties index e802cce..3783e76 100644 --- a/wfc-common/wfc-common-core/src/main/resources/i18n/messages_en_US.properties +++ b/wfc-common/wfc-common-core/src/main/resources/i18n/messages_en_US.properties @@ -81,6 +81,8 @@ user.file.service.error.contact.administrator=File service exception, please con user.avatar.upload.error.contact.administrator=Upload image exception, please contact the administrator user.not.register=The current system has not enabled the registration function user.name.or.password.error=Username or password error +user.order.pay.type.error=This order does not allow payment with balance +user.order.pay.amount.error=Insufficient Balance ## wfc-modules-system system.add.dict.failed.dict.exist=Add dictionary ''{0}'' failed, dictionary type already exists system.modify.dict.failed.dict.exist=Modify dictionary ''{0}'' failed, dictionary type already exists diff --git a/wfc-common/wfc-common-core/src/main/resources/i18n/messages_zh_CN.properties b/wfc-common/wfc-common-core/src/main/resources/i18n/messages_zh_CN.properties index d581f8a..050932a 100644 --- a/wfc-common/wfc-common-core/src/main/resources/i18n/messages_zh_CN.properties +++ b/wfc-common/wfc-common-core/src/main/resources/i18n/messages_zh_CN.properties @@ -81,6 +81,8 @@ user.file.service.error.contact.administrator=文件服务异常,请联系管 user.avatar.upload.error.contact.administrator=上传图片异常,请联系管理员 user.not.register=当前系统没有开启注册功能 user.name.or.password.error=用户名或密码错误 +user.order.pay.type.error=不允许使用余额支付 +user.order.pay.amount.error=余额不足 ## wfc-modules-system system.add.dict.failed.dict.exist=新增字典''{0}''失败,字典类型已存在 system.modify.dict.failed.dict.exist=修改字典''{0}''失败,字典类型已存在 diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UOrderController.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UOrderController.java index cf66a13..75c070e 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UOrderController.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UOrderController.java @@ -121,4 +121,9 @@ public class UOrderController extends BaseController { public AjaxResult paySuccess(@PathVariable("id") Long id) { return toAjax(uOrderService.paySuccess(id)); } + + @PostMapping("payBalance/{id}") + public AjaxResult payBalance(@PathVariable("id") Long id) { + return toAjax(uOrderService.payByBalance(id)); + } } diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUOrderService.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUOrderService.java index 79f5102..dc7af6d 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUOrderService.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUOrderService.java @@ -16,4 +16,6 @@ public interface IUOrderService extends IService { Long saveOrder(UOrder order); boolean paySuccess(Long orderId); + + boolean payByBalance(Long orderId); } diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java index 7229d67..23ed818 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UOrderServiceImpl.java @@ -142,6 +142,33 @@ public class UOrderServiceImpl extends ServiceImpl impleme return true; } + @Override + @Transactional(rollbackFor = Exception.class) + public boolean payByBalance(Long orderId) { + UOrder order = this.getById(orderId); + if (!OrderTypeEnum.PACKAGE.getCode().equals(order.getType())) { + throw new ServiceException("user.order.pay.type.error"); + } + UAccount account = accountService.getOne(Wrappers.lambdaQuery().eq(UAccount::getUserId, order.getUserId()), false); + + BigDecimal balance; + if (ObjectUtil.isNull(account)) { + throw new ServiceException("user.order.pay.amount.error"); + } else { + account.setBalance(Optional.ofNullable(account.getBalance()).orElse(BigDecimal.ZERO)); + balance = account.getBalance().subtract(Optional.ofNullable(account.getBalanceUsed()).orElse(BigDecimal.ZERO)); + } + if (order.getOrderAmount().compareTo(balance) > 0) { + throw new ServiceException("user.order.pay.amount.error"); + } + if (paySuccess(orderId)) { + account.setBalance(account.getBalance().subtract(order.getOrderAmount())); + accountService.updateById(account); + } + + return true; + } + private void callbackPackage(UOrder order, UAccount account, boolean isValid) { if (ObjectUtil.isNull(order.getPackageId())) { return;