feat:app转账

This commit is contained in:
dzc committed 2025-04-01 19:01:35 +08:00
1 parent 819e47b450
commit 634652e3d8
4 files changed
+47 -8

No files matched your search

@@ -1,5 +1,6 @@
package com.bsd.pjcloud.wallet.api.dto.rule;
import com.bsd.pjcloud.common.core.validation.Group;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@@ -8,18 +9,18 @@ import lombok.Data;
public class WalletRuleTransferAccountsDto {
@Schema(description = "用户id")
@NotNull(message = "用户id不能为空")
@NotNull(message = "用户id不能为空", groups = {Group.ADMIN.class})
private Long userId;
@Schema(description = "源钱包id")
@NotNull(message = "源钱包类型id不能为空")
@NotNull(message = "源钱包类型id不能为空", groups = {Group.ADMIN.class, Group.APP.class})
private Long sourceWalletTypeId;
@Schema(description = "目标钱包id")
@NotNull(message = "目标钱包类型id不能为空")
@NotNull(message = "目标钱包类型id不能为空", groups = {Group.ADMIN.class})
private Long targetWalletTypeId;
@Schema(description = "转换金额")
@NotNull(message = "转换金额不能为空")
@NotNull(message = "转换金额不能为空", groups = {Group.ADMIN.class, Group.APP.class})
private Integer balance;
}
@@ -48,17 +48,17 @@ public class WalletRuleJoinUserConfigVo {
private Integer changeTransferBalance = 0;
/**
* 总充值余额
* 源钱包充值总金额
*/
private Long totalTopUpBalance = 0L;
/**
* 总的可以转账的金额
* 源钱包支持最大转账金额
*/
private Long maxTransferBalance = 0L;
/**
* 总的转账余额
* 目标钱包已转账金额
*/
private Long totalTransferBalance = 0L;
@@ -2,17 +2,26 @@ package com.bsd.pjcloud.wallet.controller.rule;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.core.util.ValidGroup;
import com.bsd.pjcloud.common.core.validation.Group;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.DataScopeFuncEnum;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import com.bsd.pjcloud.wallet.api.dto.rule.WalletRuleTransactionDto;
import com.bsd.pjcloud.wallet.api.dto.rule.WalletRuleTransferAccountsDto;
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleTransactionEntity;
import com.bsd.pjcloud.wallet.service.WalletRuleTransactionService;
import com.bsd.pjcloud.wallet.service.WalletTypeService;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
@@ -22,6 +31,7 @@ import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -38,17 +48,41 @@ import java.util.Objects;
public class WalletRuleTransactionController {
private final WalletRuleTransactionService walletRuleTransactionService;
private final WalletTypeService walletTypeService;
/* ************************************* start app start ************************************* */
@Operation(summary = "app转账", description = "app转账")
@PostMapping("/app/transfer-accounts")
@Idempotent(expireTime = 3, info = "正在处理中,请勿重复操作")
public R appTransferAccounts(@Validated(Group.APP.class) @RequestBody WalletRuleTransferAccountsDto body) {
PjcloudUser user = SecurityUtils.getUser();
body.setUserId(user.getId());
// 移动端不传默认消费钱包
if (ObjectUtil.isNotEmpty(body.getTargetWalletTypeId())) {
WalletTypeEntity walletType = walletTypeService.getByUniqueCode(WalletTypeEnum.PAY);
if (ObjectUtil.isNotEmpty(walletType)) {
body.setTargetWalletTypeId(walletType.getId());
}
}
walletRuleTransactionService.transferAccounts(body);
return R.ok();
}
/* ************************************* end app end ************************************* */
@Operation(summary = "转账", description = "转账")
@PostMapping("/transfer-accounts")
@Idempotent(expireTime = 3, info = "正在处理中,请勿重复操作")
@PreAuthorize("@pms.hasPermission('wallet_walletRuleTransaction_transfer_accounts')")
public R transferAccounts(@Valid @RequestBody WalletRuleTransferAccountsDto body) {
public R transferAccounts(@Validated(Group.ADMIN.class) @RequestBody WalletRuleTransferAccountsDto body) {
walletRuleTransactionService.transferAccounts(body);
return R.ok();
}
@Operation(summary = "退回", description = "退回")
@GetMapping("/refund")
@Idempotent(expireTime = 3, info = "正在处理中,请勿重复操作")
@PreAuthorize("@pms.hasPermission('wallet_walletRuleTransaction_refund')")
public R refund(@RequestParam Long id) {
walletRuleTransactionService.refund(id);
@@ -77,6 +77,10 @@ public class WalletRuleTransactionServiceImpl extends ServiceImpl<WalletRuleTran
throw new RuntimeException(WalletTypeEnum.EAT.getDesc() + "余额必须留40元用于公午餐");
}
}
// 是否已经超过最大限制
if (userConfig.getTotalTransferBalance() > userConfig.getMaxTransferBalance()) {
throw new RuntimeException("已经超过最大转账金额限制");
}
entity.setSourceWalletId(userConfig.getSourceWalletId());
entity.setTargetWalletId(userConfig.getTargetWalletId());
entity.setSourceWalletBalance(userConfig.getSourceWalletBalance());