Commit 080c32b9f3e9f159750355af13827cfe505387e0
1 parent
bbc16bb9
code review:钱包充值
Showing
15 changed files
with
104 additions
and
70 deletions
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java
| ... | ... | @@ -46,6 +46,9 @@ public interface ErrorCodeConstants { |
| 46 | 46 | ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1007007002, "未找到对应的钱包交易"); |
| 47 | 47 | ErrorCode WALLET_REFUND_AMOUNT_ERROR = new ErrorCode(1007007003, "钱包退款金额不对"); |
| 48 | 48 | ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1007007004, "已经存在钱包退款"); |
| 49 | + | |
| 50 | + // TODO @jason:把钱包充值,单独搞个错误码段哈; | |
| 51 | + | |
| 49 | 52 | ErrorCode WALLET_RECHARGE_NOT_FOUND = new ErrorCode(1007007005, "钱包充值记录不存在"); |
| 50 | 53 | ErrorCode WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007007006, "钱包充值更新支付状态失败,钱包充值记录不是【未支付】状态"); |
| 51 | 54 | ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1007007007, "钱包充值更新支付状态失败,支付单编号不匹配"); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java
| ... | ... | @@ -33,13 +33,14 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi |
| 33 | 33 | public class AppPayWalletRechargeController { |
| 34 | 34 | |
| 35 | 35 | @Resource |
| 36 | - private PayWalletRechargeService payWalletRechargeService; | |
| 36 | + private PayWalletRechargeService walletRechargeService; | |
| 37 | 37 | |
| 38 | 38 | @PostMapping("/create") |
| 39 | - @Operation(summary = "创建钱包充值记录") | |
| 40 | - public CommonResult<AppPayWalletRechargeCreateRespVO> createWalletRecharge(@Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) { | |
| 41 | - PayWalletRechargeDO walletRecharge = payWalletRechargeService.createWalletRecharge(getLoginUserId(), | |
| 42 | - getLoginUserType(), reqVO); | |
| 39 | + @Operation(summary = "创建钱包充值记录(发起充值)") | |
| 40 | + public CommonResult<AppPayWalletRechargeCreateRespVO> createWalletRecharge( | |
| 41 | + @Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) { | |
| 42 | + PayWalletRechargeDO walletRecharge = walletRechargeService.createWalletRecharge( | |
| 43 | + getLoginUserId(), getLoginUserType(), reqVO); | |
| 43 | 44 | return success(PayWalletRechargeConvert.INSTANCE.convert(walletRecharge)); |
| 44 | 45 | } |
| 45 | 46 | |
| ... | ... | @@ -47,9 +48,12 @@ public class AppPayWalletRechargeController { |
| 47 | 48 | @Operation(summary = "更新钱包充值为已充值") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob |
| 48 | 49 | @PermitAll // 无需登录,安全由 内部校验实现 |
| 49 | 50 | @OperateLog(enable = false) // 禁用操作日志,因为没有操作人 |
| 50 | - public CommonResult<Boolean> updateWalletRechargerPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) { | |
| 51 | - payWalletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), | |
| 51 | + public CommonResult<Boolean> updateWalletRechargerPaid(@Valid @RequestBody PayOrderNotifyReqDTO notifyReqDTO) { | |
| 52 | + walletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), | |
| 52 | 53 | notifyReqDTO.getPayOrderId()); |
| 53 | 54 | return success(true); |
| 54 | 55 | } |
| 56 | + | |
| 57 | + // TODO @jason:管理后台,是不是可以搞个发起退款; | |
| 58 | + | |
| 55 | 59 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java
| ... | ... | @@ -12,11 +12,14 @@ public class AppPayWalletRechargeCreateReqVO { |
| 12 | 12 | |
| 13 | 13 | @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") |
| 14 | 14 | @NotNull(message = "支付金额不能为空") |
| 15 | + // TODO @jason999:是不是 @Min 哈? | |
| 15 | 16 | @DecimalMin(value = "0", inclusive = false, message = "支付金额必须大于零") |
| 16 | 17 | private Integer payPrice; |
| 17 | 18 | |
| 19 | + // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 | |
| 18 | 20 | @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") |
| 19 | 21 | @NotNull(message = "钱包赠送金额不能为空") |
| 20 | 22 | @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零") |
| 21 | 23 | private Integer walletBonus; |
| 24 | + | |
| 22 | 25 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java
| ... | ... | @@ -16,6 +16,7 @@ public interface PayWalletRechargeConvert { |
| 16 | 16 | |
| 17 | 17 | PayWalletRechargeDO convert(AppPayWalletRechargeCreateReqVO vo); |
| 18 | 18 | |
| 19 | + // TODO @jason:好像 price 相加,可以写个表达式的,通过 @Mapping | |
| 19 | 20 | default PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo) { |
| 20 | 21 | PayWalletRechargeDO walletRecharge = convert(vo); |
| 21 | 22 | return walletRecharge.setWalletId(walletId) | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.pay.convert.wallet; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionRespVO; |
| 5 | 5 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 6 | -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; | |
| 6 | +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; | |
| 7 | 7 | import org.mapstruct.Mapper; |
| 8 | 8 | import org.mapstruct.factory.Mappers; |
| 9 | 9 | |
| ... | ... | @@ -14,6 +14,6 @@ public interface PayWalletTransactionConvert { |
| 14 | 14 | |
| 15 | 15 | PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page); |
| 16 | 16 | |
| 17 | - PayWalletTransactionDO convert(CreateWalletTransactionBO bean); | |
| 17 | + PayWalletTransactionDO convert(WalletTransactionCreateReqBO bean); | |
| 18 | 18 | |
| 19 | 19 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | +import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; | |
| 5 | +import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO; | |
| 4 | 6 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| ... | ... | @@ -23,40 +25,49 @@ public class PayWalletRechargeDO extends BaseDO { |
| 23 | 25 | private Long id; |
| 24 | 26 | |
| 25 | 27 | /** |
| 26 | - * 会员钱包 id | |
| 28 | + * 钱包编号 | |
| 29 | + * | |
| 30 | + * 关联 {@link PayWalletDO#getId()} | |
| 27 | 31 | */ |
| 28 | 32 | private Long walletId; |
| 29 | 33 | |
| 34 | + // TODO @jason:要不改成 totalPrice? | |
| 30 | 35 | /** |
| 31 | - * 用户实际到账余额,例如充 100 送 20,则该值是 120 | |
| 36 | + * 用户实际到账余额 | |
| 37 | + * | |
| 38 | + * 例如充 100 送 20,则该值是 120 | |
| 32 | 39 | */ |
| 33 | 40 | private Integer price; |
| 34 | - | |
| 35 | 41 | /** |
| 36 | 42 | * 实际支付金额 |
| 37 | 43 | */ |
| 38 | 44 | private Integer payPrice; |
| 39 | - | |
| 45 | + // TODO @jason:bonusPrice 哈,更统一一点; | |
| 40 | 46 | /** |
| 41 | 47 | * 钱包赠送金额 |
| 42 | 48 | */ |
| 43 | 49 | private Integer walletBonus; |
| 44 | 50 | |
| 45 | 51 | /** |
| 46 | - * 是否已支付:[0:未支付 1:已经支付过] | |
| 52 | + * 是否已支付 | |
| 53 | + * | |
| 54 | + * true - 已支付 | |
| 55 | + * false - 未支付 | |
| 47 | 56 | */ |
| 48 | 57 | private Boolean payStatus; |
| 49 | 58 | |
| 50 | 59 | /** |
| 51 | 60 | * 支付订单编号 |
| 61 | + * | |
| 62 | + * 关联 {@link PayOrderDO#getId()} | |
| 52 | 63 | */ |
| 53 | 64 | private Long payOrderId; |
| 54 | - | |
| 55 | 65 | /** |
| 56 | 66 | * 支付成功的支付渠道 |
| 67 | + * | |
| 68 | + * 冗余 {@link PayOrderDO#getChannelCode()} | |
| 57 | 69 | */ |
| 58 | 70 | private String payChannelCode; |
| 59 | - | |
| 60 | 71 | /** |
| 61 | 72 | * 订单支付时间 |
| 62 | 73 | */ |
| ... | ... | @@ -64,26 +75,27 @@ public class PayWalletRechargeDO extends BaseDO { |
| 64 | 75 | |
| 65 | 76 | /** |
| 66 | 77 | * 支付退款单编号 |
| 78 | + * | |
| 79 | + * 关联 {@link PayRefundDO#getId()} | |
| 67 | 80 | */ |
| 68 | 81 | private Long payRefundId; |
| 69 | - | |
| 82 | + // TODO @jason:要不改成 refundTotalPrice? | |
| 70 | 83 | /** |
| 71 | 84 | * 退款金额,包含赠送金额 |
| 72 | 85 | */ |
| 73 | 86 | private Integer refundPrice; |
| 74 | - | |
| 75 | 87 | /** |
| 76 | 88 | * 退款支付金额 |
| 77 | 89 | */ |
| 78 | 90 | private Integer refundPayPrice; |
| 79 | - | |
| 91 | + // TODO @jason:要不改成 refundBonusPrice? | |
| 80 | 92 | /** |
| 81 | 93 | * 退款钱包赠送金额 |
| 82 | 94 | */ |
| 83 | 95 | private Integer refundWalletBonus; |
| 84 | - | |
| 85 | 96 | /** |
| 86 | 97 | * 退款时间 |
| 87 | 98 | */ |
| 88 | 99 | private LocalDateTime refundTime; |
| 89 | -} | |
| 90 | 100 | \ No newline at end of file |
| 101 | + | |
| 102 | +} | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java
| ... | ... | @@ -14,6 +14,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { |
| 14 | 14 | PayWalletDO::getUserType, userType); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | + // TODO @jason:下面几个更新方法,把 id 放前面哈。一般来说,重要参数放前面; | |
| 18 | + | |
| 17 | 19 | /** |
| 18 | 20 | * 当消费退款时候, 更新钱包 |
| 19 | 21 | * |
| ... | ... | @@ -55,6 +57,7 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { |
| 55 | 57 | .eq(PayWalletDO::getId, id); |
| 56 | 58 | return update(null, lambdaUpdateWrapper); |
| 57 | 59 | } |
| 60 | + | |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | 63 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java
| ... | ... | @@ -2,17 +2,17 @@ package cn.iocoder.yudao.module.pay.dal.mysql.wallet; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 5 | -import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoOrderDO; | |
| 6 | 5 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; |
| 7 | 6 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 7 | |
| 9 | 8 | @Mapper |
| 10 | 9 | public interface PayWalletRechargeMapper extends BaseMapperX<PayWalletRechargeDO> { |
| 11 | 10 | |
| 12 | - default int updateByIdAndPaid(Long id, boolean wherePayed, PayWalletRechargeDO updateObj){ | |
| 11 | + default int updateByIdAndPaid(Long id, boolean wherePayStatus, PayWalletRechargeDO updateObj){ | |
| 13 | 12 | return update(updateObj, new LambdaQueryWrapperX<PayWalletRechargeDO>() |
| 14 | - .eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getPayStatus, wherePayed)); | |
| 13 | + .eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getPayStatus, wherePayStatus)); | |
| 15 | 14 | } |
| 15 | + | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java
| ... | ... | @@ -11,19 +11,22 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; |
| 11 | 11 | public interface PayWalletRechargeService { |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | - * 创建钱包充值记录 | |
| 14 | + * 创建钱包充值记录(发起充值) | |
| 15 | + * | |
| 15 | 16 | * @param userId 用户 id |
| 16 | 17 | * @param userType 用户类型 |
| 17 | - * @param vo 钱包充值请求 vo | |
| 18 | + * @param createReqVO 钱包充值请求 VO | |
| 18 | 19 | * @return 钱包充值记录 |
| 19 | 20 | */ |
| 20 | - PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, AppPayWalletRechargeCreateReqVO vo); | |
| 21 | - | |
| 21 | + PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, | |
| 22 | + AppPayWalletRechargeCreateReqVO createReqVO); | |
| 22 | 23 | |
| 23 | 24 | /** |
| 24 | 25 | * 更新钱包充值成功 |
| 25 | - * @param walletRechargeId 钱包充值 id | |
| 26 | + * | |
| 27 | + * @param id 钱包充值记录 id | |
| 26 | 28 | * @param payOrderId 支付订单 id |
| 27 | 29 | */ |
| 28 | - void updateWalletRechargerPaid(Long walletRechargeId, Long payOrderId); | |
| 30 | + void updateWalletRechargerPaid(Long id, Long payOrderId); | |
| 31 | + | |
| 29 | 32 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
| ... | ... | @@ -42,57 +42,61 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { |
| 42 | 42 | |
| 43 | 43 | @Resource |
| 44 | 44 | private PayWalletRechargeMapper walletRechargeMapper; |
| 45 | + | |
| 45 | 46 | @Resource |
| 46 | 47 | private PayWalletService payWalletService; |
| 47 | 48 | @Resource |
| 48 | 49 | private PayOrderService payOrderService; |
| 49 | 50 | |
| 50 | - | |
| 51 | 51 | @Override |
| 52 | 52 | @Transactional(rollbackFor = Exception.class) |
| 53 | - public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, AppPayWalletRechargeCreateReqVO vo) { | |
| 54 | - // 1. 获取钱包 | |
| 53 | + public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, | |
| 54 | + AppPayWalletRechargeCreateReqVO createReqVO) { | |
| 55 | + // 1. 新增钱包充值记录 | |
| 55 | 56 | PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType); |
| 56 | - // 2. 新增钱包充值记录 | |
| 57 | - PayWalletRechargeDO walletRecharge = PayWalletRechargeConvert.INSTANCE.convert(wallet.getId(), vo); | |
| 57 | + PayWalletRechargeDO walletRecharge = PayWalletRechargeConvert.INSTANCE.convert(wallet.getId(), createReqVO); | |
| 58 | 58 | walletRechargeMapper.insert(walletRecharge); |
| 59 | - // 3.创建支付单 | |
| 59 | + | |
| 60 | + // 2.1 创建支付单 | |
| 60 | 61 | Long payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO() |
| 61 | 62 | .setAppId(WALLET_PAY_APP_ID).setUserIp(getClientIP()) |
| 62 | 63 | .setMerchantOrderId(walletRecharge.getId().toString()) // 业务的订单编号 |
| 63 | 64 | .setSubject(WALLET_RECHARGE_ORDER_SUBJECT).setBody("").setPrice(walletRecharge.getPayPrice()) |
| 64 | 65 | .setExpireTime(addTime(Duration.ofHours(2L)))); |
| 65 | - // 4.更新钱包充值记录中支付订单 | |
| 66 | + // 2.2 更新钱包充值记录中支付订单 | |
| 66 | 67 | walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) |
| 67 | 68 | .setId(walletRecharge.getId())); |
| 69 | + // TODO @jason:是不是你直接返回就好啦;然后 payOrderId 设置下; | |
| 68 | 70 | return walletRechargeMapper.selectById(walletRecharge.getId()); |
| 69 | 71 | } |
| 70 | 72 | |
| 71 | 73 | @Override |
| 72 | 74 | @Transactional(rollbackFor = Exception.class) |
| 73 | - public void updateWalletRechargerPaid(Long walletRechargeId, Long payOrderId) { | |
| 74 | - // 1. 获取钱包充值记录 | |
| 75 | - PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(walletRechargeId); | |
| 75 | + public void updateWalletRechargerPaid(Long id, Long payOrderId) { | |
| 76 | + // 1.1 获取钱包充值记录 | |
| 77 | + PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(id); | |
| 76 | 78 | if (walletRecharge == null) { |
| 77 | - log.error("[updateWalletRechargerPaid],钱包充值记录不存在,钱包充值 Id:{} ", walletRechargeId); | |
| 79 | + log.error("[updateWalletRechargerPaid][钱包充值记录不存在,钱包充值记录 id({})]", id); | |
| 78 | 80 | throw exception(WALLET_RECHARGE_NOT_FOUND); |
| 79 | 81 | } |
| 80 | - // 2. 校验钱包充值是否可以支付 | |
| 82 | + // 1.2 校验钱包充值是否可以支付 | |
| 81 | 83 | PayOrderDO payOrderDO = validateWalletRechargerCanPaid(walletRecharge, payOrderId); |
| 82 | - // 3. 更新钱包充值的支付状态 | |
| 83 | - int updateCount = walletRechargeMapper.updateByIdAndPaid(walletRechargeId,false, new PayWalletRechargeDO().setId(walletRechargeId) | |
| 84 | - .setPayStatus(true).setPayTime(LocalDateTime.now()) | |
| 84 | + | |
| 85 | + // 2. 更新钱包充值的支付状态 | |
| 86 | + int updateCount = walletRechargeMapper.updateByIdAndPaid(id,false, | |
| 87 | + new PayWalletRechargeDO().setId(id).setPayStatus(true).setPayTime(LocalDateTime.now()) | |
| 85 | 88 | .setPayChannelCode(payOrderDO.getChannelCode())); |
| 86 | 89 | if (updateCount == 0) { |
| 87 | 90 | throw exception(WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID); |
| 88 | 91 | } |
| 89 | - // 4. 更新钱包余额 | |
| 90 | - payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(walletRechargeId), | |
| 92 | + | |
| 93 | + // 3. 更新钱包余额 | |
| 94 | + // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110; | |
| 95 | + payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id), | |
| 91 | 96 | PayWalletBizTypeEnum.RECHARGE, walletRecharge.getPrice()); |
| 92 | 97 | } |
| 93 | 98 | |
| 94 | 99 | private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { |
| 95 | - | |
| 96 | 100 | // 1.1 校验充值记录的支付状态 |
| 97 | 101 | if (walletRecharge.getPayStatus()) { |
| 98 | 102 | log.error("[validateWalletRechargerCanPaid][钱包({}) 不处于未支付状态! 钱包数据是:{}]", |
| ... | ... | @@ -105,6 +109,7 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { |
| 105 | 109 | walletRecharge.getId(), payOrderId, toJsonString(walletRecharge)); |
| 106 | 110 | throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR); |
| 107 | 111 | } |
| 112 | + | |
| 108 | 113 | // 2.1 校验支付单是否存在 |
| 109 | 114 | PayOrderDO payOrder = payOrderService.getOrder(payOrderId); |
| 110 | 115 | if (payOrder == null) { |
| ... | ... | @@ -132,4 +137,5 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { |
| 132 | 137 | } |
| 133 | 138 | return payOrder; |
| 134 | 139 | } |
| 140 | + | |
| 135 | 141 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
| ... | ... | @@ -9,7 +9,7 @@ import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper; |
| 9 | 9 | import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; |
| 10 | 10 | import cn.iocoder.yudao.module.pay.service.order.PayOrderService; |
| 11 | 11 | import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; |
| 12 | -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; | |
| 12 | +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; | |
| 13 | 13 | import lombok.extern.slf4j.Slf4j; |
| 14 | 14 | import org.springframework.context.annotation.Lazy; |
| 15 | 15 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -84,6 +84,7 @@ public class PayWalletServiceImpl implements PayWalletService { |
| 84 | 84 | Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), refundPrice); |
| 85 | 85 | PayWalletDO wallet = walletMapper.selectById(walletId); |
| 86 | 86 | Assert.notNull(wallet, "钱包 {} 不存在", walletId); |
| 87 | + | |
| 87 | 88 | // 2. 增加余额 |
| 88 | 89 | return addWalletBalance(walletId, String.valueOf(payRefund.getId()), PAYMENT_REFUND, refundPrice); |
| 89 | 90 | } |
| ... | ... | @@ -137,42 +138,39 @@ public class PayWalletServiceImpl implements PayWalletService { |
| 137 | 138 | } |
| 138 | 139 | // 2.2 生成钱包流水 |
| 139 | 140 | Integer afterBalance = payWallet.getBalance() - price; |
| 140 | - CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) | |
| 141 | + WalletTransactionCreateReqBO bo = new WalletTransactionCreateReqBO().setWalletId(payWallet.getId()) | |
| 141 | 142 | .setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId)) |
| 142 | 143 | .setBizType(bizType.getType()).setTitle(bizType.getDescription()); |
| 143 | 144 | return walletTransactionService.createWalletTransaction(bo); |
| 144 | 145 | } |
| 145 | 146 | |
| 146 | 147 | @Override |
| 147 | - public PayWalletTransactionDO addWalletBalance(Long walletId, | |
| 148 | - String bizId, PayWalletBizTypeEnum bizType, Integer price) { | |
| 149 | - // 1. 获取钱包 | |
| 148 | + public PayWalletTransactionDO addWalletBalance(Long walletId, String bizId, | |
| 149 | + PayWalletBizTypeEnum bizType, Integer price) { | |
| 150 | + // 1.1 获取钱包 | |
| 150 | 151 | PayWalletDO payWallet = getWallet(walletId); |
| 151 | - | |
| 152 | 152 | if (payWallet == null) { |
| 153 | 153 | log.error("[addWalletBalance],用户钱包({})不存在.", walletId); |
| 154 | 154 | throw exception(WALLET_NOT_FOUND); |
| 155 | 155 | } |
| 156 | - | |
| 156 | + // 1.2 更新钱包金额 | |
| 157 | 157 | switch (bizType) { |
| 158 | - case PAYMENT_REFUND: { | |
| 159 | - // 退款更新 | |
| 158 | + case PAYMENT_REFUND: { // 退款更新 | |
| 160 | 159 | walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); |
| 161 | 160 | break; |
| 162 | 161 | } |
| 163 | - case RECHARGE: { | |
| 164 | - // 充值更新 | |
| 162 | + case RECHARGE: { // 充值更新 | |
| 165 | 163 | walletMapper.updateWhenRecharge(price, payWallet.getId()); |
| 166 | 164 | break; |
| 167 | 165 | } |
| 168 | - // TODO 其它类型 | |
| 166 | + // TODO 其它类型;这里可以先跑异常;避免有业务搞错; | |
| 169 | 167 | } |
| 170 | 168 | |
| 171 | 169 | // 2. 生成钱包流水 |
| 172 | - CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) | |
| 173 | - .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(bizId) | |
| 174 | - .setBizType(bizType.getType()).setTitle(bizType.getDescription()); | |
| 175 | - return walletTransactionService.createWalletTransaction(bo); | |
| 170 | + WalletTransactionCreateReqBO transactionCreateReqBO = new WalletTransactionCreateReqBO() | |
| 171 | + .setWalletId(payWallet.getId()).setPrice(price).setBalance(payWallet.getBalance() + price) | |
| 172 | + .setBizId(bizId).setBizType(bizType.getType()).setTitle(bizType.getDescription()); | |
| 173 | + return walletTransactionService.createWalletTransaction(transactionCreateReqBO); | |
| 176 | 174 | } |
| 177 | 175 | |
| 178 | 176 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java
| ... | ... | @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 6 | 6 | import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; |
| 7 | -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; | |
| 7 | +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; | |
| 8 | 8 | |
| 9 | 9 | import javax.validation.Valid; |
| 10 | 10 | |
| ... | ... | @@ -31,7 +31,7 @@ public interface PayWalletTransactionService { |
| 31 | 31 | * @param bo 创建钱包流水 bo |
| 32 | 32 | * @return 新建的钱包 do |
| 33 | 33 | */ |
| 34 | - PayWalletTransactionDO createWalletTransaction(@Valid CreateWalletTransactionBO bo); | |
| 34 | + PayWalletTransactionDO createWalletTransaction(@Valid WalletTransactionCreateReqBO bo); | |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * 根据 no,获取钱包余流水 |
| ... | ... | @@ -48,5 +48,5 @@ public interface PayWalletTransactionService { |
| 48 | 48 | * @return 钱包流水 |
| 49 | 49 | */ |
| 50 | 50 | PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); |
| 51 | - | |
| 51 | + | |
| 52 | 52 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java
| ... | ... | @@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 8 | 8 | import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletTransactionMapper; |
| 9 | 9 | import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO; |
| 10 | 10 | import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; |
| 11 | -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; | |
| 11 | +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; | |
| 12 | 12 | import lombok.extern.slf4j.Slf4j; |
| 13 | 13 | import org.springframework.stereotype.Service; |
| 14 | 14 | |
| ... | ... | @@ -43,7 +43,7 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | @Override |
| 46 | - public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) { | |
| 46 | + public PayWalletTransactionDO createWalletTransaction(WalletTransactionCreateReqBO bo) { | |
| 47 | 47 | PayWalletTransactionDO transaction = PayWalletTransactionConvert.INSTANCE.convert(bo) |
| 48 | 48 | .setNo(noRedisDAO.generate(WALLET_NO_PREFIX)); |
| 49 | 49 | payWalletTransactionMapper.insert(transaction); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java renamed to yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/WalletTransactionCreateReqBO.java