Commit 11a6e8ebf75f1152df38756cc4bceae7620c38f4
1 parent
c7ccb828
【新增】MALL: 更新会员用户余额相关接口
Showing
8 changed files
with
127 additions
and
6 deletions
yudao-module-member/yudao-module-member-biz/pom.xml
| @@ -33,6 +33,11 @@ | @@ -33,6 +33,11 @@ | ||
| 33 | <artifactId>yudao-module-infra-api</artifactId> | 33 | <artifactId>yudao-module-infra-api</artifactId> |
| 34 | <version>${revision}</version> | 34 | <version>${revision}</version> |
| 35 | </dependency> | 35 | </dependency> |
| 36 | + <dependency> | ||
| 37 | + <groupId>cn.iocoder.boot</groupId> | ||
| 38 | + <artifactId>yudao-module-pay-api</artifactId> | ||
| 39 | + <version>${revision}</version> | ||
| 40 | + </dependency> | ||
| 36 | 41 | ||
| 37 | <!-- 业务组件 --> | 42 | <!-- 业务组件 --> |
| 38 | <dependency> | 43 | <dependency> |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.controller.admin.user; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.controller.admin.user; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 6 | import cn.iocoder.yudao.module.member.controller.admin.user.vo.*; | 7 | import cn.iocoder.yudao.module.member.controller.admin.user.vo.*; |
| 7 | import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert; | 8 | import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert; |
| 8 | import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO; | 9 | import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO; |
| @@ -15,15 +16,17 @@ import cn.iocoder.yudao.module.member.service.level.MemberLevelService; | @@ -15,15 +16,17 @@ import cn.iocoder.yudao.module.member.service.level.MemberLevelService; | ||
| 15 | import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService; | 16 | import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService; |
| 16 | import cn.iocoder.yudao.module.member.service.tag.MemberTagService; | 17 | import cn.iocoder.yudao.module.member.service.tag.MemberTagService; |
| 17 | import cn.iocoder.yudao.module.member.service.user.MemberUserService; | 18 | import cn.iocoder.yudao.module.member.service.user.MemberUserService; |
| 19 | +import cn.iocoder.yudao.module.pay.api.wallet.PayWalletApi; | ||
| 20 | +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO; | ||
| 18 | import io.swagger.v3.oas.annotations.Operation; | 21 | import io.swagger.v3.oas.annotations.Operation; |
| 19 | import io.swagger.v3.oas.annotations.Parameter; | 22 | import io.swagger.v3.oas.annotations.Parameter; |
| 20 | import io.swagger.v3.oas.annotations.tags.Tag; | 23 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 24 | +import jakarta.annotation.Resource; | ||
| 25 | +import jakarta.validation.Valid; | ||
| 21 | import org.springframework.security.access.prepost.PreAuthorize; | 26 | import org.springframework.security.access.prepost.PreAuthorize; |
| 22 | import org.springframework.validation.annotation.Validated; | 27 | import org.springframework.validation.annotation.Validated; |
| 23 | import org.springframework.web.bind.annotation.*; | 28 | import org.springframework.web.bind.annotation.*; |
| 24 | 29 | ||
| 25 | -import jakarta.annotation.Resource; | ||
| 26 | -import jakarta.validation.Valid; | ||
| 27 | import java.util.Collection; | 30 | import java.util.Collection; |
| 28 | import java.util.List; | 31 | import java.util.List; |
| 29 | import java.util.Objects; | 32 | import java.util.Objects; |
| @@ -50,6 +53,8 @@ public class MemberUserController { | @@ -50,6 +53,8 @@ public class MemberUserController { | ||
| 50 | private MemberGroupService memberGroupService; | 53 | private MemberGroupService memberGroupService; |
| 51 | @Resource | 54 | @Resource |
| 52 | private MemberPointRecordService memberPointRecordService; | 55 | private MemberPointRecordService memberPointRecordService; |
| 56 | + @Resource | ||
| 57 | + private PayWalletApi payWalletApi; | ||
| 53 | 58 | ||
| 54 | @PutMapping("/update") | 59 | @PutMapping("/update") |
| 55 | @Operation(summary = "更新会员用户") | 60 | @Operation(summary = "更新会员用户") |
| @@ -79,8 +84,9 @@ public class MemberUserController { | @@ -79,8 +84,9 @@ public class MemberUserController { | ||
| 79 | @PutMapping("/update-balance") | 84 | @PutMapping("/update-balance") |
| 80 | @Operation(summary = "更新会员用户余额") | 85 | @Operation(summary = "更新会员用户余额") |
| 81 | @PreAuthorize("@ss.hasPermission('member:user:update-balance')") | 86 | @PreAuthorize("@ss.hasPermission('member:user:update-balance')") |
| 82 | - public CommonResult<Boolean> updateUserBalance(@Valid @RequestBody Long id) { | ||
| 83 | - // todo @jason:增加一个【修改余额】 | 87 | + public CommonResult<Boolean> updateUserBalance(@Valid @RequestBody MemberUserUpdateBalanceReqVO updateReqVO) { |
| 88 | + payWalletApi.updateBalance(BeanUtils.toBean(updateReqVO, PayWalletUpdateBalanceReqDTO.class) | ||
| 89 | + .setUserId(updateReqVO.getId())); | ||
| 84 | return success(true); | 90 | return success(true); |
| 85 | } | 91 | } |
| 86 | 92 |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateBalanceReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.admin.user.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotNull; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.ToString; | ||
| 7 | + | ||
| 8 | +@Schema(description = "管理后台 - 用户修改余额 Request VO") | ||
| 9 | +@Data | ||
| 10 | +@ToString(callSuper = true) | ||
| 11 | +public class MemberUserUpdateBalanceReqVO { | ||
| 12 | + | ||
| 13 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23788") | ||
| 14 | + @NotNull(message = "用户编号不能为空") | ||
| 15 | + private Long id; | ||
| 16 | + | ||
| 17 | + @Schema(description = "变动余额,正数为增加,负数为减少", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | ||
| 18 | + @NotNull(message = "变动余额不能为空") | ||
| 19 | + private Integer balance; | ||
| 20 | + | ||
| 21 | +} |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.api.wallet; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 会员钱包 API 接口 | ||
| 7 | + * | ||
| 8 | + * @author HUIHUI | ||
| 9 | + */ | ||
| 10 | +public interface PayWalletApi { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 更新钱包余额 | ||
| 14 | + * | ||
| 15 | + * @param reqDTO 请求 | ||
| 16 | + */ | ||
| 17 | + void updateBalance(PayWalletUpdateBalanceReqDTO reqDTO); | ||
| 18 | + | ||
| 19 | +} |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/PayWalletUpdateBalanceReqDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.api.wallet.dto; | ||
| 2 | + | ||
| 3 | +import jakarta.validation.constraints.NotNull; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 钱包余额更新 Request DTO | ||
| 8 | + * | ||
| 9 | + * @author HUIHUI | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class PayWalletUpdateBalanceReqDTO { | ||
| 13 | + | ||
| 14 | + @NotNull(message = "用户编号不能为空") | ||
| 15 | + private Long userId; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 变动余额,正数为增加,负数为减少 | ||
| 19 | + */ | ||
| 20 | + @NotNull(message = "变动余额不能为空") | ||
| 21 | + private Integer balance; | ||
| 22 | + | ||
| 23 | +} |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/wallet/PayWalletBizTypeEnum.java
| @@ -18,7 +18,8 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable { | @@ -18,7 +18,8 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable { | ||
| 18 | RECHARGE(1, "充值"), | 18 | RECHARGE(1, "充值"), |
| 19 | RECHARGE_REFUND(2, "充值退款"), | 19 | RECHARGE_REFUND(2, "充值退款"), |
| 20 | PAYMENT(3, "支付"), | 20 | PAYMENT(3, "支付"), |
| 21 | - PAYMENT_REFUND(4, "支付退款"); | 21 | + PAYMENT_REFUND(4, "支付退款"), |
| 22 | + UPDATE_BALANCE(5, "更新余额"); | ||
| 22 | 23 | ||
| 23 | // TODO 后续增加 | 24 | // TODO 后续增加 |
| 24 | 25 |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.api.wallet; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO; | ||
| 4 | +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; | ||
| 5 | +import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum; | ||
| 6 | +import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService; | ||
| 7 | +import jakarta.annotation.Resource; | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | +import org.springframework.validation.annotation.Validated; | ||
| 11 | + | ||
| 12 | +import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER; | ||
| 13 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 14 | +import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * 会员钱包 API 实现类 | ||
| 18 | + * | ||
| 19 | + * @author HUIHUI | ||
| 20 | + */ | ||
| 21 | +@Service | ||
| 22 | +@Validated | ||
| 23 | +@Slf4j | ||
| 24 | +public class PayWalletApiImpl implements PayWalletApi { | ||
| 25 | + | ||
| 26 | + @Resource | ||
| 27 | + private PayWalletService payWalletService; | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public void updateBalance(PayWalletUpdateBalanceReqDTO reqDTO) { | ||
| 31 | + // 获得用户钱包 | ||
| 32 | + PayWalletDO wallet = payWalletService.getOrCreateWallet(reqDTO.getUserId(), MEMBER.getValue()); | ||
| 33 | + if (wallet == null) { | ||
| 34 | + log.error("[updateBalance],reqDTO({}) 用户钱包不存在.", reqDTO); | ||
| 35 | + throw exception(WALLET_NOT_FOUND); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + // 更新钱包余额 | ||
| 39 | + payWalletService.addWalletBalance(wallet.getId(), String.valueOf(reqDTO.getUserId()), | ||
| 40 | + PayWalletBizTypeEnum.UPDATE_BALANCE, reqDTO.getBalance()); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | +} |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
| @@ -12,12 +12,12 @@ import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum; | @@ -12,12 +12,12 @@ import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum; | ||
| 12 | import cn.iocoder.yudao.module.pay.service.order.PayOrderService; | 12 | import cn.iocoder.yudao.module.pay.service.order.PayOrderService; |
| 13 | import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; | 13 | import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; |
| 14 | import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; | 14 | import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; |
| 15 | +import jakarta.annotation.Resource; | ||
| 15 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 16 | import org.springframework.context.annotation.Lazy; | 17 | import org.springframework.context.annotation.Lazy; |
| 17 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Transactional; | 19 | import org.springframework.transaction.annotation.Transactional; |
| 19 | 20 | ||
| 20 | -import jakarta.annotation.Resource; | ||
| 21 | import java.time.LocalDateTime; | 21 | import java.time.LocalDateTime; |
| 22 | 22 | ||
| 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -176,6 +176,9 @@ public class PayWalletServiceImpl implements PayWalletService { | @@ -176,6 +176,9 @@ public class PayWalletServiceImpl implements PayWalletService { | ||
| 176 | walletMapper.updateWhenRecharge(payWallet.getId(), price); | 176 | walletMapper.updateWhenRecharge(payWallet.getId(), price); |
| 177 | break; | 177 | break; |
| 178 | } | 178 | } |
| 179 | + case UPDATE_BALANCE: // 更新余额 | ||
| 180 | + walletMapper.updateWhenRecharge(payWallet.getId(), price); | ||
| 181 | + break; | ||
| 179 | default: { | 182 | default: { |
| 180 | // TODO 其它类型待实现 | 183 | // TODO 其它类型待实现 |
| 181 | throw new UnsupportedOperationException("待实现"); | 184 | throw new UnsupportedOperationException("待实现"); |