mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 07:11:52 +08:00
充值套餐修改
This commit is contained in:
parent
7b727d5ce2
commit
571961b4da
@ -76,3 +76,52 @@ CREATE TABLE `pay_demo_transfer` (
|
||||
ALTER TABLE `pay_channel`
|
||||
MODIFY COLUMN `config` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '支付渠道配置' AFTER `app_id`;
|
||||
|
||||
-- ----------------------------
|
||||
-- 套餐充值表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `pay_wallet_recharge_package`;
|
||||
CREATE TABLE `pay_wallet_recharge_package`
|
||||
(
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
|
||||
`name` varchar(64) NOT NULL COMMENT '套餐名',
|
||||
`pay_price` int NOT NULL COMMENT '支付金额',
|
||||
`bonus_price` int NOT NULL COMMENT '赠送金额',
|
||||
`status` tinyint NOT NULL COMMENT '状态',
|
||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin 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='套餐充值表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for pay_wallet_recharge
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `pay_wallet_recharge`;
|
||||
CREATE TABLE `pay_wallet_recharge` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '编号',
|
||||
`wallet_id` bigint(0) NOT NULL COMMENT '会员钱包 id',
|
||||
`total_price` int(0) NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120',
|
||||
`pay_price` int(0) NOT NULL COMMENT '实际支付金额',
|
||||
`bonus_price` int(0) NOT NULL COMMENT '钱包赠送金额',
|
||||
`package_id` bigint(0) DEFAULT NULL COMMENT '充值套餐编号',
|
||||
`pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]',
|
||||
`pay_order_id` bigint(0) DEFAULT NULL COMMENT '支付订单编号',
|
||||
`pay_channel_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '支付成功的支付渠道',
|
||||
`pay_time` datetime(0) DEFAULT NULL COMMENT '订单支付时间',
|
||||
`pay_refund_id` bigint(0) DEFAULT NULL COMMENT '支付退款单编号',
|
||||
`refund_total_price` int(0) NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额',
|
||||
`refund_pay_price` int(0) NOT NULL DEFAULT 0 COMMENT '退款支付金额',
|
||||
`refund_bonus_price` int(0) NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额',
|
||||
`refund_time` datetime(0) DEFAULT NULL COMMENT '退款时间',
|
||||
`refund_status` int(0) NOT NULL DEFAULT 0 COMMENT '退款状态',
|
||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
|
||||
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
|
||||
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
|
||||
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||
`tenant_id` bigint(0) NOT NULL DEFAULT 0 COMMENT '租户编号',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '会员钱包充值' ROW_FORMAT = Dynamic;
|
||||
|
@ -61,7 +61,8 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR = new ErrorCode(1_007_008_008, "钱包退款更新失败,钱包退款单编号不匹配");
|
||||
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND = new ErrorCode(1_007_008_009, "钱包退款更新失败,退款订单不存在");
|
||||
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, "钱包充值套餐不存在");
|
||||
// ========== 转账模块 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 不能为空");
|
||||
|
@ -9,21 +9,11 @@ import javax.validation.constraints.Min;
|
||||
@Data
|
||||
public class AppPayWalletRechargeCreateReqVO {
|
||||
|
||||
@Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
// @NotNull(message = "支付金额不能为空")
|
||||
@Schema(description = "支付金额", example = "1000")
|
||||
@Min(value = 1, message = "支付金额必须大于零")
|
||||
private Integer payPrice;
|
||||
|
||||
// TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。
|
||||
// TOTO 那是不是搞一个充值模板
|
||||
@Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
// @NotNull(message = "钱包赠送金额不能为空")
|
||||
// @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零")
|
||||
private Integer bonusPrice = 0;
|
||||
|
||||
@Schema(description = "充值套餐编号", example = "1024")
|
||||
private Long packageId;
|
||||
|
||||
// TODO @jason:可以改成 payPrice 和 packageId 两个至少一个不为空;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.pay.convert.wallet;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
|
||||
import org.mapstruct.Mapper;
|
||||
@ -15,8 +14,8 @@ public interface PayWalletRechargeConvert {
|
||||
|
||||
PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class);
|
||||
|
||||
@Mapping(target = "totalPrice", expression = "java(vo.getPayPrice() + vo.getBonusPrice() )")
|
||||
PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo);
|
||||
@Mapping(target = "totalPrice", expression = "java( payPrice + bonusPrice)")
|
||||
PayWalletRechargeDO convert(Long walletId, Integer payPrice, Integer bonusPrice, Long packageId);
|
||||
|
||||
AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean);
|
||||
|
||||
|
@ -47,7 +47,11 @@ public class PayWalletRechargeDO extends BaseDO {
|
||||
* 钱包赠送金额
|
||||
*/
|
||||
private Integer bonusPrice;
|
||||
// TODO @jason:如果有赠送金额,需要关联下 PayWalletPackageDO 的 id 字段
|
||||
|
||||
/**
|
||||
* 充值套餐编号
|
||||
*/
|
||||
private Long packageId;
|
||||
|
||||
/**
|
||||
* 是否已支付
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.dataobject.wallet;
|
||||
|
||||
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;
|
||||
@ -15,7 +16,7 @@ import lombok.Data;
|
||||
@TableName(value ="pay_wallet_recharge_package")
|
||||
@KeySequence("pay_wallet_recharge_package_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
public class PayWalletRechargePackageDO {
|
||||
public class PayWalletRechargePackageDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
|
@ -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.PayWalletRechargePackageDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PayWalletRechargePackageMapper extends BaseMapperX<PayWalletRechargePackageDO> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
package cn.iocoder.yudao.module.pay.service.wallet;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
|
||||
|
||||
/**
|
||||
* 钱包充值套餐 Service 接口
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
public interface PayWalletRechargePackageService {
|
||||
|
||||
/**
|
||||
* 获取钱包充值套餐
|
||||
* @param packageId 充值套餐编号
|
||||
*/
|
||||
PayWalletRechargePackageDO getWalletRechargePackage(Long packageId);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.pay.service.wallet;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 钱包充值套餐 Service 实现类
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
@Service
|
||||
public class PayWalletRechargePackageServiceImpl implements PayWalletRechargePackageService {
|
||||
|
||||
@Resource
|
||||
private PayWalletRechargePackageMapper rechargePackageMapper;
|
||||
|
||||
@Override
|
||||
public PayWalletRechargePackageDO getWalletRechargePackage(Long packageId) {
|
||||
return rechargePackageMapper.selectById(packageId);
|
||||
}
|
||||
}
|
@ -6,11 +6,11 @@ import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargeMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
||||
@ -24,12 +24,14 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.hutool.core.util.ObjectUtil.notEqual;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*;
|
||||
|
||||
@ -58,14 +60,33 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
|
||||
private PayOrderService payOrderService;
|
||||
@Resource
|
||||
private PayRefundService payRefundService;
|
||||
@Resource
|
||||
private PayWalletRechargePackageService payWalletRechargePackageService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType,
|
||||
AppPayWalletRechargeCreateReqVO createReqVO) {
|
||||
// 1. 新增钱包充值记录
|
||||
AppPayWalletRechargeCreateReqVO reqVO) {
|
||||
// 1.1 校验参数
|
||||
if (Objects.isNull(reqVO.getPayPrice()) && Objects.isNull(reqVO.getPackageId())) {
|
||||
throw exception(WALLET_RECHARGE_PACKAGE_AND_PRICE_IS_EMPTY);
|
||||
}
|
||||
// 1.2 新增钱包充值记录
|
||||
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);
|
||||
}
|
||||
payPrice = rechargePackage.getPayPrice();
|
||||
bonusPrice = rechargePackage.getBonusPrice();
|
||||
} else {
|
||||
payPrice = reqVO.getPayPrice();
|
||||
}
|
||||
|
||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType);
|
||||
PayWalletRechargeDO walletRecharge = PayWalletRechargeConvert.INSTANCE.convert(wallet.getId(), createReqVO);
|
||||
PayWalletRechargeDO walletRecharge = INSTANCE.convert(wallet.getId(), payPrice, bonusPrice, reqVO.getPackageId());
|
||||
walletRechargeMapper.insert(walletRecharge);
|
||||
|
||||
// 2.1 创建支付单
|
||||
|
Loading…
Reference in New Issue
Block a user