chenjiahe
2023-04-01 510678fe2f81501914ea4905fb7026b9c7be414f
phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java
@@ -873,22 +873,27 @@
    /**保存退款信息
     * 保存退款信息,并没有真正退款
     */
    public RefundRecord insertRefundInfo(OrderRefundDto orderRefundDto,OrdersTotal ordersTotal,StringBuilder orderNodeBuilder
            , ThirtApplication thirtApplication){
    public RefundRecord insertRefundInfo(OrderRefundDto orderRefundDto,OrdersTotal ordersTotal
            ,StringBuilder orderNodeBuilder, ThirtApplication thirtApplication){
        //操作人
        Employee employee = commonService.selectOneByKey(EmployeeMapper.class,orderRefundDto.getOperatorId());
        if(employee == null){
            throw new TipsException("操作人标识错误!");
        }
        ///////退款总表数据填充
        //生成退款编号
        String totalCode = createNoService.createNo("R",System.currentTimeMillis()+"",8);
        RefundRecord refundRecord=new RefundRecord(totalCode,ordersTotal.getShopId(),ordersTotal.getShopName(),orderRefundDto.getRefundTotal()
                , RefundStatus.STATUS_APPLY_REFUND,0, RefundSoruceConstants.TYPE_SOURCE_ORDER,orderRefundDto.getRemarks(),ordersTotal.getId(),ordersTotal.getUserId());
        //操作人信息
        refundRecord.setOperatorType(RefundRecord.OPERATOR_TYPE_EMPLOYEE);
        Employee employee = commonService.selectOneByKey(EmployeeMapper.class,orderRefundDto.getOperatorId());
        if(employee == null){
            throw new TipsException("操作人标识错误!");
        }
        refundRecord.setOperatorId(employee.getId());
        refundRecord.setRefundOperationType(orderRefundDto.getRefundOperationType());
        refundRecord.setOperatorNo(employee.getEmployeeNo());
        refundRecord.setOperatorName(employee.getCnName());
        refundRecord.setRefundOperationType(orderRefundDto.getRefundOperationType());
        /////退款的备注
        refundRecord.setRemarks(orderRefundDto.getRemarks());
        refundRecord.setRefundReason(orderRefundDto.getRefundReason());
@@ -898,14 +903,13 @@
        refundRecordService.insert(refundRecord);
        //退款方式处理
        List<RefundRecordMethod> refundRecordMethodList = null;
        if(orderRefundDto.getRefundPayMethod() !=null && orderRefundDto.getRefundPayMethod().size() > 0){
            refundRecordMethodList = handleRefundPayMethod(orderRefundDto,orderNodeBuilder,ordersTotal,refundRecord);
            handleRefundPayMethod(orderRefundDto,orderNodeBuilder,ordersTotal,refundRecord);
        }
        //退款的子项处理
        if(orderRefundDto.getRefundList()!=null && orderRefundDto.getRefundList().size()>0){
            insertRefundRecordItem(orderRefundDto,orderNodeBuilder,ordersTotal,refundRecord,refundRecordMethodList);
            insertRefundRecordItem(orderRefundDto,orderNodeBuilder,refundRecord);
        }
        //回退的优惠卷处理
        if(orderRefundDto.getCouponList() != null && orderRefundDto.getCouponList().size()>0){
@@ -1117,23 +1121,22 @@
    public List<RefundRecordMethod> handleRefundPayMethod(OrderRefundDto orderRefundDto,StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord){
        orderNodeBuilder.append("-记录退款方式:");
        //获取订单可退款方式
        //获取订单可退款方式,就是支付方式总表的信息,已经支付编号求和
        List<PayMethodVo> payMethodVoList = refundMapper.selectConsumePayList(ordersTotal.getId());
        Map<String, PayMethodVo> payMethodVoMap = payMethodVoList.stream().collect(
                Collectors.toMap(PayMethodVo::getNumberNo,(a) -> a));
        //用map装载,后面根据支付编号直接获取便可
        Map<String, PayMethodVo> payMethodVoMap = payMethodVoList.stream().collect(Collectors.toMap(PayMethodVo::getNumberNo,(a) -> a));
        List<RefundRecordMethod> refundRecordMethodList = new ArrayList<>();
        PayMethodVo payMethodVo;
        RefundRecordMethod refundRecordMethod=null;
        RefundMethodTransformation refundMethodTransformation=null;
        RefundRecordMethod refundRecordMethod;
        for (OrderPayMethodDto orderPayMethodDto : orderRefundDto.getRefundPayMethod()) {
            payMethodVo = payMethodVoMap.get(orderPayMethodDto.getPayMethodNo());
            //判断是不是在支付方式里面的
            if (payMethodVo == null){
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"可退支付方式未找到对应的支付:"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]");
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"可退支付方式未找到:"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]");
            }
            //判断支付方式
            PaymentMethod payMethod = paymentMethodService.selectNumberNoUncheckUp(orderPayMethodDto.getPayMethodNo());
@@ -1153,32 +1156,26 @@
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款金额错误:"+orderPayMethodDto.getPayMethodName()+"["+orderPayMethodDto.getPayMethodNo()+"]");
            }
            //新增转换表记录
            refundMethodTransformation = new RefundMethodTransformation();
            BeanUtils.copyProperties(orderPayMethodDto, refundMethodTransformation);
            refundMethodTransformation.setRefundTotal(orderPayMethodDto.getMoney());
            refundMethodTransformation.setRefundRecordId(refundRecord.getId());
            refundMethodTransformationMapper.insert(refundMethodTransformation);
            //退回客户的支付方式
            ////退款方式数据填充
            refundRecordMethod = new RefundRecordMethod();
            refundRecordMethod.setType(refundRecord.getSourceType());
            refundRecordMethod.setActualTotal(orderPayMethodDto.getMoney());
            //支付方式信息
            refundRecordMethod.setNumberNo(payMethod.getNumberNo());
            refundRecordMethod.setPaymentMethodId(payMethod.getId());
            refundRecordMethod.setName(payMethod.getName());
            refundRecordMethod.setIsMoneyPay(payMethodVo.getIsMoneyPay());
            refundRecordMethod.setIsExecute(payMethodVo.getIsExecute());
            //退款方式信息
            refundRecordMethod.setRefundNumberNo(refundMethod.getNumberNo());
            refundRecordMethod.setRefundName(refundMethod.getName());
            refundRecordMethod.setRefundMethodId(refundMethod.getId());
            refundRecordMethod.setActualTotal(orderPayMethodDto.getMoney());
            refundRecordMethod.setRefundMethodId(refundMethod.getId());
            refundRecordMethod.setIsMoneyPayRefund(refundMethod.getIsMoneyPay());
            refundRecordMethod.setIsExecuteRefund(refundMethod.getIsExecute());
            refundRecordMethod.setRefundMethodTransId(refundMethodTransformation.getId());
            refundRecordMethod.setRemarks(orderPayMethodDto.getRemarks());
            //refundRecordMethod.setRemarks(orderPayMethodDto.getRemarks());
            refundRecordMethodService.insert(refundRecordMethod);
            refundRecordMethodList.add(refundRecordMethod);
@@ -1189,7 +1186,7 @@
    /**
     * 退款记录子项
     */
    public void insertRefundRecordItem(OrderRefundDto orderRefundDto,StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,List<RefundRecordMethod> refundRecordMethodList){
    public void insertRefundRecordItem(OrderRefundDto orderRefundDto,StringBuilder orderNodeBuilder,RefundRecord refundRecord){
        orderNodeBuilder.append("-记录退款详情");
@@ -1255,9 +1252,8 @@
                refundRecordItem.setRefundMoney(refundTotal);
            }
            refundRecordItemService.insert(refundRecordItem);
            //计算剩余要分配的退款总金额
            //减去已经分配的退款金额
            refundTotal = refundTotal.subtract(refundRecordItem.getRefundMoney()).setScale(2,RoundingMode.HALF_UP);
            //子单子项处理
            insertRefundRecordItemTwo(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos());
        }
@@ -1336,7 +1332,6 @@
            refundRecordItemSourceMapper.insert(refundRecordItemSource);
            //减去已经分配退款金额
            refundTotal = refundTotal.subtract(refundRecordItemSource.getRefundMoney()).setScale(2,RoundingMode.HALF_UP);
        }
        if(refundTotal.compareTo(BigDecimal.ZERO) > 0){
@@ -1349,12 +1344,12 @@
     * 记录退款记录优惠卷
     */
    public void handleOrderCouponRefunDto(List<OrderCouponRefunDto> couponList,StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord){
        CouponOrderDiscountLog couponOrderDiscountLog=null;
        RefundRecordCoupon refundRecordCoupon=null;
        CouponOrderDiscountLog couponOrderDiscountLog;
        RefundRecordCoupon refundRecordCoupon;
        orderNodeBuilder.append("-处理退款优惠卷");
        for (OrderCouponRefunDto orderCouponRefunDto : couponList) {
            couponOrderDiscountLog=couponOrderDiscountLogMapper.selectOneByKey(orderCouponRefunDto.getOrderCouponId());
            if(couponOrderDiscountLog==null){
            if( couponOrderDiscountLog == null){
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单优惠卷标识不正确");
            }
            refundRecordCoupon=new  RefundRecordCoupon(ordersTotal.getId(),refundRecord.getId(),ordersTotal.getUserId(),1,1,couponOrderDiscountLog.getId(),
@@ -1376,7 +1371,7 @@
        orderNodeBuilder.append("-处理退款支付方式,用户待执行项目");
        //处理主业务
        ordersTotal=  PartialRefundUtil.refundProcess(commonService, operationId, operatorName, refundRecord.getId());
        ordersTotal =  PartialRefundUtil.refundProcess(commonService, operationId, operatorName, refundRecord.getId());
        //返回数据
        Map<String,Object> data=new HashMap<>();