mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	code review 修改
This commit is contained in:
		| @@ -50,17 +50,17 @@ CREATE TABLE `pay_wallet_recharge` | |||||||
| ( | ( | ||||||
|     `id`                            bigint      NOT NULL AUTO_INCREMENT COMMENT '编号', |     `id`                            bigint      NOT NULL AUTO_INCREMENT COMMENT '编号', | ||||||
|     `wallet_id`                     bigint      NOT NULL COMMENT '会员钱包 id', |     `wallet_id`                     bigint      NOT NULL COMMENT '会员钱包 id', | ||||||
|     `price`                         int         NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', |     `total_price`                   int         NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', | ||||||
|     `pay_price`                     int         NOT NULL COMMENT '实际支付金额', |     `pay_price`                     int         NOT NULL COMMENT '实际支付金额', | ||||||
|     `wallet_bonus`                  int         NOT NULL COMMENT '钱包赠送金额', |     `bonus_price`                   int         NOT NULL COMMENT '钱包赠送金额', | ||||||
|     `pay_status`                    bit(1)      NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]', |     `pay_status`                    bit(1)      NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]', | ||||||
|     `pay_order_id`                  bigint      NULL COMMENT '支付订单编号', |     `pay_order_id`                  bigint      NULL COMMENT '支付订单编号', | ||||||
|     `pay_channel_code`              varchar(16) NULL COMMENT '支付成功的支付渠道', |     `pay_channel_code`              varchar(16) NULL COMMENT '支付成功的支付渠道', | ||||||
|     `pay_time`                      datetime    NULL COMMENT '订单支付时间', |     `pay_time`                      datetime    NULL COMMENT '订单支付时间', | ||||||
|     `pay_refund_id`                 bigint      NULL COMMENT '支付退款单编号', |     `pay_refund_id`                 bigint      NULL COMMENT '支付退款单编号', | ||||||
|     `refund_price`                  int         NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', |     `refund_total_price`            int         NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', | ||||||
|     `refund_pay_price`              int         NOT NULL DEFAULT 0 COMMENT '退款支付金额', |     `refund_pay_price`              int         NOT NULL DEFAULT 0 COMMENT '退款支付金额', | ||||||
|     `refund_wallet_bonus`           int         NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', |     `refund_bonus_price`            int         NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', | ||||||
|     `refund_time`                   datetime    NULL COMMENT '退款时间', |     `refund_time`                   datetime    NULL COMMENT '退款时间', | ||||||
|     `creator`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', |     `creator`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', | ||||||
|     `create_time`    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |     `create_time`    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; | |||||||
| import lombok.Data; | import lombok.Data; | ||||||
|  |  | ||||||
| import javax.validation.constraints.DecimalMin; | import javax.validation.constraints.DecimalMin; | ||||||
|  | import javax.validation.constraints.Min; | ||||||
| import javax.validation.constraints.NotNull; | import javax.validation.constraints.NotNull; | ||||||
|  |  | ||||||
| @Schema(description = "用户 APP - 创建钱包充值 Request VO") | @Schema(description = "用户 APP - 创建钱包充值 Request VO") | ||||||
| @@ -12,14 +13,14 @@ public class AppPayWalletRechargeCreateReqVO { | |||||||
|  |  | ||||||
|     @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") |     @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | ||||||
|     @NotNull(message = "支付金额不能为空") |     @NotNull(message = "支付金额不能为空") | ||||||
|     // TODO @jason999:是不是 @Min 哈? |     @Min(value = 1,  message = "支付金额必须大于零") | ||||||
|     @DecimalMin(value = "0", inclusive = false, message = "支付金额必须大于零") |  | ||||||
|     private Integer payPrice; |     private Integer payPrice; | ||||||
|  |  | ||||||
|     // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 |     // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 | ||||||
|  |     // TOTO 那是不是搞一个充值模板 | ||||||
|     @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") |     @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | ||||||
|     @NotNull(message = "钱包赠送金额不能为空") |     @NotNull(message = "钱包赠送金额不能为空") | ||||||
|     @DecimalMin(value = "0",  message = "钱包赠送金额必须大于等于零") |     @DecimalMin(value = "0",  message = "钱包赠送金额必须大于等于零") | ||||||
|     private Integer walletBonus; |     private Integer bonusPrice; | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalle | |||||||
| import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; | import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; | ||||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; | ||||||
| import org.mapstruct.Mapper; | import org.mapstruct.Mapper; | ||||||
|  | import org.mapstruct.Mapping; | ||||||
| import org.mapstruct.factory.Mappers; | import org.mapstruct.factory.Mappers; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -14,14 +15,8 @@ public interface PayWalletRechargeConvert { | |||||||
|  |  | ||||||
|     PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class); |     PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class); | ||||||
|  |  | ||||||
|     PayWalletRechargeDO convert(AppPayWalletRechargeCreateReqVO vo); |     @Mapping(target = "totalPrice", expression = "java(vo.getPayPrice() + vo.getBonusPrice() )") | ||||||
|  |     PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo); | ||||||
|     // TODO @jason:好像 price 相加,可以写个表达式的,通过 @Mapping |  | ||||||
|     default PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo) { |  | ||||||
|         PayWalletRechargeDO walletRecharge = convert(vo); |  | ||||||
|         return walletRecharge.setWalletId(walletId) |  | ||||||
|                 .setPrice(walletRecharge.getPayPrice() + walletRecharge.getWalletBonus()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean); |     AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -31,22 +31,21 @@ public class PayWalletRechargeDO extends BaseDO { | |||||||
|      */ |      */ | ||||||
|     private Long walletId; |     private Long walletId; | ||||||
|  |  | ||||||
|     // TODO @jason:要不改成 totalPrice? |  | ||||||
|     /** |     /** | ||||||
|      * 用户实际到账余额 |      * 用户实际到账余额 | ||||||
|      * |      * | ||||||
|      * 例如充 100 送 20,则该值是 120 |      * 例如充 100 送 20,则该值是 120 | ||||||
|      */ |      */ | ||||||
|     private Integer price; |     private Integer totalPrice; | ||||||
|     /** |     /** | ||||||
|      * 实际支付金额 |      * 实际支付金额 | ||||||
|      */ |      */ | ||||||
|     private Integer payPrice; |     private Integer payPrice; | ||||||
|     // TODO @jason:bonusPrice 哈,更统一一点; |  | ||||||
|     /** |     /** | ||||||
|      * 钱包赠送金额 |      * 钱包赠送金额 | ||||||
|      */ |      */ | ||||||
|     private Integer walletBonus; |     private Integer bonusPrice; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 是否已支付 |      * 是否已支付 | ||||||
| @@ -62,6 +61,7 @@ public class PayWalletRechargeDO extends BaseDO { | |||||||
|      * 关联 {@link PayOrderDO#getId()} |      * 关联 {@link PayOrderDO#getId()} | ||||||
|      */ |      */ | ||||||
|     private Long payOrderId; |     private Long payOrderId; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 支付成功的支付渠道 |      * 支付成功的支付渠道 | ||||||
|      * |      * | ||||||
| @@ -79,20 +79,21 @@ public class PayWalletRechargeDO extends BaseDO { | |||||||
|      * 关联 {@link PayRefundDO#getId()} |      * 关联 {@link PayRefundDO#getId()} | ||||||
|      */ |      */ | ||||||
|     private Long payRefundId; |     private Long payRefundId; | ||||||
|     // TODO @jason:要不改成 refundTotalPrice? |  | ||||||
|     /** |     /** | ||||||
|      * 退款金额,包含赠送金额 |      * 退款金额,包含赠送金额 | ||||||
|      */ |      */ | ||||||
|     private Integer refundPrice; |     private Integer refundTotalPrice; | ||||||
|     /** |     /** | ||||||
|      * 退款支付金额 |      * 退款支付金额 | ||||||
|      */ |      */ | ||||||
|     private Integer refundPayPrice; |     private Integer refundPayPrice; | ||||||
|     // TODO @jason:要不改成 refundBonusPrice? |  | ||||||
|     /** |     /** | ||||||
|      * 退款钱包赠送金额 |      * 退款钱包赠送金额 | ||||||
|      */ |      */ | ||||||
|     private Integer refundWalletBonus; |     private Integer refundBonusPrice; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 退款时间 |      * 退款时间 | ||||||
|      */ |      */ | ||||||
|   | |||||||
| @@ -14,15 +14,13 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | |||||||
|                 PayWalletDO::getUserType, userType); |                 PayWalletDO::getUserType, userType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // TODO @jason:下面几个更新方法,把 id 放前面哈。一般来说,重要参数放前面; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 当消费退款时候, 更新钱包 |      * 当消费退款时候, 更新钱包 | ||||||
|      * |      * | ||||||
|      * @param price 消费金额 |  | ||||||
|      * @param id 钱包 id |      * @param id 钱包 id | ||||||
|  |      * @param price 消费金额 | ||||||
|      */ |      */ | ||||||
|     default int updateWhenConsumptionRefund(Integer price, Long id){ |     default int updateWhenConsumptionRefund(Long id, Integer price){ | ||||||
|         LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() |         LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() | ||||||
|                 .setSql(" balance = balance + " + price |                 .setSql(" balance = balance + " + price | ||||||
|                         + ", total_expense = total_expense - " + price) |                         + ", total_expense = total_expense - " + price) | ||||||
| @@ -36,7 +34,7 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | |||||||
|      * @param price 消费金额 |      * @param price 消费金额 | ||||||
|      * @param id 钱包 id |      * @param id 钱包 id | ||||||
|      */ |      */ | ||||||
|     default int updateWhenConsumption(Integer price, Long id){ |     default int updateWhenConsumption(Long id, Integer price){ | ||||||
|         LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() |         LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() | ||||||
|                 .setSql(" balance = balance - " + price |                 .setSql(" balance = balance - " + price | ||||||
|                         + ", total_expense = total_expense + " + price) |                         + ", total_expense = total_expense + " + price) | ||||||
| @@ -47,10 +45,11 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 当充值的时候,更新钱包 |      * 当充值的时候,更新钱包 | ||||||
|      * @param price 钱包金额 |      * | ||||||
|      * @param id 钱包 id |      * @param id 钱包 id | ||||||
|  |      * @param price 钱包金额 | ||||||
|      */ |      */ | ||||||
|     default int updateWhenRecharge(Integer price, Long id){ |     default int updateWhenRecharge(Long id, Integer price){ | ||||||
|         LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() |         LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() | ||||||
|                 .setSql(" balance = balance + " + price |                 .setSql(" balance = balance + " + price | ||||||
|                         + ", total_recharge = total_recharge + " + price) |                         + ", total_recharge = total_recharge + " + price) | ||||||
|   | |||||||
| @@ -66,8 +66,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { | |||||||
|         // 2.2 更新钱包充值记录中支付订单 |         // 2.2 更新钱包充值记录中支付订单 | ||||||
|         walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) |         walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) | ||||||
|                 .setId(walletRecharge.getId())); |                 .setId(walletRecharge.getId())); | ||||||
|         // TODO @jason:是不是你直接返回就好啦;然后 payOrderId 设置下; |  | ||||||
|         return walletRechargeMapper.selectById(walletRecharge.getId()); |         walletRecharge.setPayOrderId(payOrderId); | ||||||
|  |         return walletRecharge; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -92,8 +93,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { | |||||||
|  |  | ||||||
|         // 3. 更新钱包余额 |         // 3. 更新钱包余额 | ||||||
|         // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110; |         // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110; | ||||||
|  |         // TODO 需要钱包中加个可提现余额 | ||||||
|         payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id), |         payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id), | ||||||
|                 PayWalletBizTypeEnum.RECHARGE, walletRecharge.getPrice()); |                 PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { |     private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { | ||||||
|   | |||||||
| @@ -125,7 +125,7 @@ public class PayWalletServiceImpl implements  PayWalletService { | |||||||
|         int updateCounts = 0 ; |         int updateCounts = 0 ; | ||||||
|         switch (bizType) { |         switch (bizType) { | ||||||
|             case PAYMENT: { |             case PAYMENT: { | ||||||
|                 updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId()); |                 updateCounts = walletMapper.updateWhenConsumption(payWallet.getId(), price); | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|             case RECHARGE_REFUND: { |             case RECHARGE_REFUND: { | ||||||
| @@ -156,11 +156,11 @@ public class PayWalletServiceImpl implements  PayWalletService { | |||||||
|         // 1.2 更新钱包金额 |         // 1.2 更新钱包金额 | ||||||
|         switch (bizType) { |         switch (bizType) { | ||||||
|             case PAYMENT_REFUND: { // 退款更新 |             case PAYMENT_REFUND: { // 退款更新 | ||||||
|                 walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); |                 walletMapper.updateWhenConsumptionRefund(payWallet.getId(), price); | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|             case RECHARGE: { // 充值更新 |             case RECHARGE: { // 充值更新 | ||||||
|                 walletMapper.updateWhenRecharge(price, payWallet.getId()); |                 walletMapper.updateWhenRecharge(payWallet.getId(), price); | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|             // TODO 其它类型;这里可以先跑异常;避免有业务搞错; |             // TODO 其它类型;这里可以先跑异常;避免有业务搞错; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jason
					jason