“mitao”
2026-04-28 a53476cf294d5b4bfc156622d18b5b3f2122296a
feat:兑换码表接口设计修改
4个文件已修改
69 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TExchangeCodeDetail.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TExchangeCodeUseRecord.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/vo/GovernmentCloudSystemVO.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TExchangeCodePackageServiceImpl.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TExchangeCodeDetail.java
@@ -48,6 +48,14 @@
    @ApiModelProperty("已使用金额")
    private BigDecimal usedAmount;
    @TableField("gift_amount")
    @ApiModelProperty("当前兑换码赠送金额")
    private BigDecimal giftAmount;
    @TableField("gift_ratio")
    @ApiModelProperty("赠送金额比例")
    private BigDecimal giftRatio;
    @TableField("bind_user_id")
    @ApiModelProperty("绑定用户ID")
    private Long bindUserId;
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TExchangeCodeUseRecord.java
@@ -28,16 +28,28 @@
    private Long detailId;
    @TableField("order_id")
    @ApiModelProperty("订单ID")
    @ApiModelProperty("订单ID,兑换收入为0")
    private Long orderId;
    @TableField("refund_no")
    @ApiModelProperty("退款单号/退款流水号")
    private String refundNo;
    @TableField("user_id")
    @ApiModelProperty("用户ID")
    private Long userId;
    @TableField("change_type")
    @ApiModelProperty("变动类型 1兑换收入 2充电消费 3退款返还")
    private Integer changeType;
    @TableField("used_amount")
    @ApiModelProperty("本次使用金额")
    private BigDecimal usedAmount;
    @TableField("gift_used_amount")
    @ApiModelProperty("本次使用赠送金额")
    private BigDecimal giftUsedAmount;
    @TableField(exist = false)
    private String uid;
@@ -47,9 +59,6 @@
    @TableField(exist = false)
    private String orderCode;
    @TableField(exist = false)
    private Integer changeType;
    @TableField(exist = false)
    private BigDecimal changeAmount;
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/vo/GovernmentCloudSystemVO.java
@@ -4,11 +4,9 @@
import com.ruoyi.system.api.domain.SysOperLog;
import com.ruoyi.system.api.domain.SysRole;
import com.ruoyi.system.api.domain.SysUser;
import com.sun.javafx.tk.TKSystemMenu;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.expression.spel.ast.Operator;
import java.util.List;
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TExchangeCodePackageServiceImpl.java
@@ -57,6 +57,9 @@
    private static final Integer CODE_STATUS_UNBOUND = 1;
    private static final Integer CODE_STATUS_BOUND = 2;
    private static final Integer CODE_STATUS_INVALID = 3;
    private static final Integer USE_RECORD_TYPE_EXCHANGE = 1;
    private static final Integer USE_RECORD_TYPE_CONSUME = 2;
    private static final Integer USE_RECORD_TYPE_REFUND = 3;
    private static final DateTimeFormatter BATCH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    @Resource
@@ -283,7 +286,9 @@
        record.setDetailId(detail.getId());
        record.setOrderId(0L);
        record.setUserId(userId);
        record.setChangeType(USE_RECORD_TYPE_EXCHANGE);
        record.setUsedAmount(amount);
        record.setGiftUsedAmount(defaultMoney(detail.getGiftAmount()));
        useRecordMapper.insert(record);
        refreshPackageStats(exchangePackage.getId());
        ExchangeCodeBindResultVO resultVO = new ExchangeCodeBindResultVO();
@@ -299,8 +304,7 @@
        Page<TExchangeCodeUseRecord> page = useRecordMapper.selectPage(Page.of(query.getPageCurr(), query.getPageSize()),
                new QueryWrapper<TExchangeCodeUseRecord>()
                        .eq("user_id", query.getUserId())
                        .eq(Objects.equals(query.getChangeType(), 1), "IFNULL(order_id, 0)", 0)
                        .gt(Objects.equals(query.getChangeType(), 2), "order_id", 0)
                        .eq(query.getChangeType() != null, "change_type", query.getChangeType())
                        .orderByDesc("create_time"));
        page.getRecords().forEach(this::fillUseRecordView);
        return page;
@@ -382,13 +386,22 @@
            record.setDetailId(detail.getId());
            record.setOrderId(dto.getOrderId());
            record.setUserId(dto.getUserId());
            record.setChangeType(USE_RECORD_TYPE_CONSUME);
            record.setUsedAmount(useAmount);
            record.setGiftUsedAmount(calculateGiftUsedAmount(useAmount, detail));
            useRecordMapper.insert(record);
            remainingNeed = remainingNeed.subtract(useAmount);
            deductedAmount = deductedAmount.add(useAmount);
        }
        resultVO.setDeductedAmount(deductedAmount.setScale(2, RoundingMode.HALF_UP));
        return resultVO;
    }
    private BigDecimal calculateGiftUsedAmount(BigDecimal useAmount, TExchangeCodeDetail detail) {
        if (useAmount == null || detail == null || detail.getGiftRatio() == null) {
            return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
        }
        return useAmount.multiply(detail.getGiftRatio()).setScale(2, RoundingMode.HALF_UP);
    }
    private BigDecimal getDetailRemainAmount(TExchangeCodeDetail detail) {
@@ -513,6 +526,8 @@
            return;
        }
        String batchNo = "PKG" + LocalDateTime.now().format(BATCH_FORMATTER);
        TExchangeCodePackage exchangePackage = this.getById(packageId);
        BigDecimal giftRatio = calculateGiftRatio(exchangePackage);
        List<TExchangeCodePackageSpec> expandList = new ArrayList<>();
        for (TExchangeCodePackageSpec spec : specEntities) {
            for (int i = 0; i < spec.getQuantity(); i++) {
@@ -530,9 +545,27 @@
            detail.setCode(generateCode(packageId, i));
            detail.setPassword(generatePassword());
            detail.setStatus(CODE_STATUS_UNBOUND);
            detail.setGiftRatio(giftRatio);
            detail.setGiftAmount(calculateDetailGiftAmount(spec, giftRatio));
            detail.setBatchNo(batchNo);
            codeDetailMapper.insert(detail);
        }
    }
    private BigDecimal calculateGiftRatio(TExchangeCodePackage exchangePackage) {
        if (exchangePackage == null || exchangePackage.getTotalAmount() == null
                || exchangePackage.getTotalAmount().compareTo(BigDecimal.ZERO) == 0) {
            return BigDecimal.ZERO.setScale(6, RoundingMode.HALF_UP);
        }
        return defaultMoney(exchangePackage.getGiftAmount())
                .divide(exchangePackage.getTotalAmount(), 6, RoundingMode.HALF_UP);
    }
    private BigDecimal calculateDetailGiftAmount(TExchangeCodePackageSpec spec, BigDecimal giftRatio) {
        if (spec == null || spec.getAmount() == null || giftRatio == null) {
            return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
        }
        return spec.getAmount().multiply(giftRatio).setScale(2, RoundingMode.HALF_UP);
    }
    private void refreshPackageStats(Long packageId) {
@@ -570,7 +603,10 @@
        record.setDateTime(record.getCreateTime());
        record.setChangeAmount(defaultMoney(record.getUsedAmount()));
        record.setCurrentBalance(defaultMoney(record.getUsedAmount()));
        record.setChangeType(record.getOrderId() == null || record.getOrderId() == 0 ? 1 : 2);
        if (record.getChangeType() == null) {
            record.setChangeType(record.getOrderId() == null || record.getOrderId() == 0
                    ? USE_RECORD_TYPE_EXCHANGE : USE_RECORD_TYPE_CONSUME);
        }
        if (record.getDetailId() != null) {
            TExchangeCodeDetail detail = codeDetailMapper.selectById(record.getDetailId());
            if (detail != null) {