mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-30 18:16:57 +08:00 
			
		
		
		
	新增获得支付钱包接口
This commit is contained in:
		
							
								
								
									
										44
									
								
								sql/mysql/pay_wallet.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								sql/mysql/pay_wallet.sql
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | ||||
| -- ---------------------------- | ||||
| -- 支付-钱包表 | ||||
| -- ---------------------------- | ||||
| DROP TABLE IF EXISTS `pay_wallet`; | ||||
| CREATE TABLE `pay_wallet` | ||||
| ( | ||||
|     `id`             bigint   NOT NULL AUTO_INCREMENT COMMENT '编号', | ||||
|     `user_id`        bigint   NOT NULL COMMENT '用户 id', | ||||
|     `user_type`      tinyint  NOT NULL DEFAULT 0 COMMENT '用户类型', | ||||
|     `balance`        int      NOT NULL DEFAULT 0 COMMENT '余额, 单位分', | ||||
|     `total_expense`  bigint      NOT NULL DEFAULT 0 COMMENT '累计支出, 单位分', | ||||
|     `total_recharge` bigint      NOT NULL DEFAULT 0 COMMENT '累计充值, 单位分', | ||||
|     `creator`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', | ||||
|     `create_time`    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||||
|     `updater`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', | ||||
|     `update_time`    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||||
|     `deleted`        bit(1)   NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||||
|     `tenant_id`      bigint   NOT NULL DEFAULT 0 COMMENT '租户编号', | ||||
|     PRIMARY KEY (`id`) USING BTREE | ||||
| ) ENGINE=InnoDB COMMENT='支付钱包表'; | ||||
|  | ||||
| -- ---------------------------- | ||||
| -- 支付- 钱包余额明细表 | ||||
| -- ---------------------------- | ||||
| DROP TABLE IF EXISTS `pay_wallet_transaction`; | ||||
| CREATE TABLE `pay_wallet_transaction` | ||||
| ( | ||||
|     `id`               bigint      NOT NULL AUTO_INCREMENT COMMENT '编号', | ||||
|     `wallet_id`        bigint      NOT NULL COMMENT '会员钱包 id', | ||||
|     `user_id`          bigint      NOT NULL COMMENT '用户 id', | ||||
|     `biz_type`         tinyint     NOT NULL COMMENT '关联类型', | ||||
|     `biz_id`           bigint      NOT NULL COMMENT '关联业务编号', | ||||
|     `no`               varchar(64) NOT NULL COMMENT '流水号', | ||||
|     `description`      varchar(255)         COMMENT '操作说明', | ||||
|     `amount`           int         NOT NULL COMMENT '交易金额, 单位分', | ||||
|     `balance`          int         NOT NULL COMMENT '余额, 单位分', | ||||
|     `transaction_time` datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间', | ||||
|     `create_time`      datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||||
|     `updater`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', | ||||
|     `update_time`      datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||||
|     `deleted`          bit(1)      NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||||
|     `tenant_id`        bigint      NOT NULL DEFAULT 0 COMMENT '租户编号', | ||||
|     PRIMARY KEY (`id`) USING BTREE | ||||
| ) ENGINE=InnoDB COMMENT='支付钱包余额明细表'; | ||||
| @ -4,20 +4,21 @@ import lombok.AllArgsConstructor; | ||||
| import lombok.Getter; | ||||
| 
 | ||||
| /** | ||||
|  * 钱包交易大类枚举 | ||||
|  * 钱包交易业务分类 | ||||
|  * | ||||
|  * @author jason | ||||
|  */ | ||||
| @AllArgsConstructor | ||||
| @Getter | ||||
| public enum WalletTransactionGategoryEnum { | ||||
|     TOP_UP(1, "充值"), | ||||
|     SPENDING(2, "支出"); | ||||
| public enum WalletBizTypeEnum { | ||||
|     RECHARGE(1, "充值"), | ||||
|     RECHARGE_REFUND(2, "充值退款"); | ||||
| 
 | ||||
|     // TODO 后续增加 | ||||
|     /** | ||||
|      * 分类 | ||||
|      * 业务分类 | ||||
|      */ | ||||
|     private final Integer category; | ||||
|     private final Integer bizType; | ||||
| 
 | ||||
|     /** | ||||
|      * 说明 | ||||
| @ -4,16 +4,15 @@ import lombok.AllArgsConstructor; | ||||
| import lombok.Getter; | ||||
| 
 | ||||
| /** | ||||
|  * 钱包操作类型枚举 | ||||
|  * 钱包交易大分类 | ||||
|  * | ||||
|  * @author jason | ||||
|  */ | ||||
| @AllArgsConstructor | ||||
| @Getter | ||||
| public enum WalletOperateTypeEnum { | ||||
|     TOP_UP_INC(1, "充值增加"), | ||||
|     ORDER_DEC(2, "订单消费扣除"); | ||||
|     // TODO 其它类型 | ||||
| public enum WalletTypeEnum { | ||||
|     RECHARGE(1, "充值"), | ||||
|     EXPENSE(2, "消费"); | ||||
| 
 | ||||
|     private final Integer type; | ||||
| 
 | ||||
| @ -0,0 +1,41 @@ | ||||
| package cn.iocoder.yudao.module.pay.controller.app.wallet; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletRespVO; | ||||
| import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert; | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; | ||||
| import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||
| import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||||
|  | ||||
| /** | ||||
|  * @author jason | ||||
|  */ | ||||
| @Tag(name = "用户 APP - 支付钱包") | ||||
| @RestController | ||||
| @RequestMapping("/pay/wallet") | ||||
| @Validated | ||||
| @Slf4j | ||||
| public class AppPayWalletController { | ||||
|  | ||||
|     @Resource | ||||
|     private PayWalletService payWalletService; | ||||
|  | ||||
|     @GetMapping("/get") | ||||
|     @Operation(summary = "获取支付钱包") | ||||
|     public CommonResult<AppPayWalletRespVO> getPayWallet() { | ||||
|         PayWalletDO payWallet = payWalletService.getPayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); | ||||
|         return success(PayWalletConvert.INSTANCE.convert(payWallet)); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,21 @@ | ||||
| package cn.iocoder.yudao.module.pay.controller.app.wallet.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.Data; | ||||
|  | ||||
| /** | ||||
|  * @author jason | ||||
|  */ | ||||
| @Schema(description = "用户 APP - 获取用户钱包 Response VO") | ||||
| @Data | ||||
| public class AppPayWalletRespVO { | ||||
|  | ||||
|     @Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | ||||
|     private Integer balance; | ||||
|  | ||||
|     @Schema(description = "累计支出, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | ||||
|     private Long totalExpense; | ||||
|  | ||||
|     @Schema(description = "累计充值, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") | ||||
|     private Long totalRecharge; | ||||
| } | ||||
| @ -0,0 +1,14 @@ | ||||
| package cn.iocoder.yudao.module.pay.convert.wallet; | ||||
|  | ||||
| import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletRespVO; | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.factory.Mappers; | ||||
|  | ||||
| @Mapper | ||||
| public interface PayWalletConvert { | ||||
|  | ||||
|     PayWalletConvert INSTANCE = Mappers.getMapper(PayWalletConvert.class); | ||||
|  | ||||
|     AppPayWalletRespVO convert(PayWalletDO bean); | ||||
| } | ||||
| @ -1,86 +0,0 @@ | ||||
| package cn.iocoder.yudao.module.pay.dal.dataobject.member; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import cn.iocoder.yudao.module.pay.enums.member.WalletOperateTypeEnum; | ||||
| import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionGategoryEnum; | ||||
| import com.baomidou.mybatisplus.annotation.KeySequence; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| /** | ||||
|  * 支付-会员钱包明细 DO | ||||
|  * | ||||
|  * @author jason | ||||
|  */ | ||||
| @TableName(value ="pay_member_wallet_transaction") | ||||
| @KeySequence("pay_member_wallet_transaction_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||||
| @Data | ||||
| public class MemberWalletTransactionDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 编号 | ||||
|      */ | ||||
|     @TableId | ||||
|     private Long id; | ||||
|  | ||||
|     /** | ||||
|      * 会员钱包 id | ||||
|      * | ||||
|      * 关联 {@link MemberWalletDO#getId()} | ||||
|      */ | ||||
|     private Long walletId; | ||||
|  | ||||
|     /** | ||||
|      * 用户 id | ||||
|      * | ||||
|      * 关联 MemberUserDO 的 id 编号 | ||||
|      */ | ||||
|     private Long userId; | ||||
|  | ||||
|     /** | ||||
|      * 交易单号  @芋艿 这里是关联交易单号, 还是订单号 , 退款单号!  ?? | ||||
|      */ | ||||
|     private String tradeNo; | ||||
|  | ||||
|     /** | ||||
|      * 交易分类 | ||||
|      * | ||||
|      * 枚举 {@link WalletTransactionGategoryEnum#getCategory()} | ||||
|      */ | ||||
|     private Integer category; | ||||
|  | ||||
|     /** | ||||
|      * 操作分类 | ||||
|      * | ||||
|      * 枚举 {@link WalletOperateTypeEnum#getType()} | ||||
|      */ | ||||
|     private Integer operateType; | ||||
|  | ||||
|     /** | ||||
|      * 操作详情 | ||||
|      */ | ||||
|     private String operateDesc; | ||||
|  | ||||
|     /** | ||||
|      * 交易金额, 单位分 | ||||
|      */ | ||||
|     private Integer price; | ||||
|  | ||||
|     /** | ||||
|      * 余额, 单位分 | ||||
|      */ | ||||
|     private Integer balance; | ||||
|  | ||||
|     /** | ||||
|      * 备注 | ||||
|      */ | ||||
|     private String mark; | ||||
|  | ||||
|     /** | ||||
|      * 交易时间 | ||||
|      */ | ||||
|     private LocalDateTime transactionTime; | ||||
| } | ||||
| @ -1,21 +1,21 @@ | ||||
| package cn.iocoder.yudao.module.pay.dal.dataobject.member; | ||||
| package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import com.baomidou.mybatisplus.annotation.KeySequence; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.Data; | ||||
| 
 | ||||
| // TODO @jason:修改 MemberWalletDO 为 PayWalletDO | ||||
| /** | ||||
|  * 支付 - 会员钱包 DO | ||||
|  * | ||||
|  * @author jason | ||||
|  */ | ||||
| @TableName(value ="pay_member_wallet") | ||||
| @KeySequence("pay_member_wallet_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||||
| @TableName(value ="pay_wallet") | ||||
| @KeySequence("pay_wallet_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||||
| @Data | ||||
| public class MemberWalletDO extends BaseDO { | ||||
| public class PayWalletDO extends BaseDO { | ||||
| 
 | ||||
|     /** | ||||
|      * 编号 | ||||
| @ -23,7 +23,6 @@ public class MemberWalletDO extends BaseDO { | ||||
|     @TableId | ||||
|     private Long id; | ||||
| 
 | ||||
|     // TODO @jaosn:增加 userType 字段; | ||||
|     /** | ||||
|      * 用户 id | ||||
|      * | ||||
| @ -32,6 +31,13 @@ public class MemberWalletDO extends BaseDO { | ||||
|      */ | ||||
|     private Long userId; | ||||
| 
 | ||||
|     /** | ||||
|      * 用户类型, 预留 多商户转帐可能需要用到 | ||||
|      * | ||||
|      * 关联 {@link UserTypeEnum} | ||||
|      */ | ||||
|     private Integer userType; | ||||
| 
 | ||||
|     /** | ||||
|      * 余额, 单位分 | ||||
|      */ | ||||
| @ -40,10 +46,10 @@ public class MemberWalletDO extends BaseDO { | ||||
|     /** | ||||
|      * 累计支出, 单位分 | ||||
|      */ | ||||
|     private Integer totalSpending; | ||||
|     private Long totalExpense; | ||||
| 
 | ||||
|     /** | ||||
|      * 累计充值, 单位分 | ||||
|      */ | ||||
|     private Integer totalTopUp; | ||||
|     private Long totalRecharge; | ||||
| } | ||||
| @ -0,0 +1,79 @@ | ||||
| package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import cn.iocoder.yudao.module.pay.enums.member.WalletBizTypeEnum; | ||||
| import com.baomidou.mybatisplus.annotation.KeySequence; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| /** | ||||
|  * 支付-会员钱包明细 DO | ||||
|  * | ||||
|  * @author jason | ||||
|  */ | ||||
| @TableName(value ="pay_wallet_transaction") | ||||
| @KeySequence("pay_wallet_transaction_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||||
| @Data | ||||
| public class PayWalletTransactionDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 编号 | ||||
|      */ | ||||
|     @TableId | ||||
|     private Long id; | ||||
|  | ||||
|     /** | ||||
|      * 会员钱包 id | ||||
|      * | ||||
|      * 关联 {@link PayWalletDO#getId()} | ||||
|      */ | ||||
|     private Long walletId; | ||||
|  | ||||
|     /** | ||||
|      * 用户 id | ||||
|      * | ||||
|      * 关联 MemberUserDO 的 id 编号 | ||||
|      */ | ||||
|     private Long userId; | ||||
|  | ||||
|     /** | ||||
|      * 关联业务 | ||||
|      * | ||||
|      * 枚举 {@link WalletBizTypeEnum#getBizType()} | ||||
|      */ | ||||
|     private Integer bizType; | ||||
|  | ||||
|     /** | ||||
|      * 关联业务编号 | ||||
|      */ | ||||
|     private Long bizId; | ||||
|  | ||||
|     /** | ||||
|      * 流水号 | ||||
|      */ | ||||
|     private String no; | ||||
|  | ||||
|     /** | ||||
|      * 附加说明 | ||||
|      */ | ||||
|     private String description; | ||||
|  | ||||
|     /** | ||||
|      * 交易金额, 单位分 | ||||
|      * 正值表示余额增加,负值表示余额减少 | ||||
|      */ | ||||
|     private Integer amount; | ||||
|  | ||||
|     /** | ||||
|      * 交易后余额,单位分 | ||||
|      */ | ||||
|     private Integer balance; | ||||
|  | ||||
|     /** | ||||
|      * 交易时间 | ||||
|      */ | ||||
|     private LocalDateTime transactionTime; | ||||
| } | ||||
| @ -1,15 +0,0 @@ | ||||
| package cn.iocoder.yudao.module.pay.dal.mysql.member; | ||||
|  | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.member.MemberWalletDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| @Mapper | ||||
| public interface MemberWalletMapper extends BaseMapperX<MemberWalletDO> { | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -1,15 +0,0 @@ | ||||
| package cn.iocoder.yudao.module.pay.dal.mysql.member; | ||||
|  | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.member.MemberWalletTransactionDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| @Mapper | ||||
| public interface MemberWalletTransactionMapper extends BaseMapperX<MemberWalletTransactionDO> { | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -0,0 +1,18 @@ | ||||
| package cn.iocoder.yudao.module.pay.dal.mysql.wallet; | ||||
|  | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| @Mapper | ||||
| public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | ||||
|  | ||||
|     default PayWalletDO selectByUserIdAndType(Long userId, Integer userType) { | ||||
|         return selectOne(PayWalletDO::getUserId, userId, PayWalletDO::getUserType, userType); | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -0,0 +1,15 @@ | ||||
| package cn.iocoder.yudao.module.pay.dal.mysql.wallet; | ||||
|  | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| @Mapper | ||||
| public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> { | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -0,0 +1,18 @@ | ||||
| package cn.iocoder.yudao.module.pay.service.wallet; | ||||
|  | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; | ||||
|  | ||||
| /** | ||||
|  * 支付钱包 Service 接口 | ||||
|  * | ||||
|  * @author jason | ||||
|  */ | ||||
| public interface PayWalletService { | ||||
|  | ||||
|     /** | ||||
|      * 得到用户的支付钱包 | ||||
|      * @param userId 用户 id | ||||
|      * @param userType 用户类型 | ||||
|      */ | ||||
|     PayWalletDO getPayWallet(Long userId, Integer userType); | ||||
| } | ||||
| @ -0,0 +1,24 @@ | ||||
| package cn.iocoder.yudao.module.pay.service.wallet; | ||||
|  | ||||
| import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; | ||||
| import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
|  | ||||
| /** | ||||
|  * 支付钱包 Service 实现类 | ||||
|  * | ||||
|  * @author jason | ||||
|  */ | ||||
| @Service | ||||
| public class PayWalletServiceImpl implements  PayWalletService { | ||||
|  | ||||
|     @Resource | ||||
|     private PayWalletMapper payWalletMapper; | ||||
|  | ||||
|     @Override | ||||
|     public PayWalletDO getPayWallet(Long userId, Integer userType) { | ||||
|         return payWalletMapper.selectByUserIdAndType(userId, userType); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 jason
					jason