Commit dbd7ab5f231c60bac29ee4346263057fb32c879c

Authored by jason
1 parent 080c32b9

code review 修改

sql/mysql/pay_wallet.sql
@@ -50,17 +50,17 @@ CREATE TABLE `pay_wallet_recharge` @@ -50,17 +50,17 @@ CREATE TABLE `pay_wallet_recharge`
50 ( 50 (
51 `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', 51 `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
52 `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', 52 `wallet_id` bigint NOT NULL COMMENT '会员钱包 id',
53 - `price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', 53 + `total_price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120',
54 `pay_price` int NOT NULL COMMENT '实际支付金额', 54 `pay_price` int NOT NULL COMMENT '实际支付金额',
55 - `wallet_bonus` int NOT NULL COMMENT '钱包赠送金额', 55 + `bonus_price` int NOT NULL COMMENT '钱包赠送金额',
56 `pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]', 56 `pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]',
57 `pay_order_id` bigint NULL COMMENT '支付订单编号', 57 `pay_order_id` bigint NULL COMMENT '支付订单编号',
58 `pay_channel_code` varchar(16) NULL COMMENT '支付成功的支付渠道', 58 `pay_channel_code` varchar(16) NULL COMMENT '支付成功的支付渠道',
59 `pay_time` datetime NULL COMMENT '订单支付时间', 59 `pay_time` datetime NULL COMMENT '订单支付时间',
60 `pay_refund_id` bigint NULL COMMENT '支付退款单编号', 60 `pay_refund_id` bigint NULL COMMENT '支付退款单编号',
61 - `refund_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', 61 + `refund_total_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额',
62 `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额', 62 `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额',
63 - `refund_wallet_bonus` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', 63 + `refund_bonus_price` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额',
64 `refund_time` datetime NULL COMMENT '退款时间', 64 `refund_time` datetime NULL COMMENT '退款时间',
65 `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', 65 `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
66 `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 66 `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java
@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
4 import lombok.Data; 4 import lombok.Data;
5 5
6 import javax.validation.constraints.DecimalMin; 6 import javax.validation.constraints.DecimalMin;
  7 +import javax.validation.constraints.Min;
7 import javax.validation.constraints.NotNull; 8 import javax.validation.constraints.NotNull;
8 9
9 @Schema(description = "用户 APP - 创建钱包充值 Request VO") 10 @Schema(description = "用户 APP - 创建钱包充值 Request VO")
@@ -12,14 +13,14 @@ public class AppPayWalletRechargeCreateReqVO { @@ -12,14 +13,14 @@ public class AppPayWalletRechargeCreateReqVO {
12 13
13 @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") 14 @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
14 @NotNull(message = "支付金额不能为空") 15 @NotNull(message = "支付金额不能为空")
15 - // TODO @jason999:是不是 @Min 哈?  
16 - @DecimalMin(value = "0", inclusive = false, message = "支付金额必须大于零") 16 + @Min(value = 1, message = "支付金额必须大于零")
17 private Integer payPrice; 17 private Integer payPrice;
18 18
19 // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 19 // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。
  20 + // TOTO 那是不是搞一个充值模板
20 @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") 21 @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
21 @NotNull(message = "钱包赠送金额不能为空") 22 @NotNull(message = "钱包赠送金额不能为空")
22 @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零") 23 @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零")
23 - private Integer walletBonus; 24 + private Integer bonusPrice;
24 25
25 } 26 }
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java
@@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalle @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalle
4 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; 4 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO;
5 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; 5 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
6 import org.mapstruct.Mapper; 6 import org.mapstruct.Mapper;
  7 +import org.mapstruct.Mapping;
7 import org.mapstruct.factory.Mappers; 8 import org.mapstruct.factory.Mappers;
8 9
9 /** 10 /**
@@ -14,14 +15,8 @@ public interface PayWalletRechargeConvert { @@ -14,14 +15,8 @@ public interface PayWalletRechargeConvert {
14 15
15 PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class); 16 PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class);
16 17
17 - PayWalletRechargeDO convert(AppPayWalletRechargeCreateReqVO vo);  
18 -  
19 - // TODO @jason:好像 price 相加,可以写个表达式的,通过 @Mapping  
20 - default PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo) {  
21 - PayWalletRechargeDO walletRecharge = convert(vo);  
22 - return walletRecharge.setWalletId(walletId)  
23 - .setPrice(walletRecharge.getPayPrice() + walletRecharge.getWalletBonus());  
24 - } 18 + @Mapping(target = "totalPrice", expression = "java(vo.getPayPrice() + vo.getBonusPrice() )")
  19 + PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo);
25 20
26 AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean); 21 AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean);
27 22
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java
@@ -31,22 +31,21 @@ public class PayWalletRechargeDO extends BaseDO { @@ -31,22 +31,21 @@ public class PayWalletRechargeDO extends BaseDO {
31 */ 31 */
32 private Long walletId; 32 private Long walletId;
33 33
34 - // TODO @jason:要不改成 totalPrice?  
35 /** 34 /**
36 * 用户实际到账余额 35 * 用户实际到账余额
37 * 36 *
38 * 例如充 100 送 20,则该值是 120 37 * 例如充 100 送 20,则该值是 120
39 */ 38 */
40 - private Integer price; 39 + private Integer totalPrice;
41 /** 40 /**
42 * 实际支付金额 41 * 实际支付金额
43 */ 42 */
44 private Integer payPrice; 43 private Integer payPrice;
45 - // TODO @jason:bonusPrice 哈,更统一一点; 44 +
46 /** 45 /**
47 * 钱包赠送金额 46 * 钱包赠送金额
48 */ 47 */
49 - private Integer walletBonus; 48 + private Integer bonusPrice;
50 49
51 /** 50 /**
52 * 是否已支付 51 * 是否已支付
@@ -62,6 +61,7 @@ public class PayWalletRechargeDO extends BaseDO { @@ -62,6 +61,7 @@ public class PayWalletRechargeDO extends BaseDO {
62 * 关联 {@link PayOrderDO#getId()} 61 * 关联 {@link PayOrderDO#getId()}
63 */ 62 */
64 private Long payOrderId; 63 private Long payOrderId;
  64 +
65 /** 65 /**
66 * 支付成功的支付渠道 66 * 支付成功的支付渠道
67 * 67 *
@@ -79,20 +79,21 @@ public class PayWalletRechargeDO extends BaseDO { @@ -79,20 +79,21 @@ public class PayWalletRechargeDO extends BaseDO {
79 * 关联 {@link PayRefundDO#getId()} 79 * 关联 {@link PayRefundDO#getId()}
80 */ 80 */
81 private Long payRefundId; 81 private Long payRefundId;
82 - // TODO @jason:要不改成 refundTotalPrice? 82 +
83 /** 83 /**
84 * 退款金额,包含赠送金额 84 * 退款金额,包含赠送金额
85 */ 85 */
86 - private Integer refundPrice; 86 + private Integer refundTotalPrice;
87 /** 87 /**
88 * 退款支付金额 88 * 退款支付金额
89 */ 89 */
90 private Integer refundPayPrice; 90 private Integer refundPayPrice;
91 - // TODO @jason:要不改成 refundBonusPrice? 91 +
92 /** 92 /**
93 * 退款钱包赠送金额 93 * 退款钱包赠送金额
94 */ 94 */
95 - private Integer refundWalletBonus; 95 + private Integer refundBonusPrice;
  96 +
96 /** 97 /**
97 * 退款时间 98 * 退款时间
98 */ 99 */
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java
@@ -14,15 +14,13 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { @@ -14,15 +14,13 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
14 PayWalletDO::getUserType, userType); 14 PayWalletDO::getUserType, userType);
15 } 15 }
16 16
17 - // TODO @jason:下面几个更新方法,把 id 放前面哈。一般来说,重要参数放前面;  
18 -  
19 /** 17 /**
20 * 当消费退款时候, 更新钱包 18 * 当消费退款时候, 更新钱包
21 * 19 *
22 - * @param price 消费金额  
23 * @param id 钱包 id 20 * @param id 钱包 id
  21 + * @param price 消费金额
24 */ 22 */
25 - default int updateWhenConsumptionRefund(Integer price, Long id){ 23 + default int updateWhenConsumptionRefund(Long id, Integer price){
26 LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() 24 LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
27 .setSql(" balance = balance + " + price 25 .setSql(" balance = balance + " + price
28 + ", total_expense = total_expense - " + price) 26 + ", total_expense = total_expense - " + price)
@@ -36,7 +34,7 @@ public interface PayWalletMapper extends BaseMapperX&lt;PayWalletDO&gt; { @@ -36,7 +34,7 @@ public interface PayWalletMapper extends BaseMapperX&lt;PayWalletDO&gt; {
36 * @param price 消费金额 34 * @param price 消费金额
37 * @param id 钱包 id 35 * @param id 钱包 id
38 */ 36 */
39 - default int updateWhenConsumption(Integer price, Long id){ 37 + default int updateWhenConsumption(Long id, Integer price){
40 LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() 38 LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
41 .setSql(" balance = balance - " + price 39 .setSql(" balance = balance - " + price
42 + ", total_expense = total_expense + " + price) 40 + ", total_expense = total_expense + " + price)
@@ -47,10 +45,11 @@ public interface PayWalletMapper extends BaseMapperX&lt;PayWalletDO&gt; { @@ -47,10 +45,11 @@ public interface PayWalletMapper extends BaseMapperX&lt;PayWalletDO&gt; {
47 45
48 /** 46 /**
49 * 当充值的时候,更新钱包 47 * 当充值的时候,更新钱包
50 - * @param price 钱包金额 48 + *
51 * @param id 钱包 id 49 * @param id 钱包 id
  50 + * @param price 钱包金额
52 */ 51 */
53 - default int updateWhenRecharge(Integer price, Long id){ 52 + default int updateWhenRecharge(Long id, Integer price){
54 LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() 53 LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
55 .setSql(" balance = balance + " + price 54 .setSql(" balance = balance + " + price
56 + ", total_recharge = total_recharge + " + price) 55 + ", total_recharge = total_recharge + " + price)
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
@@ -66,8 +66,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { @@ -66,8 +66,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
66 // 2.2 更新钱包充值记录中支付订单 66 // 2.2 更新钱包充值记录中支付订单
67 walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) 67 walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId)
68 .setId(walletRecharge.getId())); 68 .setId(walletRecharge.getId()));
69 - // TODO @jason:是不是你直接返回就好啦;然后 payOrderId 设置下;  
70 - return walletRechargeMapper.selectById(walletRecharge.getId()); 69 +
  70 + walletRecharge.setPayOrderId(payOrderId);
  71 + return walletRecharge;
71 } 72 }
72 73
73 @Override 74 @Override
@@ -92,8 +93,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { @@ -92,8 +93,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
92 93
93 // 3. 更新钱包余额 94 // 3. 更新钱包余额
94 // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110; 95 // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110;
  96 + // TODO 需要钱包中加个可提现余额
95 payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id), 97 payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id),
96 - PayWalletBizTypeEnum.RECHARGE, walletRecharge.getPrice()); 98 + PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice());
97 } 99 }
98 100
99 private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { 101 private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) {
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
@@ -125,7 +125,7 @@ public class PayWalletServiceImpl implements PayWalletService { @@ -125,7 +125,7 @@ public class PayWalletServiceImpl implements PayWalletService {
125 int updateCounts = 0 ; 125 int updateCounts = 0 ;
126 switch (bizType) { 126 switch (bizType) {
127 case PAYMENT: { 127 case PAYMENT: {
128 - updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId()); 128 + updateCounts = walletMapper.updateWhenConsumption(payWallet.getId(), price);
129 break; 129 break;
130 } 130 }
131 case RECHARGE_REFUND: { 131 case RECHARGE_REFUND: {
@@ -156,11 +156,11 @@ public class PayWalletServiceImpl implements PayWalletService { @@ -156,11 +156,11 @@ public class PayWalletServiceImpl implements PayWalletService {
156 // 1.2 更新钱包金额 156 // 1.2 更新钱包金额
157 switch (bizType) { 157 switch (bizType) {
158 case PAYMENT_REFUND: { // 退款更新 158 case PAYMENT_REFUND: { // 退款更新
159 - walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); 159 + walletMapper.updateWhenConsumptionRefund(payWallet.getId(), price);
160 break; 160 break;
161 } 161 }
162 case RECHARGE: { // 充值更新 162 case RECHARGE: { // 充值更新
163 - walletMapper.updateWhenRecharge(price, payWallet.getId()); 163 + walletMapper.updateWhenRecharge(payWallet.getId(), price);
164 break; 164 break;
165 } 165 }
166 // TODO 其它类型;这里可以先跑异常;避免有业务搞错; 166 // TODO 其它类型;这里可以先跑异常;避免有业务搞错;