chenjiahe
2024-01-30 ce00eb3b18b717cf18a9ecf6fe819b838fe73909
退款-退款金额和支付方式总金额不一样的问题优化
1个文件已修改
61 ■■■■■ 已修改文件
phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java
@@ -408,6 +408,10 @@
            DistributionRedundVo distributionRedundVo;
            OrderItem orderItem;
            //子单的支付方式
            List<OrderPayMethodDto> refundPayMethodItemList;
            OrderPayMethodDto refundPayMethodItem;
            //计算每个条目需要退多少钱
            for (OrderItemRefundDto orderItemRefundDto : refundList) {
                if(StringUtils.isEmpty(orderItemRefundDto.getOrderItemId())){
@@ -420,6 +424,7 @@
                if(!orderItem.getOrderId().equals(ordersTotal.getId())){
                    throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到退款项[012]");
                }
                refundPayMethodItemList = new ArrayList<>();
                //判断这个项目能不能显示处理
                switch (orderItem.getType()) {
@@ -465,7 +470,12 @@
                    orderPayMethodDto = orderPayMethodDtoMap.computeIfAbsent(refundPaymentMethodVo.getNumberNo(),
                            k->new OrderPayMethodDto(refundPaymentMethodVo.getNumberNo(),refundPaymentMethodVo.getName(),BigDecimal.ZERO,refundPaymentMethodVo.getIsMoneyPay(),refundPaymentMethodVo.getIsExecute()));
                    orderPayMethodDto.setPayTotal(orderPayMethodDto.getPayTotal().add(refundPaymentMethodVo.getRefundTotal()).setScale(2,RoundingMode.HALF_UP));
                    //子单的支付方式
                    refundPayMethodItem = new OrderPayMethodDto(refundPaymentMethodVo.getNumberNo(),refundPaymentMethodVo.getName(),refundPaymentMethodVo.getRefundTotal(),refundPaymentMethodVo.getIsMoneyPay(),refundPaymentMethodVo.getIsExecute());
                    refundPayMethodItemList.add(refundPayMethodItem);
                }
                orderItemRefundDto.setRefundPayMethodList(refundPayMethodItemList);
            }
            for(Map.Entry<String, OrderPayMethodDto> entry : orderPayMethodDtoMap.entrySet()) {
@@ -696,6 +706,10 @@
        Map<String,DistributionRedundMethodVo> refundPaymentMethodVoMap = new HashMap<>();
        DistributionRedundMethodVo refundPaymentMethodVo;
        //子单的支付方式
        List<OrderPayMethodDto> refundPayMethodItemList;
        OrderPayMethodDto refundPayMethodItem;
        DistributionRedundVo distributionRedundVoSon;
        for (OrderItemSourceRefundDto orderItemSourceRefundDto : orderItemSourceRefundDtos) {
            if(StringUtils.isEmpty(orderItemSourceRefundDto.getOrderItemSonId())){
@@ -710,6 +724,8 @@
            if (!orderItemSon.getOrderItemId().equals(orderItem.getId())) {
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到退款项[54]");
            }
            refundPayMethodItemList = new ArrayList<>();
            switch (orderItemSon.getType()) {
                case OrderGoodsConstants.TYPE_PROJECT:
@@ -743,8 +759,12 @@
                refundPaymentMethodVo = refundPaymentMethodVoMap.computeIfAbsent(paymentMethodVo.getNumberNo()
                        ,k-> new DistributionRedundMethodVo(paymentMethodVo.getNumberNo(),paymentMethodVo.getName(),BigDecimal.ZERO,paymentMethodVo.getIsMoneyPay(),paymentMethodVo.getIsExecute()));
                refundPaymentMethodVo.setRefundTotal(refundPaymentMethodVo.getRefundTotal().add(paymentMethodVo.getRefundTotal()).setScale(2,RoundingMode.HALF_UP));
            }
                //子单的支付方式
                refundPayMethodItem = new OrderPayMethodDto(paymentMethodVo.getNumberNo(),paymentMethodVo.getName(),paymentMethodVo.getRefundTotal(),paymentMethodVo.getIsMoneyPay(),paymentMethodVo.getIsExecute());
                refundPayMethodItemList.add(refundPayMethodItem);
            }
            orderItemSourceRefundDto.setRefundPayMethodList(refundPayMethodItemList);
        }
        //返回结构数据填充
@@ -1496,6 +1516,19 @@
            throw new TipsException("退款积分分配错误[01]!");
        }
        //客户退款的支付方式,后面的校验会用到的
        Set<String> payMonthNoSet = new HashSet<>();
        for(OrderPayMethodDto orderPayMethodDto:orderRefundDto.getPayMethodList()){
            if(orderPayMethodDto.getMoney().compareTo(BigDecimal.ZERO) < 1){
                continue;
            }
            //积分的也跳出
            if(PayMethodTypeConstants.PAY_INTEGRAL.equals(orderPayMethodDto.getPayMethodNo())){
                continue;
            }
            payMonthNoSet.add(orderPayMethodDto.getPayMethodNo());
        }
        //-----退款金额处理
        //计算金额占比,客户选择退款总金额和可退总金额占比
        if(orderRefundDto.getTotalAmount().compareTo(BigDecimal.ZERO) < 1){
@@ -1510,6 +1543,7 @@
        /////引用参数
        RefundRecordItem refundRecordItem;
        OrderItem orderItem;
        BigDecimal payMonthTotal;
        for(int i = 0;i < refundList.size();i++){
            orderItemRefundDto = refundList.get(i);
@@ -1558,6 +1592,16 @@
            if(refundRecordItem.getRefundMoney().compareTo(refundTotal) > 0){
                refundRecordItem.setRefundMoney(refundTotal);
            }
            //重点,这里还是要校验一下和支付总额是否对得上
            payMonthTotal = BigDecimal.ZERO;
            for(OrderPayMethodDto orderPayMethodDto:orderItemRefundDto.getRefundPayMethodList()){
                if(payMonthNoSet.contains(orderPayMethodDto.getPayMethodNo())){
                    payMonthTotal = payMonthTotal.add(orderPayMethodDto.getPayTotal());
                }
            }
            if(refundRecordItem.getRefundMoney().compareTo(payMonthTotal) > 0){
                refundRecordItem.setRefundMoney(payMonthTotal);
            }
            refundRecordItem.setRealRefundNum(refundRecordItem.getRefundNum());
            refundRecordItem.setRealRefundTotal(refundRecordItem.getRefundMoney());
@@ -1574,7 +1618,7 @@
            if(PartialRefundUtil.CONTAIN_SON_TYPE_SET.contains(orderItem.getType())){
                //子单子项处理
                insertRefundRecordItemTwo(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos());
                insertRefundRecordItemTwo(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos(),payMonthNoSet);
            }
            //虚拟商品退款时需校验一下,对应关联的优惠券码有没有被使用或
            if(OrderItemConstants.TYPE_COUPON.equals(orderItem.getType())){
@@ -1590,7 +1634,7 @@
    }
    /**二级子单处理*/
    public void insertRefundRecordItemTwo(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos){
    public void insertRefundRecordItemTwo(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos,Set<String> payMonthNoSet){
        if(orderItemSourceRefundDtos == null || orderItemSourceRefundDtos.size() == 0){
            return;
        }
@@ -1644,6 +1688,7 @@
        BigDecimal refundTotal = recordItem.getRefundMoney();
        OrderItemSon orderItemSon;
        RefundRecordItemSource refundRecordItemSource;
        BigDecimal payMonthTotal;
        for(int i = 0;i<orderItemSourceRefundDtos.size();i++){
            orderItemSourceRefundDto = orderItemSourceRefundDtos.get(i);
@@ -1688,6 +1733,16 @@
            if(refundRecordItemSource.getRefundMoney().compareTo(refundTotal) > 0){
                refundRecordItemSource.setRefundMoney(refundTotal);
            }
            //重点,这里还是要校验一下和支付总额是否对得上
            payMonthTotal = BigDecimal.ZERO;
            for(OrderPayMethodDto orderPayMethodDto:orderItemSourceRefundDto.getRefundPayMethodList()){
                if(payMonthNoSet.contains(orderPayMethodDto.getPayMethodNo())){
                    payMonthTotal = payMonthTotal.add(orderPayMethodDto.getPayTotal());
                }
            }
            if(refundRecordItemSource.getRefundMoney().compareTo(payMonthTotal) > 0){
                refundRecordItemSource.setRefundMoney(payMonthTotal);
            }
            refundRecordItemSource.setRealRefundNum(refundRecordItemSource.getRefundNum());
            refundRecordItemSource.setRealRefundTotal(refundRecordItemSource.getRefundMoney());