Commit 571961b4da8a7a251ab766d7dae60c4faf468207

Authored by jason
1 parent 7b727d5c

充值套餐修改

sql/mysql/pay_wallet.sql
... ... @@ -76,3 +76,52 @@ CREATE TABLE `pay_demo_transfer` (
76 76 ALTER TABLE `pay_channel`
77 77 MODIFY COLUMN `config` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '支付渠道配置' AFTER `app_id`;
78 78  
  79 +-- ----------------------------
  80 +-- 套餐充值表
  81 +-- ----------------------------
  82 +DROP TABLE IF EXISTS `pay_wallet_recharge_package`;
  83 +CREATE TABLE `pay_wallet_recharge_package`
  84 +(
  85 + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
  86 + `name` varchar(64) NOT NULL COMMENT '套餐名',
  87 + `pay_price` int NOT NULL COMMENT '支付金额',
  88 + `bonus_price` int NOT NULL COMMENT '赠送金额',
  89 + `status` tinyint NOT NULL COMMENT '状态',
  90 + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT '' COMMENT '创建者',
  91 + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  92 + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
  93 + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  94 + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  95 + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  96 + PRIMARY KEY (`id`) USING BTREE
  97 +) ENGINE=InnoDB COMMENT='套餐充值表';
  98 +
  99 +-- ----------------------------
  100 +-- Table structure for pay_wallet_recharge
  101 +-- ----------------------------
  102 +DROP TABLE IF EXISTS `pay_wallet_recharge`;
  103 +CREATE TABLE `pay_wallet_recharge` (
  104 + `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '编号',
  105 + `wallet_id` bigint(0) NOT NULL COMMENT '会员钱包 id',
  106 + `total_price` int(0) NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120',
  107 + `pay_price` int(0) NOT NULL COMMENT '实际支付金额',
  108 + `bonus_price` int(0) NOT NULL COMMENT '钱包赠送金额',
  109 + `package_id` bigint(0) DEFAULT NULL COMMENT '充值套餐编号',
  110 + `pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]',
  111 + `pay_order_id` bigint(0) DEFAULT NULL COMMENT '支付订单编号',
  112 + `pay_channel_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '支付成功的支付渠道',
  113 + `pay_time` datetime(0) DEFAULT NULL COMMENT '订单支付时间',
  114 + `pay_refund_id` bigint(0) DEFAULT NULL COMMENT '支付退款单编号',
  115 + `refund_total_price` int(0) NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额',
  116 + `refund_pay_price` int(0) NOT NULL DEFAULT 0 COMMENT '退款支付金额',
  117 + `refund_bonus_price` int(0) NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额',
  118 + `refund_time` datetime(0) DEFAULT NULL COMMENT '退款时间',
  119 + `refund_status` int(0) NOT NULL DEFAULT 0 COMMENT '退款状态',
  120 + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
  121 + `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  122 + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
  123 + `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
  124 + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  125 + `tenant_id` bigint(0) NOT NULL DEFAULT 0 COMMENT '租户编号',
  126 + PRIMARY KEY (`id`) USING BTREE
  127 +) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '会员钱包充值' ROW_FORMAT = Dynamic;
... ...
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java
... ... @@ -61,7 +61,8 @@ public interface ErrorCodeConstants {
61 61 ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR = new ErrorCode(1_007_008_008, "钱包退款更新失败,钱包退款单编号不匹配");
62 62 ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND = new ErrorCode(1_007_008_009, "钱包退款更新失败,退款订单不存在");
63 63 ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH = new ErrorCode(1_007_008_010, "钱包退款更新失败,退款单金额不匹配");
64   -
  64 + ErrorCode WALLET_RECHARGE_PACKAGE_AND_PRICE_IS_EMPTY = new ErrorCode(1_007_008_011, "充值金额和充钱套餐不能同时为空");
  65 + ErrorCode WALLET_RECHARGE_PACKAGE_NOT_FOUND = new ErrorCode(1_007_008_012, "钱包充值套餐不存在");
65 66 // ========== 转账模块 1-007-009-000 ==========
66 67 ErrorCode PAY_TRANSFER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_009_000, "发起转账报错,错误码:{},错误提示:{}");
67 68 ErrorCode PAY_TRANSFER_ALIPAY_LOGIN_ID_IS_EMPTY = new ErrorCode(1_007_009_001, "支付宝登录 ID 不能为空");
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java
... ... @@ -9,21 +9,11 @@ import javax.validation.constraints.Min;
9 9 @Data
10 10 public class AppPayWalletRechargeCreateReqVO {
11 11  
12   - @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
13   -// @NotNull(message = "支付金额不能为空")
  12 + @Schema(description = "支付金额", example = "1000")
14 13 @Min(value = 1, message = "支付金额必须大于零")
15 14 private Integer payPrice;
16 15  
17   - // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。
18   - // TOTO 那是不是搞一个充值模板
19   - @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
20   -// @NotNull(message = "钱包赠送金额不能为空")
21   -// @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零")
22   - private Integer bonusPrice = 0;
23 16  
24 17 @Schema(description = "充值套餐编号", example = "1024")
25 18 private Long packageId;
26   -
27   - // TODO @jason:可以改成 payPrice 和 packageId 两个至少一个不为空;
28   -
29 19 }
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java
1 1 package cn.iocoder.yudao.module.pay.convert.wallet;
2 2  
3   -import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
4 3 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO;
5 4 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
6 5 import org.mapstruct.Mapper;
... ... @@ -15,8 +14,8 @@ public interface PayWalletRechargeConvert {
15 14  
16 15 PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class);
17 16  
18   - @Mapping(target = "totalPrice", expression = "java(vo.getPayPrice() + vo.getBonusPrice() )")
19   - PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo);
  17 + @Mapping(target = "totalPrice", expression = "java( payPrice + bonusPrice)")
  18 + PayWalletRechargeDO convert(Long walletId, Integer payPrice, Integer bonusPrice, Long packageId);
20 19  
21 20 AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean);
22 21  
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java
... ... @@ -47,7 +47,11 @@ public class PayWalletRechargeDO extends BaseDO {
47 47 * 钱包赠送金额
48 48 */
49 49 private Integer bonusPrice;
50   - // TODO @jason:如果有赠送金额,需要关联下 PayWalletPackageDO 的 id 字段
  50 +
  51 + /**
  52 + * 充值套餐编号
  53 + */
  54 + private Long packageId;
51 55  
52 56 /**
53 57 * 是否已支付
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargePackageDO.java
1 1 package cn.iocoder.yudao.module.pay.dal.dataobject.wallet;
2 2  
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
3 4 import com.baomidou.mybatisplus.annotation.KeySequence;
4 5 import com.baomidou.mybatisplus.annotation.TableId;
5 6 import com.baomidou.mybatisplus.annotation.TableName;
... ... @@ -15,7 +16,7 @@ import lombok.Data;
15 16 @TableName(value ="pay_wallet_recharge_package")
16 17 @KeySequence("pay_wallet_recharge_package_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
17 18 @Data
18   -public class PayWalletRechargePackageDO {
  19 +public class PayWalletRechargePackageDO extends BaseDO {
19 20  
20 21 /**
21 22 * 编号
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargePackageMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
  2 +
  3 +
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
  6 +import org.apache.ibatis.annotations.Mapper;
  7 +
  8 +@Mapper
  9 +public interface PayWalletRechargePackageMapper extends BaseMapperX<PayWalletRechargePackageDO> {
  10 +
  11 +}
  12 +
  13 +
  14 +
  15 +
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargePackageService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.service.wallet;
  2 +
  3 +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
  4 +
  5 +/**
  6 + * 钱包充值套餐 Service 接口
  7 + *
  8 + * @author jason
  9 + */
  10 +public interface PayWalletRechargePackageService {
  11 +
  12 + /**
  13 + * 获取钱包充值套餐
  14 + * @param packageId 充值套餐编号
  15 + */
  16 + PayWalletRechargePackageDO getWalletRechargePackage(Long packageId);
  17 +}
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargePackageServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.service.wallet;
  2 +
  3 +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
  4 +import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargePackageMapper;
  5 +import org.springframework.stereotype.Service;
  6 +
  7 +import javax.annotation.Resource;
  8 +
  9 +/**
  10 + * 钱包充值套餐 Service 实现类
  11 + *
  12 + * @author jason
  13 + */
  14 +@Service
  15 +public class PayWalletRechargePackageServiceImpl implements PayWalletRechargePackageService {
  16 +
  17 + @Resource
  18 + private PayWalletRechargePackageMapper rechargePackageMapper;
  19 +
  20 + @Override
  21 + public PayWalletRechargePackageDO getWalletRechargePackage(Long packageId) {
  22 + return rechargePackageMapper.selectById(packageId);
  23 + }
  24 +}
... ...
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
... ... @@ -6,11 +6,11 @@ import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
6 6 import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
7 7 import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
8 8 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
9   -import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert;
10 9 import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
11 10 import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO;
12 11 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
13 12 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
  13 +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
14 14 import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargeMapper;
15 15 import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
16 16 import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
... ... @@ -24,12 +24,14 @@ import org.springframework.transaction.annotation.Transactional;
24 24 import javax.annotation.Resource;
25 25 import java.time.Duration;
26 26 import java.time.LocalDateTime;
  27 +import java.util.Objects;
27 28  
28 29 import static cn.hutool.core.util.ObjectUtil.notEqual;
29 30 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
30 31 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
31 32 import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
32 33 import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
  34 +import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE;
33 35 import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
34 36 import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*;
35 37  
... ... @@ -58,14 +60,33 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
58 60 private PayOrderService payOrderService;
59 61 @Resource
60 62 private PayRefundService payRefundService;
  63 + @Resource
  64 + private PayWalletRechargePackageService payWalletRechargePackageService;
61 65  
62 66 @Override
63 67 @Transactional(rollbackFor = Exception.class)
64 68 public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType,
65   - AppPayWalletRechargeCreateReqVO createReqVO) {
66   - // 1. 新增钱包充值记录
  69 + AppPayWalletRechargeCreateReqVO reqVO) {
  70 + // 1.1 校验参数
  71 + if (Objects.isNull(reqVO.getPayPrice()) && Objects.isNull(reqVO.getPackageId())) {
  72 + throw exception(WALLET_RECHARGE_PACKAGE_AND_PRICE_IS_EMPTY);
  73 + }
  74 + // 1.2 新增钱包充值记录
  75 + int payPrice ;
  76 + int bonusPrice = 0 ;
  77 + if (Objects.nonNull(reqVO.getPackageId())) {
  78 + PayWalletRechargePackageDO rechargePackage = payWalletRechargePackageService.getWalletRechargePackage(reqVO.getPackageId());
  79 + if (rechargePackage == null) {
  80 + throw exception(WALLET_RECHARGE_PACKAGE_NOT_FOUND);
  81 + }
  82 + payPrice = rechargePackage.getPayPrice();
  83 + bonusPrice = rechargePackage.getBonusPrice();
  84 + } else {
  85 + payPrice = reqVO.getPayPrice();
  86 + }
  87 +
67 88 PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType);
68   - PayWalletRechargeDO walletRecharge = PayWalletRechargeConvert.INSTANCE.convert(wallet.getId(), createReqVO);
  89 + PayWalletRechargeDO walletRecharge = INSTANCE.convert(wallet.getId(), payPrice, bonusPrice, reqVO.getPackageId());
69 90 walletRechargeMapper.insert(walletRecharge);
70 91  
71 92 // 2.1 创建支付单
... ...