mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
新增查询钱包余额明细接口
This commit is contained in:
parent
1ffbd9399e
commit
f33b66558c
@ -27,7 +27,6 @@ CREATE TABLE `pay_wallet_transaction`
|
|||||||
(
|
(
|
||||||
`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',
|
||||||
`user_id` bigint NOT NULL COMMENT '用户 id',
|
|
||||||
`biz_type` tinyint NOT NULL COMMENT '关联类型',
|
`biz_type` tinyint NOT NULL COMMENT '关联类型',
|
||||||
`biz_id` bigint NOT NULL COMMENT '关联业务编号',
|
`biz_id` bigint NOT NULL COMMENT '关联业务编号',
|
||||||
`no` varchar(64) NOT NULL COMMENT '流水号',
|
`no` varchar(64) NOT NULL COMMENT '流水号',
|
||||||
@ -35,6 +34,7 @@ CREATE TABLE `pay_wallet_transaction`
|
|||||||
`amount` int NOT NULL COMMENT '交易金额, 单位分',
|
`amount` int NOT NULL COMMENT '交易金额, 单位分',
|
||||||
`balance` int NOT NULL COMMENT '余额, 单位分',
|
`balance` int NOT NULL COMMENT '余额, 单位分',
|
||||||
`transaction_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间',
|
`transaction_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP 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 '创建时间',
|
||||||
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' 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 '更新时间',
|
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
@ -41,6 +41,9 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode REFUND_NOT_FOUND = new ErrorCode(1007006004, "支付退款单不存在");
|
ErrorCode REFUND_NOT_FOUND = new ErrorCode(1007006004, "支付退款单不存在");
|
||||||
ErrorCode REFUND_STATUS_IS_NOT_WAITING = new ErrorCode(1007006005, "支付退款单不处于待退款");
|
ErrorCode REFUND_STATUS_IS_NOT_WAITING = new ErrorCode(1007006005, "支付退款单不处于待退款");
|
||||||
|
|
||||||
|
// ========== 钱包模块(退款) 1007007000 ==========
|
||||||
|
ErrorCode WALLET_NOT_FOUND = new ErrorCode(1007007000, "用户钱包不存在");
|
||||||
|
|
||||||
// ========== 示例订单 1007900000 ==========
|
// ========== 示例订单 1007900000 ==========
|
||||||
ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在");
|
ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在");
|
||||||
ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007900001, "示例订单更新支付状态失败,订单不是【未支付】状态");
|
ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007900001, "示例订单更新支付状态失败,订单不是【未支付】状态");
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package cn.iocoder.yudao.module.pay.enums.member;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 钱包明细查询类型
|
||||||
|
*
|
||||||
|
* @author jason
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum WalletTransactionQueryTypeEnum implements IntArrayValuable {
|
||||||
|
RECHARGE(1, "充值"),
|
||||||
|
EXPENSE(2, "消费");
|
||||||
|
|
||||||
|
private final Integer type;
|
||||||
|
|
||||||
|
private final String desc;
|
||||||
|
|
||||||
|
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(WalletTransactionQueryTypeEnum::getType).toArray();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] array() {
|
||||||
|
return ARRAYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WalletTransactionQueryTypeEnum valueOf(Integer type) {
|
||||||
|
return ArrayUtil.firstMatch(o -> o.getType().equals(type), values());
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.pay.enums.member;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 钱包交易大分类
|
|
||||||
*
|
|
||||||
* @author jason
|
|
||||||
*/
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public enum WalletTypeEnum {
|
|
||||||
RECHARGE(1, "充值"),
|
|
||||||
EXPENSE(2, "消费");
|
|
||||||
|
|
||||||
private final Integer type;
|
|
||||||
|
|
||||||
private final String desc;
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
|||||||
/**
|
/**
|
||||||
* @author jason
|
* @author jason
|
||||||
*/
|
*/
|
||||||
@Tag(name = "用户 APP - 支付钱包")
|
@Tag(name = "用户 APP - 钱包")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/pay/wallet")
|
@RequestMapping("/pay/wallet")
|
||||||
@Validated
|
@Validated
|
||||||
@ -33,7 +33,7 @@ public class AppPayWalletController {
|
|||||||
private PayWalletService payWalletService;
|
private PayWalletService payWalletService;
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "获取支付钱包")
|
@Operation(summary = "获取钱包")
|
||||||
public CommonResult<AppPayWalletRespVO> getPayWallet() {
|
public CommonResult<AppPayWalletRespVO> getPayWallet() {
|
||||||
PayWalletDO payWallet = payWalletService.getPayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue());
|
PayWalletDO payWallet = payWalletService.getPayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue());
|
||||||
return success(PayWalletConvert.INSTANCE.convert(payWallet));
|
return success(PayWalletConvert.INSTANCE.convert(payWallet));
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
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.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionRespVO;
|
||||||
|
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert;
|
||||||
|
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||||
|
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService;
|
||||||
|
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 javax.validation.Valid;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
|
@Tag(name = "用户 APP - 钱包余额明细")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/pay/wallet-transaction")
|
||||||
|
@Validated
|
||||||
|
@Slf4j
|
||||||
|
public class AppPayWalletTransactionController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PayWalletTransactionService payWalletTransactionService;
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得钱包余额明细分页")
|
||||||
|
public CommonResult<PageResult<AppPayWalletTransactionRespVO>> pageWalletTransaction(
|
||||||
|
@Valid AppPayWalletTransactionPageReqVO pageVO) {
|
||||||
|
PageResult<PayWalletTransactionDO> result = payWalletTransactionService.getWalletTransactionPage(getLoginUserId(),
|
||||||
|
UserTypeEnum.MEMBER.getValue(), pageVO);
|
||||||
|
return success(PayWalletTransactionConvert.INSTANCE.convertPage(result));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||||
|
import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "用户 APP - 钱包余额明细分页 Request VO")
|
||||||
|
@Data
|
||||||
|
public class AppPayWalletTransactionPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "余额明细查询分类", example = "1")
|
||||||
|
@InEnum(value = WalletTransactionQueryTypeEnum.class, message = "查询类型必须是 {value}")
|
||||||
|
private Integer type;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "用户 APP - 钱包余额明细分页 Response VO")
|
||||||
|
@Data
|
||||||
|
public class AppPayWalletTransactionRespVO {
|
||||||
|
@Schema(description = "交易金额, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||||
|
private Integer amount;
|
||||||
|
|
||||||
|
@Schema(description = "业务分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Integer bizType;
|
||||||
|
|
||||||
|
@Schema(description = "交易时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||||
|
private LocalDateTime transactionTime;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package cn.iocoder.yudao.module.pay.convert.wallet;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionRespVO;
|
||||||
|
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface PayWalletTransactionConvert {
|
||||||
|
|
||||||
|
PayWalletTransactionConvert INSTANCE = Mappers.getMapper(PayWalletTransactionConvert.class);
|
||||||
|
|
||||||
|
PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page);
|
||||||
|
}
|
@ -27,22 +27,13 @@ public class PayWalletTransactionDO extends BaseDO {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员钱包 id
|
* 会员钱包 id
|
||||||
*
|
|
||||||
* 关联 {@link PayWalletDO#getId()}
|
* 关联 {@link PayWalletDO#getId()}
|
||||||
*/
|
*/
|
||||||
private Long walletId;
|
private Long walletId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户 id
|
* 钱包交易业务分类
|
||||||
*
|
* 关联枚举 {@link WalletBizTypeEnum#getBizType()}
|
||||||
* 关联 MemberUserDO 的 id 编号
|
|
||||||
*/
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关联业务
|
|
||||||
*
|
|
||||||
* 枚举 {@link WalletBizTypeEnum#getBizType()}
|
|
||||||
*/
|
*/
|
||||||
private Integer bizType;
|
private Integer bizType;
|
||||||
|
|
||||||
|
@ -1,13 +1,31 @@
|
|||||||
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
|
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||||
|
import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> {
|
public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> {
|
||||||
|
|
||||||
|
default PageResult<PayWalletTransactionDO> selectPageByWalletIdAndQueryType(Long walletId,
|
||||||
|
WalletTransactionQueryTypeEnum queryType,
|
||||||
|
PageParam pageParam) {
|
||||||
|
LambdaQueryWrapperX<PayWalletTransactionDO> query = new LambdaQueryWrapperX<PayWalletTransactionDO>()
|
||||||
|
.eq(PayWalletTransactionDO::getWalletId, walletId);
|
||||||
|
if (WalletTransactionQueryTypeEnum.RECHARGE == queryType ) {
|
||||||
|
query.ge(PayWalletTransactionDO::getAmount, 0);
|
||||||
|
}
|
||||||
|
if (WalletTransactionQueryTypeEnum.EXPENSE == queryType ) {
|
||||||
|
query.lt(PayWalletTransactionDO::getAmount, 0);
|
||||||
|
}
|
||||||
|
query.orderByDesc(PayWalletTransactionDO::getTransactionTime);
|
||||||
|
return selectPage(pageParam, query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,14 +3,14 @@ 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.dataobject.wallet.PayWalletDO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付钱包 Service 接口
|
* 钱包 Service 接口
|
||||||
*
|
*
|
||||||
* @author jason
|
* @author jason
|
||||||
*/
|
*/
|
||||||
public interface PayWalletService {
|
public interface PayWalletService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到用户的支付钱包
|
* 获取钱包信息
|
||||||
* @param userId 用户 id
|
* @param userId 用户 id
|
||||||
* @param userType 用户类型
|
* @param userType 用户类型
|
||||||
*/
|
*/
|
||||||
|
@ -7,7 +7,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付钱包 Service 实现类
|
* 钱包 Service 实现类
|
||||||
*
|
*
|
||||||
* @author jason
|
* @author jason
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package cn.iocoder.yudao.module.pay.service.wallet;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 钱包余额明细 Service 接口
|
||||||
|
*
|
||||||
|
* @author jason
|
||||||
|
*/
|
||||||
|
public interface PayWalletTransactionService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询钱包余额明细, 分页
|
||||||
|
*
|
||||||
|
* @param userId 用户 id
|
||||||
|
* @param userType 用户类型
|
||||||
|
* @param pageVO 分页查询参数
|
||||||
|
*/
|
||||||
|
PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType,
|
||||||
|
AppPayWalletTransactionPageReqVO pageVO);
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package cn.iocoder.yudao.module.pay.service.wallet;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
|
||||||
|
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||||
|
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletTransactionMapper;
|
||||||
|
import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 钱包余额明细 Service 实现类
|
||||||
|
*
|
||||||
|
* @author jason
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class PayWalletTransactionServiceImpl implements PayWalletTransactionService{
|
||||||
|
@Resource
|
||||||
|
private PayWalletService payWalletService;
|
||||||
|
@Resource
|
||||||
|
private PayWalletTransactionMapper payWalletTransactionMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType,
|
||||||
|
AppPayWalletTransactionPageReqVO pageVO) {
|
||||||
|
PayWalletDO payWallet = payWalletService.getPayWallet(userId, userType);
|
||||||
|
if (payWallet == null) {
|
||||||
|
log.error("[pageWalletTransaction] 用户 {} 钱包不存在", userId);
|
||||||
|
throw exception(WALLET_NOT_FOUND);
|
||||||
|
}
|
||||||
|
return payWalletTransactionMapper.selectPageByWalletIdAndQueryType(payWallet.getId(),
|
||||||
|
WalletTransactionQueryTypeEnum.valueOf(pageVO.getType()), pageVO);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user