wallet - 充值套餐 管理端

This commit is contained in:
jason 2023-10-13 10:43:04 +08:00
parent 2e207019b3
commit 8cd7941fc3
12 changed files with 371 additions and 7 deletions

View File

@ -63,6 +63,7 @@ public interface ErrorCodeConstants {
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH = new ErrorCode(1_007_008_010, "钱包退款更新失败,退款单金额不匹配");
ErrorCode WALLET_RECHARGE_PACKAGE_AND_PRICE_IS_EMPTY = new ErrorCode(1_007_008_011, "充值金额和充钱套餐不能同时为空");
ErrorCode WALLET_RECHARGE_PACKAGE_NOT_FOUND = new ErrorCode(1_007_008_012, "钱包充值套餐不存在");
ErrorCode WALLET_RECHARGE_PACKAGE_IS_DISABLE = new ErrorCode(1_007_008_013, "钱包充值套餐已禁用");
// ========== 转账模块 1-007-009-000 ==========
ErrorCode PAY_TRANSFER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_009_000, "发起转账报错,错误码:{},错误提示:{}");
ErrorCode PAY_TRANSFER_ALIPAY_LOGIN_ID_IS_EMPTY = new ErrorCode(1_007_009_001, "支付宝登录 ID 不能为空");

View File

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageCreateReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageRespVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageUpdateReqVO;
import cn.iocoder.yudao.module.pay.convert.wallet.WalletRechargePackageConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargePackageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 钱包充值套餐")
@RestController
@RequestMapping("/pay/wallet-recharge-package")
@Validated
public class PayWalletRechargePackageController {
@Resource
private PayWalletRechargePackageService walletRechargePackageService;
@PostMapping("/create")
@Operation(summary = "创建钱包充值套餐")
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:create')")
public CommonResult<Long> createWalletRechargePackage(@Valid @RequestBody WalletRechargePackageCreateReqVO createReqVO) {
return success(walletRechargePackageService.createWalletRechargePackage(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新钱包充值套餐")
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:update')")
public CommonResult<Boolean> updateWalletRechargePackage(@Valid @RequestBody WalletRechargePackageUpdateReqVO updateReqVO) {
walletRechargePackageService.updateWalletRechargePackage(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除钱包充值套餐")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:delete')")
public CommonResult<Boolean> deleteWalletRechargePackage(@RequestParam("id") Long id) {
walletRechargePackageService.deleteWalletRechargePackage(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得钱包充值套餐")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:query')")
public CommonResult<WalletRechargePackageRespVO> getWalletRechargePackage(@RequestParam("id") Long id) {
PayWalletRechargePackageDO walletRechargePackage = walletRechargePackageService.getWalletRechargePackage(id);
return success(WalletRechargePackageConvert.INSTANCE.convert(walletRechargePackage));
}
@GetMapping("/page")
@Operation(summary = "获得钱包充值套餐分页")
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:query')")
public CommonResult<PageResult<WalletRechargePackageRespVO>> getWalletRechargePackagePage(@Valid WalletRechargePackagePageReqVO pageVO) {
PageResult<PayWalletRechargePackageDO> pageResult = walletRechargePackageService.getWalletRechargePackagePage(pageVO);
return success(WalletRechargePackageConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 套餐充值 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class WalletRechargePackageBaseVO {
@Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@NotNull(message = "套餐名不能为空")
private String name;
@Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "16454")
@NotNull(message = "支付金额不能为空")
private Integer payPrice;
@Schema(description = "赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20887")
@NotNull(message = "赠送金额不能为空")
private Integer bonusPrice;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "状态不能为空")
private Byte status;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 套餐充值创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WalletRechargePackageCreateReqVO extends WalletRechargePackageBaseVO {
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 套餐充值分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WalletRechargePackagePageReqVO extends PageParam {
@Schema(description = "套餐名", example = "李四")
private String name;
@Schema(description = "支付金额", example = "16454")
private Integer payPrice;
@Schema(description = "赠送金额", example = "20887")
private Integer bonusPrice;
@Schema(description = "状态", example = "2")
private Integer status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 套餐充值 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WalletRechargePackageRespVO extends WalletRechargePackageBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9032")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 套餐充值更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WalletRechargePackageUpdateReqVO extends WalletRechargePackageBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9032")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.pay.convert.wallet;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageCreateReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageRespVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageUpdateReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* 套餐充值 Convert
*
* @author 芋道源码
*/
@Mapper
public interface WalletRechargePackageConvert {
WalletRechargePackageConvert INSTANCE = Mappers.getMapper(WalletRechargePackageConvert.class);
PayWalletRechargePackageDO convert(WalletRechargePackageCreateReqVO bean);
PayWalletRechargePackageDO convert(WalletRechargePackageUpdateReqVO bean);
WalletRechargePackageRespVO convert(PayWalletRechargePackageDO bean);
List<WalletRechargePackageRespVO> convertList(List<PayWalletRechargePackageDO> list);
PageResult<WalletRechargePackageRespVO> convertPage(PageResult<PayWalletRechargePackageDO> page);
}

View File

@ -1,13 +1,25 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PayWalletRechargePackageMapper extends BaseMapperX<PayWalletRechargePackageDO> {
default PageResult<PayWalletRechargePackageDO> selectPage(WalletRechargePackagePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<PayWalletRechargePackageDO>()
.likeIfPresent(PayWalletRechargePackageDO::getName, reqVO.getName())
.eqIfPresent(PayWalletRechargePackageDO::getPayPrice, reqVO.getPayPrice())
.eqIfPresent(PayWalletRechargePackageDO::getBonusPrice, reqVO.getBonusPrice())
.eqIfPresent(PayWalletRechargePackageDO::getStatus, reqVO.getStatus())
.betweenIfPresent(PayWalletRechargePackageDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(PayWalletRechargePackageDO::getId));
}
}

View File

@ -1,7 +1,15 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageCreateReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageUpdateReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* 钱包充值套餐 Service 接口
*
@ -14,4 +22,50 @@ public interface PayWalletRechargePackageService {
* @param packageId 充值套餐编号
*/
PayWalletRechargePackageDO getWalletRechargePackage(Long packageId);
/**
* 校验钱包充值套餐的有效性, 无效的话抛出 ServiceException 异常
*
* @param packageId 充值套餐编号
*/
PayWalletRechargePackageDO validWalletRechargePackage(Long packageId);
/**
* 创建套餐充值
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createWalletRechargePackage(@Valid WalletRechargePackageCreateReqVO createReqVO);
/**
* 更新套餐充值
*
* @param updateReqVO 更新信息
*/
void updateWalletRechargePackage(@Valid WalletRechargePackageUpdateReqVO updateReqVO);
/**
* 删除套餐充值
*
* @param id 编号
*/
void deleteWalletRechargePackage(Long id);
/**
* 获得套餐充值列表
*
* @param ids 编号
* @return 套餐充值列表
*/
List<PayWalletRechargePackageDO> getWalletRechargePackageList(Collection<Long> ids);
/**
* 获得套餐充值分页
*
* @param pageReqVO 分页查询
* @return 套餐充值分页
*/
PageResult<PayWalletRechargePackageDO> getWalletRechargePackagePage(WalletRechargePackagePageReqVO pageReqVO);
}

View File

@ -1,11 +1,25 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageCreateReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageUpdateReqVO;
import cn.iocoder.yudao.module.pay.convert.wallet.WalletRechargePackageConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargePackageMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
* 钱包充值套餐 Service 实现类
*
@ -15,10 +29,68 @@ import javax.annotation.Resource;
public class PayWalletRechargePackageServiceImpl implements PayWalletRechargePackageService {
@Resource
private PayWalletRechargePackageMapper rechargePackageMapper;
private PayWalletRechargePackageMapper walletRechargePackageMapper;
@Override
public PayWalletRechargePackageDO getWalletRechargePackage(Long packageId) {
return rechargePackageMapper.selectById(packageId);
return walletRechargePackageMapper.selectById(packageId);
}
@Override
public PayWalletRechargePackageDO validWalletRechargePackage(Long packageId) {
PayWalletRechargePackageDO rechargePackageDO = walletRechargePackageMapper.selectById(packageId);
if (rechargePackageDO == null) {
throw exception(WALLET_RECHARGE_PACKAGE_NOT_FOUND);
}
if (CommonStatusEnum.DISABLE.getStatus().equals(rechargePackageDO.getStatus())) {
throw exception(WALLET_RECHARGE_PACKAGE_IS_DISABLE);
}
return rechargePackageDO;
}
@Override
public Long createWalletRechargePackage(WalletRechargePackageCreateReqVO createReqVO) {
// 插入
PayWalletRechargePackageDO walletRechargePackage = WalletRechargePackageConvert.INSTANCE.convert(createReqVO);
walletRechargePackageMapper.insert(walletRechargePackage);
// 返回
return walletRechargePackage.getId();
}
@Override
public void updateWalletRechargePackage(WalletRechargePackageUpdateReqVO updateReqVO) {
// 校验存在
validateWalletRechargePackageExists(updateReqVO.getId());
// 更新
PayWalletRechargePackageDO updateObj = WalletRechargePackageConvert.INSTANCE.convert(updateReqVO);
walletRechargePackageMapper.updateById(updateObj);
}
@Override
public void deleteWalletRechargePackage(Long id) {
// 校验存在
validateWalletRechargePackageExists(id);
// 删除
walletRechargePackageMapper.deleteById(id);
}
private void validateWalletRechargePackageExists(Long id) {
if (walletRechargePackageMapper.selectById(id) == null) {
throw exception(WALLET_RECHARGE_PACKAGE_NOT_FOUND);
}
}
@Override
public List<PayWalletRechargePackageDO> getWalletRechargePackageList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return walletRechargePackageMapper.selectBatchIds(ids);
}
@Override
public PageResult<PayWalletRechargePackageDO> getWalletRechargePackagePage(WalletRechargePackagePageReqVO pageReqVO) {
return walletRechargePackageMapper.selectPage(pageReqVO);
}
}

View File

@ -52,7 +52,6 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
@Resource
private PayWalletRechargeMapper walletRechargeMapper;
@Resource
private PayWalletService payWalletService;
@Resource
@ -74,10 +73,7 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
int payPrice ;
int bonusPrice = 0 ;
if (Objects.nonNull(reqVO.getPackageId())) {
PayWalletRechargePackageDO rechargePackage = payWalletRechargePackageService.getWalletRechargePackage(reqVO.getPackageId());
if (rechargePackage == null) {
throw exception(WALLET_RECHARGE_PACKAGE_NOT_FOUND);
}
PayWalletRechargePackageDO rechargePackage = payWalletRechargePackageService.validWalletRechargePackage(reqVO.getPackageId());
payPrice = rechargePackage.getPayPrice();
bonusPrice = rechargePackage.getBonusPrice();
} else {