Commit 16cea614354bcb24a5ec00c39facc6c44138fd2b

Authored by YunaiV
1 parent 34891447

wallet:增加充值套餐

sql/mysql/pay_wallet.sql
1 -- ---------------------------- 1 -- ----------------------------
2 --- 会员钱包表  
3 --- ----------------------------  
4 -DROP TABLE IF EXISTS `pay_wallet`;  
5 -CREATE TABLE `pay_wallet`  
6 -(  
7 - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',  
8 - `user_id` bigint NOT NULL COMMENT '用户编号',  
9 - `user_type` tinyint NOT NULL DEFAULT 0 COMMENT '用户类型',  
10 - `balance` int NOT NULL DEFAULT 0 COMMENT '余额,单位分',  
11 - `total_expense` int NOT NULL DEFAULT 0 COMMENT '累计支出,单位分',  
12 - `total_recharge` int NOT NULL DEFAULT 0 COMMENT '累计充值,单位分',  
13 - `freeze_price` int NOT NULL DEFAULT 0 COMMENT '冻结金额,单位分',  
14 - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',  
15 - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',  
16 - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',  
17 - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',  
18 - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',  
19 - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',  
20 - PRIMARY KEY (`id`) USING BTREE  
21 -) ENGINE=InnoDB COMMENT='会员钱包表';  
22 -  
23 --- ----------------------------  
24 --- 会员钱包流水表  
25 --- ----------------------------  
26 -DROP TABLE IF EXISTS `pay_wallet_transaction`;  
27 -CREATE TABLE `pay_wallet_transaction`  
28 -(  
29 - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',  
30 - `wallet_id` bigint NOT NULL COMMENT '会员钱包 id',  
31 - `biz_type` tinyint NOT NULL COMMENT '关联类型',  
32 - `biz_id` varchar(64) NOT NULL COMMENT '关联业务编号',  
33 - `no` varchar(64) NOT NULL COMMENT '流水号',  
34 - `title` varchar(128) NOT NULL COMMENT '流水标题',  
35 - `price` int NOT NULL COMMENT '交易金额, 单位分',  
36 - `balance` int NOT NULL COMMENT '余额, 单位分',  
37 - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',  
38 - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',  
39 - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',  
40 - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',  
41 - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',  
42 - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',  
43 - PRIMARY KEY (`id`) USING BTREE  
44 -) ENGINE=InnoDB COMMENT='会员钱包流水表';  
45 -  
46 --- ----------------------------  
47 --- 会员钱包充值  
48 --- ----------------------------  
49 -DROP TABLE IF EXISTS `pay_wallet_recharge`;  
50 -CREATE TABLE `pay_wallet_recharge`  
51 -(  
52 - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',  
53 - `wallet_id` bigint NOT NULL COMMENT '会员钱包 id',  
54 - `total_price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120',  
55 - `pay_price` int NOT NULL COMMENT '实际支付金额',  
56 - `bonus_price` int NOT NULL COMMENT '钱包赠送金额',  
57 - `pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]',  
58 - `pay_order_id` bigint NULL COMMENT '支付订单编号',  
59 - `pay_channel_code` varchar(16) NULL COMMENT '支付成功的支付渠道',  
60 - `pay_time` datetime NULL COMMENT '订单支付时间',  
61 - `pay_refund_id` bigint NULL COMMENT '支付退款单编号',  
62 - `refund_total_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额',  
63 - `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额',  
64 - `refund_bonus_price` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额',  
65 - `refund_time` datetime NULL COMMENT '退款时间',  
66 - `refund_status` int NOT NULL DEFAULT 0 COMMENT '退款状态',  
67 - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',  
68 - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',  
69 - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',  
70 - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',  
71 - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',  
72 - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',  
73 - PRIMARY KEY (`id`) USING BTREE  
74 -) ENGINE=InnoDB COMMENT='会员钱包充值';  
75 -  
76 --- ----------------------------  
77 -- 转账单表 2 -- 转账单表
78 -- ---------------------------- 3 -- ----------------------------
79 DROP TABLE IF EXISTS `pay_transfer`; 4 DROP TABLE IF EXISTS `pay_transfer`;
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/PayWalletRechargeController.java
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.pay.controller.admin.wallet; @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.pay.controller.admin.wallet;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 4 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  5 +import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
5 import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO; 6 import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO;
6 import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargeService; 7 import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargeService;
7 import io.swagger.v3.oas.annotations.Operation; 8 import io.swagger.v3.oas.annotations.Operation;
@@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.*; @@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
13 14
14 import javax.annotation.Resource; 15 import javax.annotation.Resource;
15 import javax.annotation.security.PermitAll; 16 import javax.annotation.security.PermitAll;
  17 +import javax.validation.Valid;
16 18
17 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 19 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
18 import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; 20 import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@@ -27,12 +29,22 @@ public class PayWalletRechargeController { @@ -27,12 +29,22 @@ public class PayWalletRechargeController {
27 @Resource 29 @Resource
28 private PayWalletRechargeService walletRechargeService; 30 private PayWalletRechargeService walletRechargeService;
29 31
  32 + @PostMapping("/update-paid")
  33 + @Operation(summary = "更新钱包充值为已充值") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob
  34 + @PermitAll // 无需登录, 内部校验实现
  35 + @OperateLog(enable = false) // 禁用操作日志,因为没有操作人
  36 + public CommonResult<Boolean> updateWalletRechargerPaid(@Valid @RequestBody PayOrderNotifyReqDTO notifyReqDTO) {
  37 + walletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()),
  38 + notifyReqDTO.getPayOrderId());
  39 + return success(true);
  40 + }
30 41
  42 + // TODO @jason:发起退款,要 post 操作哈;
31 @GetMapping("/refund") 43 @GetMapping("/refund")
32 @Operation(summary = "发起钱包充值退款") 44 @Operation(summary = "发起钱包充值退款")
33 @Parameter(name = "id", description = "编号", required = true, example = "1024") 45 @Parameter(name = "id", description = "编号", required = true, example = "1024")
34 public CommonResult<Boolean> refundWalletRecharge(@RequestParam("id") Long id) { 46 public CommonResult<Boolean> refundWalletRecharge(@RequestParam("id") Long id) {
35 - walletRechargeService.refundWalletRecharge(id,getClientIP()); 47 + walletRechargeService.refundWalletRecharge(id, getClientIP());
36 return success(true); 48 return success(true);
37 } 49 }
38 50
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java
1 package cn.iocoder.yudao.module.pay.controller.app.wallet; 1 package cn.iocoder.yudao.module.pay.controller.app.wallet;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;  
5 -import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;  
6 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO; 4 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
7 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; 5 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO;
8 import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert; 6 import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert;
@@ -18,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping; @@ -18,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
18 import org.springframework.web.bind.annotation.RestController; 16 import org.springframework.web.bind.annotation.RestController;
19 17
20 import javax.annotation.Resource; 18 import javax.annotation.Resource;
21 -import javax.annotation.security.PermitAll;  
22 import javax.validation.Valid; 19 import javax.validation.Valid;
23 20
24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -44,13 +41,4 @@ public class AppPayWalletRechargeController { @@ -44,13 +41,4 @@ public class AppPayWalletRechargeController {
44 return success(PayWalletRechargeConvert.INSTANCE.convert(walletRecharge)); 41 return success(PayWalletRechargeConvert.INSTANCE.convert(walletRecharge));
45 } 42 }
46 43
47 - @PostMapping("/update-paid")  
48 - @Operation(summary = "更新钱包充值为已充值") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob  
49 - @PermitAll // 无需登录,安全由 内部校验实现  
50 - @OperateLog(enable = false) // 禁用操作日志,因为没有操作人  
51 - public CommonResult<Boolean> updateWalletRechargerPaid(@Valid @RequestBody PayOrderNotifyReqDTO notifyReqDTO) {  
52 - walletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()),  
53 - notifyReqDTO.getPayOrderId());  
54 - return success(true);  
55 - }  
56 } 44 }
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargePackageController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.controller.app.wallet;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletPackageRespVO;
  5 +import io.swagger.v3.oas.annotations.Operation;
  6 +import io.swagger.v3.oas.annotations.tags.Tag;
  7 +import lombok.extern.slf4j.Slf4j;
  8 +import org.springframework.validation.annotation.Validated;
  9 +import org.springframework.web.bind.annotation.GetMapping;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RestController;
  12 +
  13 +import java.util.ArrayList;
  14 +import java.util.List;
  15 +
  16 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  17 +
  18 +@Tag(name = "用户 APP - 钱包充值套餐")
  19 +@RestController
  20 +@RequestMapping("/pay/wallet-recharge-package")
  21 +@Validated
  22 +@Slf4j
  23 +public class AppPayWalletRechargePackageController {
  24 +
  25 + @GetMapping("/list")
  26 + @Operation(summary = "获得钱包充值套餐列表")
  27 + public CommonResult<List<AppPayWalletPackageRespVO>> getWalletRechargePackageList() {
  28 + // 只查询开启;需要按照 payPrice 排序;
  29 + List<AppPayWalletPackageRespVO> list = new ArrayList<>();
  30 + list.add(new AppPayWalletPackageRespVO().setId(1L).setName("土豆").setPayPrice(10).setBonusPrice(2));
  31 + list.add(new AppPayWalletPackageRespVO().setId(2L).setName("番茄").setPayPrice(20).setBonusPrice(5));
  32 + return success(list);
  33 + }
  34 +
  35 +}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletPackageRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +@Schema(description = "用户 APP - 用户充值套餐 Response VO")
  7 +@Data
  8 +public class AppPayWalletPackageRespVO {
  9 +
  10 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  11 + private Long id;
  12 + @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "小套餐")
  13 + private String name;
  14 +
  15 + @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  16 + private Integer payPrice;
  17 + @Schema(description = "赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
  18 + private Integer bonusPrice;
  19 +
  20 +}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java
@@ -3,24 +3,27 @@ package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge; @@ -3,24 +3,27 @@ package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge;
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 import lombok.Data; 4 import lombok.Data;
5 5
6 -import javax.validation.constraints.DecimalMin;  
7 import javax.validation.constraints.Min; 6 import javax.validation.constraints.Min;
8 -import javax.validation.constraints.NotNull;  
9 7
10 @Schema(description = "用户 APP - 创建钱包充值 Request VO") 8 @Schema(description = "用户 APP - 创建钱包充值 Request VO")
11 @Data 9 @Data
12 public class AppPayWalletRechargeCreateReqVO { 10 public class AppPayWalletRechargeCreateReqVO {
13 11
14 @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") 12 @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
15 - @NotNull(message = "支付金额不能为空") 13 +// @NotNull(message = "支付金额不能为空")
16 @Min(value = 1, message = "支付金额必须大于零") 14 @Min(value = 1, message = "支付金额必须大于零")
17 private Integer payPrice; 15 private Integer payPrice;
18 16
19 // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 17 // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。
20 // TOTO 那是不是搞一个充值模板 18 // TOTO 那是不是搞一个充值模板
21 @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") 19 @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
22 - @NotNull(message = "钱包赠送金额不能为空")  
23 - @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零")  
24 - private Integer bonusPrice; 20 +// @NotNull(message = "钱包赠送金额不能为空")
  21 +// @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零")
  22 + private Integer bonusPrice = 0;
  23 +
  24 + @Schema(description = "充值套餐编号", example = "1024")
  25 + private Long packageId;
  26 +
  27 + // TODO @jason:可以改成 payPrice 和 packageId 两个至少一个不为空;
25 28
26 } 29 }
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/wallet/AppPayWalletRespVO.java
@@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet; @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet;
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 import lombok.Data; 4 import lombok.Data;
5 5
6 -@Schema(description = "用户 APP - 获取用户钱包 Response VO") 6 +@Schema(description = "用户 APP - 用户钱包 Response VO")
7 @Data 7 @Data
8 public class AppPayWalletRespVO { 8 public class AppPayWalletRespVO {
9 9
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java
@@ -47,6 +47,7 @@ public class PayWalletRechargeDO extends BaseDO { @@ -47,6 +47,7 @@ public class PayWalletRechargeDO extends BaseDO {
47 * 钱包赠送金额 47 * 钱包赠送金额
48 */ 48 */
49 private Integer bonusPrice; 49 private Integer bonusPrice;
  50 + // TODO @jason:如果有赠送金额,需要关联下 PayWalletPackageDO 的 id 字段
50 51
51 /** 52 /**
52 * 是否已支付 53 * 是否已支付
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargePackageDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.dal.dataobject.wallet;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.KeySequence;
  4 +import com.baomidou.mybatisplus.annotation.TableId;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import lombok.Data;
  7 +
  8 +/**
  9 + * 会员钱包充值套餐 DO
  10 + *
  11 + * 通过套餐充值时,可以赠送一定金额;
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@TableName(value ="pay_wallet_recharge_package")
  16 +@KeySequence("pay_wallet_recharge_package_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  17 +@Data
  18 +public class PayWalletRechargePackageDO {
  19 +
  20 + /**
  21 + * 编号
  22 + */
  23 + @TableId
  24 + private Long id;
  25 + /**
  26 + * 套餐名
  27 + */
  28 + private String name;
  29 +
  30 + /**
  31 + * 支付金额
  32 + */
  33 + private Integer payPrice;
  34 + /**
  35 + * 赠送金额
  36 + */
  37 + private Integer bonusPrice;
  38 +
  39 + /**
  40 + * 状态
  41 + *
  42 + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
  43 + */
  44 + private Integer status;
  45 +
  46 +}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
@@ -40,6 +40,7 @@ import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*; @@ -40,6 +40,7 @@ import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*;
40 @Service 40 @Service
41 @Slf4j 41 @Slf4j
42 public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { 42 public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
  43 +
43 /** 44 /**
44 * TODO 放到 配置文件中 45 * TODO 放到 配置文件中
45 */ 46 */