2
0

feat: 使用余额支付

This commit is contained in:
caiyuchao
2025-02-13 15:16:35 +08:00
parent 3731aefec8
commit 9598cacfc8
5 changed files with 38 additions and 0 deletions

View File

@@ -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

View File

@@ -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}''失败,字典类型已存在

View File

@@ -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));
}
}

View File

@@ -16,4 +16,6 @@ public interface IUOrderService extends IService<UOrder> {
Long saveOrder(UOrder order);
boolean paySuccess(Long orderId);
boolean payByBalance(Long orderId);
}

View File

@@ -142,6 +142,33 @@ public class UOrderServiceImpl extends ServiceImpl<UOrderMapper, UOrder> 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.<UAccount>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;