mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 04:08:43 +08:00 
			
		
		
		
	充值套餐修改
This commit is contained in:
		@@ -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 创建支付单
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user