chenjiahe
2023-08-11 e3b9cc6f8c579c92fc3fedec30e6ed670dba60d4
退款兼容退
5个文件已修改
180 ■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/tool/payment/ConsumeTool.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/tool/refund/RefundTool.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/consume/impl/ConsumeNotifyServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/util/api/OrderPayMoneyUtil.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/tool/payment/ConsumeTool.java
@@ -1,21 +1,18 @@
package com.hx.phip.tool.payment;
import com.hx.common.service.CommonService;
import com.hx.exception.TipsException;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.common.ConsumePayConstants;
import com.hx.phiappt.dao.mapper.ConsumeNotifyMapper;
import com.hx.phiappt.model.PaymentMethod;
import com.hx.phiappt.model.Shop;
import com.hx.phiappt.model.consume.ConsumeNotify;
import com.hx.phiappt.model.consume.ConsumePay;
import com.hx.phiappt.model.consume.RecordConsume;
import com.hx.phip.dao.mapper.PaymentMethodMapper;
import com.hx.phip.vo.payment.ConsumePayVo;
import com.hx.util.StringUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**消费记录工具
 *
@@ -152,6 +149,43 @@
        return commonService.selectList(ConsumeNotifyMapper.class,sqlSentence);
    }
    /**通过支付方式编号和金额获取到支付回调信息,获取多条,升序排序
     * @param orderId 支付回调信息关联标识
     * @param paymentNo 支付方式编号
     * @param payAmount 支付金额
     * @param commonService 映射
     * @return 支付回调信息
     */
    public static List<ConsumeNotify> selectList(String orderId,String paymentNo,BigDecimal payAmount, CommonService commonService){
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        StringBuilder stringBuilder = new StringBuilder();
        values.put("orderId",orderId);
        values.put("paymentNo",paymentNo);
        stringBuilder.append("SELECT * FROM consume_notify WHERE isDel = 0 AND paymentNo = #{m.paymentNo} AND orderId = #{m.orderId}");
        if(payAmount != null){
            values.put("payAmount",payAmount);
            stringBuilder.append(" AND payAmount = #{m.payAmount}");
        }
        stringBuilder.append(" ORDER BY payAmount ASC");
        sqlSentence.sqlSentence(stringBuilder.toString(),values);
        return commonService.selectList(ConsumeNotifyMapper.class,sqlSentence);
    }
    /**更新支付回调的退款金额信息*/
    public static void updateRefundTotal(ConsumeNotify consumeNotify,BigDecimal refundTotal,int refundStatus,CommonService commonService){
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        values.put("refundTotal",refundTotal);
        values.put("id",consumeNotify.getId());
        values.put("refundStatus",refundStatus);
        sqlSentence.sqlUpdate("refundTotal = refundTotal+#{m.refundTotal},refundStatus = #{m.refundStatus} WHERE id = #{m.id}",values);
        commonService.updateWhere(ConsumeNotify.class,sqlSentence);
    }
    /**
     * 获取支付方式
     * @param numberNo 支付编号
phi_platform_common/src/main/java/com/hx/phip/tool/refund/RefundTool.java
@@ -6,6 +6,7 @@
import com.hx.phiappt.common.RefundSoruceConstants;
import com.hx.phiappt.common.RefundStatus;
import com.hx.phiappt.model.BaseEntity;
import com.hx.phiappt.model.consume.ConsumeNotify;
import com.hx.phiappt.model.order.OrdersTotal;
import com.hx.phiappt.model.refund.RefundRecordConsumePay;
import com.hx.phiappt.model.refund.RefundRecordItem;
@@ -15,7 +16,9 @@
import com.hx.phip.dao.mapper.RefundRecordConsumePayMapper;
import com.hx.phip.dao.mapper.RefundRecordItemMapper;
import com.hx.phip.dao.mapper.RefundRecordItemSourceMapper;
import com.hx.phip.tool.payment.CenterPayUtil;
import com.hx.phip.tool.payment.ConsumeTool;
import com.hx.redis.RedisUtil;
import com.hx.util.StringUtils;
import com.hz.his.dto.order.OrderRefundNoteDto;
import com.hz.his.dto.order.OrderRefundNoteListDto;
@@ -148,34 +151,6 @@
            refundRecordItemSource.setOccupyRefundIntegral(BigDecimal.ZERO);
        }
        return refundRecordItemSource;
    }
    /**退现金到用户
     * 不是原路退,不执行第三方支付退款,直接跳过
     * @param refundCashVo 退款信息
     * @param commonService 映射
     */
    public static void refundCash(RefundCashVo refundCashVo, CommonService commonService){
        if(refundCashVo.getRefundCashItemVoList() == null || refundCashVo.getRefundCashItemVoList().size() == 0){
            return;
        }
        //合并同一个的支付方式
        Map<String,BigDecimal> refundMap = new HashMap<>();
        BigDecimal refundTotal;
        for(RefundCashItemVo refundCashItemVo:refundCashVo.getRefundCashItemVoList()){
            refundTotal = refundMap.computeIfAbsent(refundCashItemVo.getPaymentNo(),k->BigDecimal.ZERO);
            refundTotal = refundTotal.add(refundCashItemVo.getRefundTotal());
            refundMap.put(refundCashItemVo.getPaymentNo(),refundTotal);
        }
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        //获取支付信息
        //List<> ConsumeTool.selectNoBindList();
    }
}
phi_platform_user/src/main/java/com/hx/phip/service/consume/impl/ConsumeNotifyServiceImpl.java
@@ -29,6 +29,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -199,6 +200,9 @@
        if(consumeNotify.getPayAmount().compareTo(refundQrVo.getRefundTotal())!=0){
            throw new TipsException("退款金额与支付金额不符合!");
        }
        if(consumeNotify.getRefundTotal().compareTo(BigDecimal.ZERO)!=0){
            throw new TipsException("已退款金额发生改变!");
        }
        Date newDate = new Date();
phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java
@@ -12,6 +12,7 @@
import com.hx.phiappt.model.*;
import com.hx.phiappt.model.activity.ActivityAction;
import com.hx.phiappt.model.activity.ActivityRule;
import com.hx.phiappt.model.consume.ConsumeNotify;
import com.hx.phiappt.model.coupon.Coupon;
import com.hx.phiappt.model.coupon.CouponNumber;
import com.hx.phiappt.model.coupon.CouponOrderDiscountLog;
@@ -21,6 +22,8 @@
import com.hx.phiappt.model.user.UserCard;
import com.hx.phiappt.model.user.UserProjectItem;
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
import com.hx.phiappt.vo.refund.RefundCashItemVo;
import com.hx.phiappt.vo.refund.RefundCashVo;
import com.hx.phip.config.CustomParameter;
import com.hx.phip.dao.mapper.*;
import com.hx.phip.service.CreateNoService;
@@ -31,6 +34,8 @@
import com.hx.phip.service.refund.RefundRecordService;
import com.hx.phip.service.userLevel.UserLevelRuleService;
import com.hx.phip.tool.CreateNo;
import com.hx.phip.tool.payment.CenterPayUtil;
import com.hx.phip.tool.payment.ConsumeTool;
import com.hx.phip.tool.refund.OrderRefundCancelTool;
import com.hx.phip.tool.refund.PartialRefundUtil;
import com.hx.phip.tool.refund.PaymentCountTool;
@@ -56,6 +61,7 @@
import com.hz.his.dto.order.*;
import com.hz.his.feign.service.marketing.MOrderService;
import com.hz.his.vo.order.refund.RefundCancelVo;
import com.hz.pay.feign.centre.refund.FRefundService;
import com.platform.entity.ThirtApplication;
import com.platform.exception.PlatTipsException;
import com.platform.resultTool.PlatformCode;
@@ -134,6 +140,8 @@
    private RefundMapper refundMapper;
    @Resource
    private CreateNoService createNoService;
    @Resource
    private FRefundService fRefundService;
    /**
     * 获取退款页面详情
@@ -2530,4 +2538,91 @@
        }
    }
    /**退现金到用户
     * 不是原路退,不执行第三方支付退款,直接跳过
     * @param refundCashVo 退款信息
     */
    private synchronized void refundCash(String refundRecordId,RefundCashVo refundCashVo){
        if(refundCashVo.getRefundCashItemVoList() == null || refundCashVo.getRefundCashItemVoList().size() == 0){
            return;
        }
        //合并同一个的支付方式
        Map<String,BigDecimal> refundMap = new HashMap<>();
        BigDecimal refundTotal;
        for(RefundCashItemVo refundCashItemVo:refundCashVo.getRefundCashItemVoList()){
            refundTotal = refundMap.computeIfAbsent(refundCashItemVo.getPaymentNo(),k->BigDecimal.ZERO);
            refundTotal = refundTotal.add(refundCashItemVo.getRefundTotal());
            refundMap.put(refundCashItemVo.getPaymentNo(),refundTotal);
        }
        List<ConsumeNotify> consumeNotifyList;
        String refundNo;
        BigDecimal consumeTotal;
        int refundStatus;
        for (Map.Entry<String, BigDecimal> entry : refundMap.entrySet()) {
            refundTotal = entry.getValue();
            if(refundTotal.compareTo(BigDecimal.ZERO) < 1){
                continue;
            }
            //初始化可退金额
            consumeTotal = BigDecimal.ZERO;
            //获取支付信息(回调)
            consumeNotifyList = ConsumeTool.selectList(refundCashVo.getOrderId(),entry.getKey(),null,commonService);
            for(ConsumeNotify consumeNotify:consumeNotifyList){
                //计算总可退款金额
                consumeTotal = consumeTotal.add(consumeNotify.getPayAmount()).subtract(consumeNotify.getRefundTotal());
            }
            if(refundTotal.compareTo(consumeTotal) > 0){
                //总退款金额比可退金额大,那么就不执行
                continue;
            }
            for(ConsumeNotify consumeNotify:consumeNotifyList){
                if(refundTotal.compareTo(BigDecimal.ZERO) < 1){
                    //退完,那么就跳出循环
                    continue;
                }
                if(consumeNotify.getRefundStatus() == ConsumeNotify.REFUND_STATUS_ALL){
                    //没有可退金额,那么跳出循环
                    continue;
                }
                //计算可退金额
                consumeTotal = consumeNotify.getPayAmount().subtract(consumeNotify.getRefundTotal());
                if(consumeTotal.compareTo(BigDecimal.ZERO) < 1){
                    //没有可退金额,那么跳出循环
                    continue;
                }
                refundStatus = ConsumeNotify.REFUND_STATUS_ALL;
                if(consumeTotal.compareTo(refundTotal) > 0){
                    //可退金额比剩下要退的金额大
                    refundStatus = ConsumeNotify.REFUND_STATUS_PART;
                    consumeTotal = refundTotal;
                }
                //生成退款单号
                refundNo = createNoService.createNo("RF",String.valueOf(System.currentTimeMillis()),6);
                try {
                    //生成退款记录
                    RefundCash refundCash = new RefundCash();
                    refundCash.setRefundTotal(consumeTotal);
                    refundCash.setPlatTrxNo(consumeNotify.getPlatTrxNo());
                    refundCash.setRefunNo(refundNo);
                    refundCash.setOrderId(refundCashVo.getOrderId());
                    refundCash.setConsumeNotifyId(consumeNotify.getConsumePayId());
                    //调起中心平台的退款
                    CenterPayUtil.unifyRefund(consumeNotify.getAppId(),consumeNotify.getPlatTrxNo(),refundNo,refundCashVo.getRemark(),consumeNotify.getPayAmount()
                            ,consumeTotal,customParameter.getAppId(),customParameter.getPrivatekey(),fRefundService);
                    refundTotal = refundTotal.subtract(consumeTotal);
                    commonService.insert(RefundCashMapper.class,refundCash);
                    ConsumeTool.updateRefundTotal(consumeNotify,consumeTotal,refundStatus,commonService);
                }catch (Exception e){
                    logger.error("第三方退款失败",e);
                }
            }
        }
    }
}
phi_platform_user/src/main/java/com/hx/phip/util/api/OrderPayMoneyUtil.java
@@ -235,8 +235,8 @@
            hisPayList.add(hisPay);
        }
        //查找支付信息,进行关联
        ConsumeTool.bindConsumeList(ordersTotal.getId(),consumePayList,commonService);
        //查找支付信息,进行关联,暂时屏蔽
        //ConsumeTool.bindConsumeList(ordersTotal.getId(),consumePayList,commonService);
        //更新消费总记录,记录订单资金信息
        objectMap.clear();